Jump to content
43oh

Is this 38KHz PWM ?


Recommended Posts

Unfortunately I have no osciloscope , is this PWM OK to use it for an IR-Signal?


#include <msp430g2553.h>

void main(void) {

   int counter = 26; // Is this correct?

  WDTCTL = WDTPW + WDTHOLD;        // Stop watchdog timer

  P1DIR |= BIT6;                   // Set P1.6 to output direction
  P1OUT &= ~BIT6;                 // Set the green LED off
  P1SEL |= BIT6;                  // Green LED controlled by PWM

  TA0CCR0 = counter;                // Count limit (16 bit)
  TA0CCR1 = counter/2;              // 50% duty cycle
  TA0CCTL0 = 0x10;                 // Enable Timer A0 interrupts, bit 4=1
  TA0CCTL1 = OUTMOD_7;
TA0CTL = TASSEL_2 + MC_1;        // Timer A0 with ACLK, count UP



  _BIS_SR(LPM0_bits + GIE);        // LPM0 (low power mode) interrupts enabled

}

#pragma vector=TIMER1_A0_VECTOR    // Timer1 A0 interrupt service routine

  __interrupt void Timer1_A0 (void) {

                    // NOOP
}

Link to post
Share on other sites

Well, maybe. One thing: fix the comment to note that TASSEL_2 means you're actually using SMCLK (nominally 1.1 MHz) instead of ACLK (nominally 12 kHz on that MCU with that initialization sequence).

 

At 1.1MHz I think you'd get 42.3 kHz with 26 ticks per cycle. Since DCO tolerance on the MSP430G2553 is +/- 6% it's probably not very close to 38 kHz.

Link to post
Share on other sites

Here's another way

DCOCTL |= DCO0 + DCO1; // DCO = ~300kHz
BCSCTL1 |= RSEL0 + RSEL1;
BCSCTL1 &= ~(RSEL2 + RSEL3);
BCSCTL2 |= DIVS0 + DIVS1; // divide SMCLK by 8 which will give ~38kHz

P1DIR |= BIT4; // port 1.4 is configured as SMCLK out and connected to IR emitter, this will be our carrier frequency, 38kHz
P1OUT &= ~BIT4;
P1SEL &= ~BIT4;	// switch carrier off
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...