Pages: [1] 2   Go Down
Author Topic: function to generate a PPM output?  (Read 3333 times)
0 Members and 1 Guest are viewing this topic.
India
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Electronics is clearly the winner of the day, Anyday and Everyday!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How to create a function which generates a ppm pulse as a RC would? i want this function to be running in the background untill i change it.
what changes do i need to make to the following code?
Code:
void ppm_gen(int pin, int speed) {
digitalWrite(pin, HIGH);
delayMicroseconds( speed);
digitalWrite(pin, LOW);
delay(20);
}
From what i can understand this function will run only once and the control will return to the calling function.
But to run a servo the loop should run over and over again.
If my understanding correct, what changes should i make?
Logged

 ∙•● яÁђนl ●•∙

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

Use the servo library Luke ....
Logged

India
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Electronics is clearly the winner of the day, Anyday and Everyday!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes but the refresh rate is 30Hz, very low for my liking.
I need to run an ESC for a bldc. I need it to be atleast 200 - 250Hz.
Logged

 ∙•● яÁђนl ●•∙

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26219
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An RC ESC will expect PPM at 50Hz (which is the frame rate the servo library works at, not 30Hz).
Is this not an RC ESC?
« Last Edit: October 01, 2011, 07:51:34 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@rahlk

Let me understand what you are asking... I read about servos, a PWM @ 50 Hz is slow for you, OK so you need PWM @ 200 to 250 Hz instead , correct ?  OK Let analyse a PWM ... @ 50 Hz Period = 1/50 = 0.02 s  or 20 ms @ 200 Hz Period = 1/200 = 0.005 s or 5 ms.  So a PWM is changing Ton vs Toff  , therefore Ton < Toff --> < 50 %  Ton > Toff --> > 50 %   Ton = Toff --> 50 %.... Follow me so far...So your program have to reflect that. So if you whant the speed to increase, Ton have to increase  -->  Speed /\ Ton  Lower speed , lower Ton Speed \/ Ton.

Here an example of a code of a PWM @ 1000 Hz. Hope it help.

Code:
// Compile and Tested

byte PWMpin = 11;
byte vpin=0;


int vin=0;
int period=1000; // 1 kHz = 1 / Period in uS
int timeA;  // time on
int timeB; // time off

void setup()
{
  pinMode(PWMpin, OUTPUT);
}

void loop() 
{
  vin=analogRead(vpin);
  timeA=map(vin,0,1023,0,period); // calculate time on
  timeB=period-timeA; // calculate time off 
  digitalWrite(PWMpin, HIGH);
  delayMicroseconds(timeA);
  digitalWrite(PWMpin, LOW);
  delayMicroseconds(timeB);
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26219
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Tech one,
RC equipment uses PPM, not PWM
Your arithmetic looks...suspect.
« Last Edit: October 01, 2011, 12:12:43 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@AWOL

PPM is ? Pulse ? Modulation ...

edit again :

Quote
Your arithmetic looks...suspect.

What you mean my math look "suspect" ?    My technical writting skills is not that great you know.

Edit :

PPM = Pulse Position Modulation  

Like this site : [urlhttp://www.simplecircuitdiagram.com/2009/05/20/pulse-position-modulator-using-555-ic/][/url]

So in the program you simply keep Toff constant.  You simply figure out @ lower frequency the Ton and @ higher frequency the Ton with a constant Toff using speed has a variable to change Ton.  
« Last Edit: October 01, 2011, 12:32:18 pm by Techone » Logged

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1063
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@Techone
 
If you want to know the difference between ppm and pwm :

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253149521/all



Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26219
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Tech one
"20ms @ 200Hz" doesn't make a great deal of sense.

Yes, low duty cycle PWM looks a lot like PPM.
However, unless you use very high resolution PWM (I.e. greater than 8 bit), your active PPM period (< 10%) is going to have very poor resolution.

However (again) RC gear is designed to run at a frame rate of 50Hz, so simply shortening the frame time may not work at all.

Maybe the OP is confusing the ESC's control input PPM rate with its output PWM frequency.
« Last Edit: October 02, 2011, 02:39:00 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@AWOL

Quote
OK Let analyse a PWM ... @ 50 Hz Period = 1/50 = 0.02 s  or 20 ms @ 200 Hz Period = 1/200 = 0.005 s or 5 ms.

I mean ---> AT 200 Mz Period = ..... I forgot a DOT after 20 ms

I mean : @ 50 Hz Period = 1/50 = 0.02 s  or 20 ms
            @ 200 Hz Period = 1/200 = 0.005 s or 5 ms

Opps ...  smiley-red

Sorry that I sound confusing sometime.

I just trying to help the OP.  Anyway, RC is Remote Control ?  and ESC ?  

In a program to generated a PWM or PPM, you still need to control Ton, Toff and the Period.

Edit:

@Erni

Thank for the link. Interresting.
« Last Edit: October 01, 2011, 07:32:49 pm by Techone » Logged

India
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Electronics is clearly the winner of the day, Anyday and Everyday!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@AWOL
Quote
An RC ESC will expect PPM at 50Hz (which is the frame rate the servo library works at, not 30Hz).
Is this not an RC ESC?
Yes it is an RC ESC. Some wise men around told me this refresh rate of 50Hz is not good for an RC ESC and it runs best at 200Hz and a max of 300Hz.

Thanks for the link from Erni, and from a "GOD" member MEM. I figured that the servo does run from a ppm pulse after all. The ON time varies from 1000 Microseconds to 2000 Microseconds with the OFF time being constant at 20 milliseconds. So my initial snippet was correct. But all this, they still don't answer my question- what should I do to have this function running in the background untill it's changed.
Logged

 ∙•● яÁђนl ●•∙

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But all this, they still don't answer my question- what should I do to have this function running in the background untill it's changed.

 You just need to use the standard Arduino servo library. You write a value to it and it automatically continously sends it out to the servo (read ESC) input at the proper rate until you write a new value. This is handled by interrupts but you don't have to do anything for that to happen.

Lefty

Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9548
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some reading on ESCs.

http://www.google.com/search?q=arm+esc+site%3Ahttp%3A%2F%2Farduino.cc%2Fforum%2Findex.php&hl=en&num=100&lr=&ft=i&cr=&safe=images
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26219
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know your 'wise men', but I'd say they are not terribly experienced with RC gear.
If an ESC is designed for RC, then it EXPECTS PPM with a frame time of 20ms.
 This is the frame rate used by digiprop RC gear for at least the last 30 years.
It may not work well at different frame rates.
Servos frequently don't.

The output frequency may well be much higher, as I mentioned earlier.

Or maybe you simply misunderstood the wise men.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Or maybe you simply misunderstood the wise men.

That's my guess, wise men often speak in strange tongues.  smiley-wink

Logged

Pages: [1] 2   Go Up
Jump to: