StefanWxx 2 Posted November 21, 2014 Share Posted November 21, 2014 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 } Quote Link to post Share on other sites
Rickta59 589 Posted November 21, 2014 Share Posted November 21, 2014 yes StefanWxx 1 Quote Link to post Share on other sites
pabigot 355 Posted November 21, 2014 Share Posted November 21, 2014 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. StefanWxx 1 Quote Link to post Share on other sites
oPossum 1,083 Posted November 21, 2014 Share Posted November 21, 2014 It's close. Can be made more accurate... Set the oscillator to one of the calibrated values. DCOCTL = 0; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; Set the max count to N - 1 TA0CCR0 = (1000000 / 38000) - 1; TA0CCR1 = TA0CCR0 >> 1; StefanWxx and pabigot 2 Quote Link to post Share on other sites
Rickta59 589 Posted November 21, 2014 Share Posted November 21, 2014 I agree with all of the above. However do you really have to be that accurate for IR? My default clock seems to be 1.012MHz .. so it was 38.0something kHz when I measured it. Of course your results will vary. But for talking talk IR it should be fine. StefanWxx 1 Quote Link to post Share on other sites
RobG 1,892 Posted November 22, 2014 Share Posted November 22, 2014 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 StefanWxx 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.