Pages: [1] 2 3   Go Down
Author Topic: PWM @ 140hz?  (Read 4922 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34122
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: September 04, 2009, 09:28:52 am by winmutt » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 133
Posts: 6749
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, here is the code for a duamilanove board using the unique 16-bit timer.
Code:
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:
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:
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:
OCR2B= <new value>;
where PW=OCR2B/OCR2A
« Last Edit: October 19, 2009, 10:49:09 pm by selfonlypath » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah OK, thanks for clarifying!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need a driver to step-up voltage because all arduino outputs are TTL smiley-wink
« Last Edit: October 22, 2009, 11:36:51 pm by selfonlypath » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess this thread will help some thanks.

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

France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 262
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Pages: [1] 2 3   Go Up
Jump to: