TC PWM mode dynamic usage

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everybody!

 

How it possible to use TC PWM in dynamic way?

 

First of all, how it possible to force and hold PWM output to binary 0 after/before PWM CNT cycle without (discard/new) setup the timer?

 

Next, I need to change pulse parameter for every new period. It can be done by Top interrupt at begin of a new period.

Other words, how it possible to change CCx and TOP (PER) during generation of PWM pulse.

 

Thanks for any advise.

Last Edited: Wed. Jul 19, 2017 - 11:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think You can use the buffered register for that so that you can change the value before the TOP so that you don't get glitches. Otherwise just select an interrupt that suites you (capture interrupt is one I would use) and select the number needed for next pulse.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok. I try it!

 

But still open, how I force PWM output pin to 0 (or 1) without setup again the timer?

If I stop the timer, the I need to setup all register again (long time) if I wish to send the next pulse.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

just write CTRLA clksel bits to 0 to stop the timer and use CTRLC CMPx bits to set the outputs after that. After that just reset CNT register and start the timer again from CTRLA.

Last Edited: Tue. Jul 11, 2017 - 08:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huh, that is tricky!

 

I try it!

 

Thank you guys.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys, the freeze is works but I still have trouble.

 

If I set TC to normal mode (deattach io pin from TC), then I can set state of IO pin, but I cant start PWM mode again without setup the all timer.

I tried invert trick. Invert IO pin to “mix” desired output at freeze of PWM , but it not works.

I ty to manipulate period, cc and count register to “mix” desired output, but it not works.

 

So any advise.

Last Edited: Wed. Jul 19, 2017 - 11:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

use CTRLC CMPx bits to set the outputs after that

As stated above, after you have set up the timer on those pins you can't just use the port register to change output values, you have to use CTRLC register to do so (TC in PWM mode).

 

What are you using to control the timer anyway? show code (using code tags!) 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Because this code is very complex and linked with other device IT-s I show you a simplifyed  flow chart:

 

start:
set pwm single slope mode (CTRLC)
set cc and top for first pulse
start (defreeze) timer

underflow it:
set cc and top for next pulse

cc comp it:
if last then:
freeze timer using clksel = off

This code above works fine except I have no control of IO out pin if the timer are freeze.

According your idea I extend the code with:

 

set_freezed(state):
set normal mode (CTRLC)
set io pin (state)

reset_freezed:
set pwm single slope mode (CTRLC)

It called only if timer is freeze. But it is not works.

I tried with invert trick:

set_freezed(state):
if state:
set pin invert mode

reset_freezed:
reset pin invert mode

But still not works.

I try to manipulate cnt register:

 

set_freezed(state):
if state:
set cnt above cc
else:
set cnt below cc

reset_freezed:
return

But still not works.

 

I have an last idea.

I send pulse and freeze timer in a desired count value (output state).