Hi e2e,
There is a problem about Timer output of TimerB in MSP430F5324.
The first pulse is not what we expected if change the frequency. It is bigger than expected value, and the pulse is longer than expected;
Here is a example case.
Function requirement:
Output PWM definition. (Changing step is 25ms.)
Timer and mode selection:
CCR0 is working for frequency.
CCR2 is working for duty cycle.
Code:
Init function:
void enable_timerB_tone() {
TB0CCR0 = 0;
TB0CCR2 = 0;
TB0CCTL2 = CLLD_1 | OUTMOD_6;
TB0CTL = TBSSEL__SMCLK + MC__UP + ID__2 + TBCLR;
}
Each 25ms to change parameters to change the frequency:
void set_parameters_timerB(uint16_t period, uint16_t pulse_width_counter) {
TB0CCR0 = period;
TB0CCTL0 = CLLD_3;
TB0CCR2 = pulse_width_counter;
}
Result:
Check output with OSC:
The Purple line mark the parameter changing time(GPIO toggle for debugging, it indicates the value change in MCU).
The Green line is the output of CCR2.
The Purple arrow is the time to call “set_parameters_timerB()” function (it is finished also).
The Green arrow is the problem pulse.
(Before changing the pulse is 90us, after problem is 100us. Both side are correct as parameters.)
(From the rising edge of problem pulse to the next rising edge of pulse, the period is also bigger than expected value.)
do you have any suggestion in this issue?
thanks in advance.
LEON