PWM Max Frequency?


10 posts
by warrensk » Thu Feb 14, 2013 5:40 am
Hello, I am wondering what would be the best route for creating a high frequency signal to switch mosfets/transistors....I want to use the high frequency signal to pulse a coil at various frequencies, possibly making a resonant frequency graphing program. However this would be heavily reliant on the maximum frequency that can be achieved by the pwm or any of its other ports.

Thanks for any help
Posts: 4
Joined: Thu Feb 14, 2013 5:32 am
by gordon@drogon.net » Thu Feb 14, 2013 9:32 am
warrensk wrote:Hello, I am wondering what would be the best route for creating a high frequency signal to switch mosfets/transistors....I want to use the high frequency signal to pulse a coil at various frequencies, possibly making a resonant frequency graphing program. However this would be heavily reliant on the maximum frequency that can be achieved by the pwm or any of its other ports.

Thanks for any help


How high?

You might want to look at using a GPIO clock output - I put some support into the latest wiringPi for this, so you can feed a signal from 4600Hz to 19.2MHz using it. I'm wondering if that's too high for you though....

For PWM, the Pi's PWM output is by default not a typical mark:space waveform, but a balanced waveform, so it may not be what you're after - certianly the "frequency" becomes somewhat interesting to calculate, however you can put it into mark:space ratio mode then its more predictable, but it's still driven off the same 19.2MHz clock as above.

In the KHz and lower range, then you can generate reasonably accurate frequencies in software - look at the softTone module in wiringPi - it can generate a frequency from 0 to 5KHz - there is some jitter, but it's "good enough for jazz" ...

You can get more accurate in you dive into kernel land but the programming complexity goes up... But if you want to go there, then look for he servoblaster module - that would work as a good basis.

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1520
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by warrensk » Thu Feb 14, 2013 4:12 pm
Thanks gordon,

I want to go up to 15Mhz tops. Im after harmonics and the higher the frequency the better. If it can go up to 19.2 Mhz that will be plenty....I just know the arduino can only go to 500 hz or so...This was my decision of which one I should get depending on top frequency... Raspberry PI wins

Thanks again,

Warrensk
Posts: 4
Joined: Thu Feb 14, 2013 5:32 am
by gordon@drogon.net » Thu Feb 14, 2013 4:21 pm
warrensk wrote:Thanks gordon,

I want to go up to 15Mhz tops. Im after harmonics and the higher the frequency the better. If it can go up to 19.2 Mhz that will be plenty....I just know the arduino can only go to 500 hz or so...This was my decision of which one I should get depending on top frequency... Raspberry PI wins

Thanks again,

Warrensk


Not sure why you think the Arduino can only go to 500Hz - it can generate outputs much faster than that...

However Pi will be OK here - I only checked that my division sums were right to about 2.4MHz as that's the best my scope can go to though, but I think it'll be fine.

Image

that's 2.4MHz but do let me know if you can generate a 15MHz signal accurately - the clock has a 12-bit integer divider and a 12-bit fractional divider from the 19.2MHz clock to the output pin.

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1520
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by warrensk » Thu Feb 14, 2013 5:19 pm
@ gordon you are the man!

I tried searching for the same answer with the arduino and heard it may use most of its CPU while it does this, Also only a couple outputs are capable of faster frequencies... Im not sure how high it can go but its sounding like the R-Pi will be my best bet. Keep me updated if you have any more input. Ive got a little vortex coil Id love to pulse with this running my circuit and show some beautiful purple radiant energy. With the high frequencies and programming capable with up to 7-8 different outputs....talk about wave mixing!


Also, you said from 4600hz to 19.2mhz.....is the bottom frequency 4600 or can it go lower into the 10-100 hz range? I am looking for a full spectrum from 10 hz all the way up to 13-15Mhz. Ive got a spectrum analyzer that will be able to show how well it does in these high frequencies while it pulses a coil...finding the spacial resonant frequency will be a walk in the park with something of this capability.

-Warrensk
Posts: 4
Joined: Thu Feb 14, 2013 5:32 am
by gordon@drogon.net » Thu Feb 14, 2013 8:30 pm
warrensk wrote:@ gordon you are the man!

I tried searching for the same answer with the arduino and heard it may use most of its CPU while it does this, Also only a couple outputs are capable of faster frequencies... Im not sure how high it can go but its sounding like the R-Pi will be my best bet. Keep me updated if you have any more input. Ive got a little vortex coil Id love to pulse with this running my circuit and show some beautiful purple radiant energy. With the high frequencies and programming capable with up to 7-8 different outputs....talk about wave mixing!


Also, you said from 4600hz to 19.2mhz.....is the bottom frequency 4600 or can it go lower into the 10-100 hz range? I am looking for a full spectrum from 10 hz all the way up to 13-15Mhz. Ive got a spectrum analyzer that will be able to show how well it does in these high frequencies while it pulses a coil...finding the spacial resonant frequency will be a walk in the park with something of this capability.

-Warrensk


The bottom frequency is 19.2 / 4095 = ~4688.

You could use my softTone library to go from 0 to 5000, then the hardware above that - that may be adequate for your testing... But there is only one hardware clock generator avalable on the Pi. (Although the softTone library can control all the GPIO pins at once, if needed)

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1520
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by warrensk » Thu Feb 14, 2013 8:40 pm
@ gordon,

So to clarify, A written code could provide a program that could go all the way from 1hz-15mhz? or will it get pretty messy with separate programs?


Warrensk
Posts: 4
Joined: Thu Feb 14, 2013 5:32 am
by gordon@drogon.net » Thu Feb 14, 2013 8:48 pm
warrensk wrote:@ gordon,

So to clarify, A written code could provide a program that could go all the way from 1hz-15mhz? or will it get pretty messy with separate programs?


Warrensk


One program could do it, but it would need to use 2 technologys.

Actually if you use sofTone then you'll have to stop the program and re-start it - there is currently no proper way to turn it off (until you stop the program)- although you could set it to zero, then re-purpose the output pin to gpio clock mode.

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1520
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by Tzarls » Thu Jul 25, 2013 9:24 pm
Ok, regarding the lowest achievable frequency, I don´t know if this is what you´ve been talking about, BUT...

(using wiringPi)

Code: Select all
gpio mode 1 pwm
gpio pwm-ms
gpio pwmc 32
gpio pwmr 600000
gpio pwm 1 300000


I don´t have an oscilloscope, only an LED attached to the PWM pin, but I´m pretty sure I´m getting 1Hz from hardware here.... anybody care to test it with the appropriate equipment?
Posts: 65
Joined: Tue Feb 26, 2013 6:59 am
by 7eggert » Tue Nov 19, 2013 9:58 am
I've fond a better(?) thread about the clock settings for PWM.

http://raspberrypi.stackexchange.com/qu ... uency/8907

a) You have a clock of 19.2 MHz - f₁ = 19.2 MHz
b) plus a clock divisor giving you a related clock of 4.81 MHz down to 4.6 kHz - f₂ = f₁ / (clock+2) ?
(I guess you can use 0 == 4096, 1==4097 for this register?)
c) A range register further dividing the clock by up to 4096
d) A duty cycle register: if counter < dutycycle then outout := low else output := high;

Therefore you should be able to get about 1.14 Hz.
Posts: 1
Joined: Tue Nov 19, 2013 9:19 am