V71 - 8 independent PWM frequency outputs (all 50% DC)

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

Hello everyone!

 

I'm trying to determine the best way to have 8 independent frequencies on 8 different pins using a V71 device.  Not planning on doing anything special DC wise, just going to use a 50% DC on all channels.  Just need them to operate at different frequencies. 

 

I'm currently trying to set it up using the ASF 4/Atmel Start framework and I'm having issues determining if it's possible.  I was setting up PWM0 to make use of PWMC0_PWMH0-3 to have independent frequencies but it would appear that all PWM0 ports all seem to be clocking out the same data (which I don't really understand the purpose of).  Same story with PWM1.

 

What peripherals should I be using if I wanted to setup eight independent frequencies?  Should I be using the TC timers instead (and can I set frequencies independently) or another peripheral? 

I can probably figure out how to setup the peripherals in START once I know which peripherals I should be using but want to make sure I'm using the correct peripherals for the job.  Any help you can give me would be greatly appreciated.  Thanks!

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

If there are not enough timers, maybe you can use some of the available serial peripherals to generate more square waves? Like the USARTs or SPI.

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

Quote:
the best way to have 8 independent frequencies on 8 different pins 

 

You'll need 8 different timers. Or do it in software with 8 little DDSes.

Mike

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

If you don't have 8 timers, it may be possible to

have one timer produce multiple frequencies. I

only know the AVR timers so I might use different

names for things, but this is the thinking. If I had

to create two frequencies from one timer, I'd set

up the TOP value for the lower frequency in CTC

mode. CTC means (clear timer on compare match)

which is how you get a faster frequency than just

using the overflow. The timer counts from 0 to the

TOP value and then goes back to zero.

 

Then for the higher frequency, determine what it

would need for a TOP value if it was being directly

created by the timer. This value will be less than

the TOP for the lower frequency. Make note of the

difference between these values.

 

As an example, suppose you are using an 8-bit timer

and the TOP values for the two frequencies are 227

and 198. Put the timer into CTC mode and set the

TOP value to 227 (the lower frequency). Also set the

compare match value for each to 227 and choose

the toggle-pin-on-match mode for the outputs. This

is enough to get the low frequency working.

 

For the higher frequency, you also will need a compare

match interrupt. All it needs to do is modify the match

value so the next time a match will occur sooner. This

example requires subtracting 29 from the current

match value, modulo 227. The first time through, a

match occurs at 227. The second time through, 198.

Then 169, 140, 111, etc.

 

This will work fine as long as there is plenty of time

for the interrupt to perform the calculations before the

timer gets near the new match value. So for any shared

timers, configure them to generate the lowest frequencies.

 

--Mike

 

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

avr-mike wrote:

If you don't have 8 timers, it may be possible to

have one timer produce multiple frequencies. I

only know the AVR timers so I might use different

names for things, but this is the thinking. If I had

to create two frequencies from one timer, I'd set

up the TOP value for the lower frequency in CTC

mode. CTC means (clear timer on compare match)

which is how you get a faster frequency than just

using the overflow. The timer counts from 0 to the

TOP value and then goes back to zero.

 

Then for the higher frequency, determine what it

would need for a TOP value if it was being directly

created by the timer. This value will be less than

the TOP for the lower frequency. Make note of the

difference between these values.

 

As an example, suppose you are using an 8-bit timer

and the TOP values for the two frequencies are 227

and 198. Put the timer into CTC mode and set the

TOP value to 227 (the lower frequency). Also set the

compare match value for each to 227 and choose

the toggle-pin-on-match mode for the outputs. This

is enough to get the low frequency working.

 

For the higher frequency, you also will need a compare

match interrupt. All it needs to do is modify the match

value so the next time a match will occur sooner. This

example requires subtracting 29 from the current

match value, modulo 227. The first time through, a

match occurs at 227. The second time through, 198.

Then 169, 140, 111, etc.

 

This will work fine as long as there is plenty of time

for the interrupt to perform the calculations before the

timer gets near the new match value. So for any shared

timers, configure them to generate the lowest frequencies.

 

--Mike

 

 

Yeah, realistically, they're all going to be fairly similar frequencies (10kHz, 11 kHz, 12kHz, etc).  The chip says it has 12 timers onboard, just trying to determine what that looks like from a hardware output perspective.  It appears to have the following pins:

TIOA0-TIOA11
TIOB0-TIOB11
TCLK0-TCLK11

It looks like those are my 12 timers.  If I can set the thresholds for each with the correct modes, it looks like that's my best bet.  As much as I'd like to use the PWM channels, it doesn't look like they're setup in a way that can be used for 8 different frequencies.  Based on this, I might want to expand from 8 frequencies to 12, potentially. 

 

I'll have to poke around with it a bit more on Monday, figure out the best way to set all this up.  Thanks for all your help, everyone!  I should have more updates on Monday (though I'm up for any additional suggestions anyone wants to toss into the ring). 

Thanks again!

 

 

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

 a V71 device

a what?  atmega71?  

 

Edit:  Oh, I see, it is not an Atmel AVR at all

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Mar 15, 2019 - 01:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone!

I just wanted to follow up on this in case someone else ends up reading this down the road looking to do something similar.  I found a timer setup on page 1697 of the datasheet that looks like what I want to do:

 

 

 

Basically, if I setup RC to produce the frequency I want and set RA to be 50% of RC, I should get the waveform I want on TIOA.  If I want 8 different frequencies, I'll have to do this on 8 different timers.  Still need to poke around at the registers to determine how to set this up correctly but at least I found the concept I was looking for.  Hopefully this helps someone else out!

If, for whatever reason, someone has seen some sample code on how to setup the registers for something like this, I wouldn't be opposed to checking it out! 

Thanks again for the suggestions, everyone!

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

Glad you could find it... almost 2000 pagessurprise

 

"That's no moon... It's a datasheet."

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

avrcandies wrote:

 a V71 device

a what?  atmega71?  

 

Edit:  Oh, I see, it is not an Atmel AVR at all

I presume a "V71" means ATSAMV71? This is the downside of Atmel's curious decision to put the "ASF/Start" forum within the AVR area of the website.

Last Edited: Thu. Mar 21, 2019 - 10:09 AM