Go Down

Topic: PWM @ 140hz? (Read 5747 times) previous topic - next topic

winmutt

I need a period of 7.1ms and be able to modify duty cycle within that. The closest I can get looks to be 125hz, is that correct? Is there a shield that will facilitate this or am I stuck with 125hz or bitbanging?

Grumpy_Mike

The PWM is a function of the timers and the oscillator, it is not something that can be corrected by a shield. You can use a shield (extra hardware) to build another PWM circuit and have the period to just what you want.

Quote
The closest I can get looks to be 125hz, is that correct?


Without going into it I can't say, how are you altering it.

As a final point do you really need it to be that precise?

winmutt

#2
Sep 04, 2009, 04:25 pm Last Edit: Sep 04, 2009, 04:28 pm by winmutt Reason: 1
I am interfacing with an actuator for controlling vanes on a turbo charger. We are trying to retrofit new technology on ancient diesels. According to the documentation you can modify the interrupts oif the AVR8 timer to produce 125hz (122hz). You can also produce other frequencies but that is by adjusting the duty. I need to be able to adjust the duty from 0-100% @ 140hz. A friend with an oscilloscope got this reading and was able to apply that frequency to the actuator and have it move appropriately. I have asked him to check and see if 125hz works as well because as best as I can tell 140hz is an oddball frequency for PWM.

I am a programmer not an engineer, but am picking up quickly.

westfw

140Hz PWM should be pretty easy to do in software, depending on how many steps you need and how evenly spaced the steps need to be...  (although if you're controlling real-world thing with that, you'll need to be a little careful about having the SW do other things...)

winmutt

That's my concern, I will be reading other analog and digital inputs and calculating duty cycle on that.

selfonlypath

About generating 140Hz, don't know if you have duamilanove or mega board but fairly easy to do in both cases using 16bit-timer. For example, here is one possibility with mega board but there are many other ways to do...
Code: [Select]
int outputPsuB = 45;  // Timer5-B

void setup()
{
// PSU outputs via timer5
 pinMode(outputPsuB, OUTPUT);  // select Pin as ch-B
 
 TCCR5A = B00100010; // Phase correct PWM change at OCRA
 TCCR5B = B10010;  // prescaling by 8 the system clock
 OCR5A = 7143; // 139,9972Hz
 OCR5B = 2357; // 33% PWM
 }


PWM = OCR5B/OCR5A

winmutt

Thanks, I have the duamilanove. So this will set the frequency to 133,9072hz and then I control duty cycle analogWrite?


selfonlypath

#7
Oct 20, 2009, 04:44 am Last Edit: Oct 20, 2009, 05:49 am by selfonlypath Reason: 1
Ok, here is the code for a duamilanove board using the unique 16-bit timer.
Code: [Select]
int outputPsuB = 10;  // Timer1-B

void setup()
{
 pinMode(outputPsuB, OUTPUT);  // select Pin as ch-B
 
 TCCR1A = B00100001; // PWM, Phase and frequency correct - change at OCR1A
 TCCR1B = B10010;  // prescaling by 8 the system clock
 OCR1A = 7143; // 139.9972Hz
 OCR1B = 2357; // 33% PWM
 }  


To control duty cycle, you just do it for example by changing OCR1B but leaving constant OCR1A which defines your 139.9972Hz frequency close enough from 140Hz
Code: [Select]
OCR1B= <new value>;
where PW=OCR1B/OCR1A

If you want to use timer2 which only has 8 bits, you'll get less PW resolution along with a frequency of 140.1345Hz instead of 139.9972Hz
Code: [Select]
int outputPsuB = 3;  // Timer2-B

void setup()
{
 pinMode(outputPsuB, OUTPUT);  // select Pin as ch-B
 
 TCCR2A = B00100001; // PWM, Phase correct - change at OCR2A
 TCCR2B = B1110;  // prescaling by 256 the system clock
 OCR2A = 223; // 140.1345Hz
 OCR2B = 50; // 22.42% PWM
 }  


To control duty cycle, you just do it for example by changing OCR2B but leaving constant OCR2A which defines your 140.1345Hz frequency close enough from 140Hz
Code: [Select]
OCR2B= <new value>;
where PW=OCR2B/OCR2A

winmutt

Ah OK, thanks for clarifying!

winmutt

Another quesion, the PWM voltage at 100% duty is only 5v? What if I need 10v?

selfonlypath

#10
Oct 23, 2009, 06:35 am Last Edit: Oct 23, 2009, 06:36 am by selfonlypath Reason: 1
You need a driver to step-up voltage because all arduino outputs are TTL ;)

winmutt

Not sure what that means for me, I'm such a noob. My input voltage is 12v, is the PWM still 5v?

winmutt

Not sure what that means for me, I'm such a noob. My input voltage is 12v, is the PWM still 5v?

winmutt

I guess this thread will help some thanks.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=print;num=1232562874

selfonlypath

what is your arduino board type and what is your power supply voltage powering your arduino  ?

In any case, your arduino output pin generating PWM 140Hz will always be TTL (off=0V - On=5V) even if your board power supply is for example 12V.

what is your vane actuator spec: voltage & current needed to operate properly ?

depending on your actuator spec, you'll need to design a driver to either step-up voltage from TTL to fhigher voltage and/or boost current if your actuator needs more that max current tolerated by arduino TTL output

In resumé: your arduino can software generate PWM 140Hz with a TTL logic level output but you might need to adapt this signal to your actuator spec


Go Up