User avatar
CarlD26
Posts: 12
Joined: Thu May 02, 2013 12:16 pm

Timers on RPi??????

Fri May 03, 2013 10:48 am

Are there any timers that are accessible on the RPi?????
Coz i have searched a lot but could not find anything on this matter
also if i found something i could understand it
Will someone help me????
coz i am really interested in using the pi for different applications but i do not have much knowledge about it

stijn.ghesquiere
Posts: 26
Joined: Sat May 19, 2012 9:44 pm

Re: Timers on RPi??????

Fri May 03, 2013 7:28 pm

Could you elaborate a bit more on what kind of applications you have in mind?
What programming language you would like to use, what hardware is involved etc.
Perhaps we can help you then with practical suggestions and advice.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Timers on RPi??????

Fri May 03, 2013 7:34 pm

I have an application timing stuff down to the nearest millisecond which is dead accurate when run alongside an arduino with known good timekeeping. I believe it will do a lot better than millisecond timing with a good degree of accuracy.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
CarlD26
Posts: 12
Joined: Thu May 02, 2013 12:16 pm

Re: Timers on RPi??????

Sat May 04, 2013 6:34 am

I have four industrial servo motors that i have to run (which can run at max 150 khz)
So i need to generate pulses for motors (to rotate) and need logic 0 and 1 for direction
I want it to control these motors with the RPi in the same way as PIC does
So i also need to know how accurately this can be done
I am using python as the programming language

User avatar
joan
Posts: 14937
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timers on RPi??????

Sat May 04, 2013 6:57 am

CarlD26 wrote:I have four industrial servo motors that i have to run (which can run at max 150 khz)
So i need to generate pulses for motors (to rotate) and need logic 0 and 1 for direction
I want it to control these motors with the RPi in the same way as PIC does
So i also need to know how accurately this can be done
I am using python as the programming language
Do you mean the servos need updating 150 times a second? What pulse widths do they expect?

User avatar
rpdom
Posts: 17189
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Timers on RPi??????

Sat May 04, 2013 7:11 am

joan wrote:
CarlD26 wrote:I have four industrial servo motors that i have to run (which can run at max 150 khz)
Do you mean the servos need updating 150 times a second? What pulse widths do they expect?
150 KHz would be 150 thousand times a second.

User avatar
joan
Posts: 14937
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timers on RPi??????

Sat May 04, 2013 7:17 am

rpdom wrote:
joan wrote:
CarlD26 wrote:I have four industrial servo motors that i have to run (which can run at max 150 khz)
Do you mean the servos need updating 150 times a second? What pulse widths do they expect?
150 KHz would be 150 thousand times a second.
Yes it is.

Mind you if it needs a 150,000 updates a second they will be fairly short pulses.

Might be more helpful to have a pointer to the specifications of these servos.

User avatar
CarlD26
Posts: 12
Joined: Thu May 02, 2013 12:16 pm

Re: Timers on RPi??????

Sat May 04, 2013 7:27 am

time period = 1/ frequency
where,
frequency= 150khz = 150000 hz
thus,
time period = 6.666 microsecond
and
duty cycle = 50%
which means,
On time = 3.33 microsecond
Off time = 3.33 microsecond
is this possible??????

User avatar
joan
Posts: 14937
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timers on RPi??????

Sat May 04, 2013 8:22 am

It might be tricky.

The only way I can think of is by using DMA to time the pulses. All the stuff I've done has been in units of microseconds (as I'm principally interested in sampling gpios and the clock I use to time-stamp has a microsecond resolution).

I just set up 4 PWM outputs at 40KHz with different pulse widths using the DMA technique on the Pi.
pwm1.png
pwm1.png (34.4 KiB) Viewed 1730 times
pwm2.png
pwm2.png (36.3 KiB) Viewed 1730 times
For the sharp eyed I mistakenly set gpio15 to 4KHz rather than 40KHz.

I redid the trace with different pulse widths.
pwm3.png
pwm3.png (29.8 KiB) Viewed 1713 times

User avatar
CarlD26
Posts: 12
Joined: Thu May 02, 2013 12:16 pm

Re: Timers on RPi??????

Sat May 04, 2013 10:07 am

Hi Joan,
I am curious to know how did you simulate the Pulses on the UI. Coz my objective is to show runtime update of the XYZUV axis i.e. (5axis) position in micro meters on the UI. So far i have been successful doing the same on my dsPIC33 controller but now i would want to achieve the same using the Raspberry Pi.

User avatar
joan
Posts: 14937
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timers on RPi??????

Sat May 04, 2013 10:49 am

CarlD26 wrote:Hi Joan,
I am curious to know how did you simulate the Pulses on the UI. Coz my objective is to show runtime update of the XYZUV axis i.e. (5axis) position in micro meters on the UI. So far i have been successful doing the same on my dsPIC33 controller but now i would want to achieve the same using the Raspberry Pi.
I have developed a library called pigpio which I use to generate PWM/Servo pulses, sample the level of gpios, and for general gpio stuff.

I configured the library to sample at 1 microsecond and notify me (via a pipe) when the PWM pins I'd started PWM pulses on were seen to change state. The PWM generation and gpio sampling are both handled by the library (via DMA) but are independent. The data isn't simulated. I convert the logged data to a vcd (value change dump) format understood by GTKWave.

User avatar
CarlD26
Posts: 12
Joined: Thu May 02, 2013 12:16 pm

Re: Timers on RPi??????

Fri Jun 21, 2013 1:40 pm

Thanks for the tip Joan. It worked perfectly using DMA on the pi. I was able to generate pwm pulses with small time periods (in microseconds).

User avatar
joan
Posts: 14937
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timers on RPi??????

Fri Jun 21, 2013 1:49 pm

Good.

If I understand correctly you are generating square waves with the ability to change the frequency.

plugwash
Forum Moderator
Forum Moderator
Posts: 3618
Joined: Wed Dec 28, 2011 11:45 pm

Re: Timers on RPi??????

Fri Jun 21, 2013 2:20 pm

RC servos respond to pulse width. The normal way to drive them is to keep the frequency the same while varying the duty cycle.

User avatar
joan
Posts: 14937
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Timers on RPi??????

Fri Jun 21, 2013 2:35 pm

plugwash wrote:RC servos respond to pulse width. The normal way to drive them is to keep the frequency the same while varying the duty cycle.
Yes, I may have fixated on the example given which was a square wave (duty cycle 50%). If it is a traditional pulse width control then I wonder how many steps he's achieving between off and fully on.

Return to “General discussion”