This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2333 PWM signal from Timer0_A3 Block#0

Other Parts Discussed in Thread: MSP430G2333

Question: How do I generate a controlled PWM duty cycle output for a Timer0_A3 Block#0 pin?

I need a controlled PWM duty cycle for the pin P1.5 shown below. 

My pin on board is connected to P1.5 (MSP430G2333) which is connected to timer0_A3 Block#0. 

Block#0 is the key, because in this block, because output modes 2, 3, 6, 7 do not work with Block#0

In Block#0, these Output modes (only) work:

0) PWM output mode 0 -- OUT bit value

1) PWM output mode 1 -- Set

4) PWM output mode 4 -- Toggle

5) PWM output mode 5 -- Reset

There are three usable Counting Modes:

1) Up Mode

2) Continuous Mode

3) Up/Down Mode

My current thinking is along the lines of Continuous Mode counting up to 0xFFFF and using a different TACCR0 value, in Toggle mode, for the duty cycle. Continuous Mode periods are too slow for my circuit.

Another thought is to use Up Mode. This has a faster overall period (with the SMCLK) in Toggle Mode but I do not think that TACCR0 will work here for duty cycle percentage -- just the overall period with the same duty cycle -- not changeable.

Third, ignore all of my thoughts listed here and, do you have an answer for the question at the top?

Thanks.

  • Some people do not want to use CPU to do ISR and restrict themselves to use the Timer hardware only. In that case, there is no solution in your case.

    If the desired transitions in the waveform are spaced with enough CPU cycles apart, almost any on/off waveform can be generated with Timer Output with the assistance of ISR.

  • You can’t eat the cake and keep it. You can't use CCR0 for controlling the PWM cycle time and for setting a PWM output duty cycle. I'm not even sure you can use CCR0 for PWM output at all (I actually never tried), as the documentation says the second action takes place at CCR0, not at timer overflow, which means, for CCR0, even if th etiemr runs in up mode, there is no way to set a duty cycle.

    At least you cannot do it in hardware. But virtually, you can do it this way:

    Let’s say, you want a PWM period of 1ms, the timer is clocked by 1MHz and your desired duty cycle is 10%. That means you want the output on for 100 timer ticks and off for 900.
    Stop the timer.
    Set CCR0 to TAR+1. CLEAR the OUT bit, set CCR0 to SET mode (this order!) and enable interrupts.
    Now start the timer. With the next timer tick, this will set TA0.0 and trigger an interrupt. In the ISR, you add 100 to CCR0 and switch to RESET mode. 100 timer ticks later, the output will be reset and another interrupt occurs. Now add 900 to CCR0 and switch to SET mode again. And so on.

    This allows different PWM periods for all CCRs, include using CCR0 for PWM.
    It does, however, prohibit duty cycles near 100% or 0%, as then the two interrupts may become too close to handle them in time. And if you fail to set the next trigger point before the timer has reached it, this will extend your current PWM period by one complete timer cycle (65ms in this case)

    So it’s best to use hardware PWM and do not use CCR0 as PWM signal, but rather to control the PWM cycle time.

  • I moved (blue wire :( fix)  to pin P3.0 that has full PWM function under Timer0_A3 Block#2 (MSP430G2333).

    Take away #1: The Timer0_A3/  _B3 Block#0 pins do not have the full PWM function. I changed Microcontrollers and had assumed (oops) that the Ports and port pins were the same across the MSP430G/F/FR family. There is still excellent consistent functionality across all of the family (it all works the same).

    Takeaway #2: Check every pin, every time, a different microController is used. 

**Attention** This is a public forum