I'm trying to generate a PWM of 6.5khz on pin 1.1 with duty cycle 50%. I'm using the code from keyforb demo.
Here's the code, but it's not working :
PERCFG |= 0x20; // Timer 3 Alternate location 2 P1SEL |= BV(1); // Peripheral function on P1_1 //P1SEL |= BV(1); P1DIR |= BV(1); // P1_1 = output T3CTL &= ~0x10; // Stop timer 3 (if it was running) T3CTL |= 0x04; // Clear timer 3 T3CTL &= ~0x08; // Disable Timer 3 overflow interrupts T3CTL |= 0x03; // Timer 3 mode = 3 - Up/Down T3CCTL0 &= ~0x40; // Disable channel 0 interrupts T3CCTL0 |= 0x04; // Ch0 mode = compare T3CCTL0 |= 0x10; // Ch0 output compare mode = toggle on compare uint8 prescaler = 0; uint8 frequency= 6500; // Get current Timer tick divisor setting uint8 tickSpdDiv = (CLKCONSTA & 0x38)>>3; // Calculate nr of ticks required to achieve target frequency uint32 ticks = (8000000/frequency) >> tickSpdDiv; // 8000000 = 32M / 4; // Fit this into an 8bit counter using the timer prescaler while ((ticks & 0xFFFFFF00) != 0) { ticks >>= 1; prescaler += 32; } // Update registers T3CTL &= ~0xE0; T3CTL |= prescaler; T3CC0 = (uint8)ticks; // Start timer T3CTL |= 0x10;