View previous topic :: View next topic |
Author |
Message |
RF_Geek
Joined: 24 Sep 2008 Posts: 9
|
50Hz PWM |
Posted: Tue Oct 21, 2008 12:21 am |
|
|
I am trying to control my DC motor using an electronic speed controller which controls the DC motor with a 50Hz PWM frequency. But i believe that with 8Mhz clock (Internal clock) the lowest frequency i can produce is about 480Hz.
The DC motor moves backwards when the duty cycle is 7.5% and forward at 9%.
I am using the PIC18F4550.
Exactly how do i produce a 50Hz signal? could someone help me on how to produce a 50Hz signal either using timer 1 or timer 2.
I will also be using one of the timers to control a servo for the steering.
Thank you. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
RF_Geek
Joined: 24 Sep 2008 Posts: 9
|
|
Posted: Tue Oct 21, 2008 1:15 am |
|
|
Thank you PCM for your help.
I will only be using one Servo, but the code helps, its a good example. I am trying to control the servo using a digital compass ($HCHDG string) the heading from the digital compass to control the servo.
Any thoughts on how to produce 50Hz PWM signal, and exactly how do we calculate the value for PR2.
I am trying to generate 50Hz signal, unfortunately i believe with a 8Mhz clock it is not possible to produce a signal smaller than 480Hz.
Any Suggestions.
Last edited by RF_Geek on Tue Oct 21, 2008 1:58 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: 50Hz PWM |
Posted: Tue Oct 21, 2008 5:17 am |
|
|
RF_Geek wrote: | ...The DC motor moves backwards when the duty cycle is 7.5% and forward at 9%.... |
As you look through the various software PWM routines that have been mentioned, keep in mind that the RC servo is not really responding to the duty cycle percentage as such. It is responding to the actual on-time (around 1 to 2 mSec). So if your overall period changed from 20 mSec to 15 mSec, but the on-time remained fixed at 1.2 mSec, there would be no change in the servo's response, even though the duty cycle percentage changed from 6% to 8%. _________________ Robert Scott
Real-Time Specialties
Embedded Systems Consulting |
|
![](templates/subSilver/images/spacer.gif) |
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Wed Oct 22, 2008 1:50 am |
|
|
The regular PWM is indeed too fast for the 50Hz rate you need for a hobby servo. But you can easily set up a timer to give you the "on" time and then set it again to give you the "off" time. Just think in terms of time intervals rather then a PWM duty cycle. And as Robert Scott said, the "on" time is what really counts, so you might choose to keep a fixed "off" time, and save some calculating. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Thu Oct 23, 2008 9:25 pm |
|
|
Thank you All,
Could you guys help me on how to setup the on and off time. I know how to setup the PWM pulse and how to vary the duty cycle.
That was for the Servo, i still need the 50Hz to run my DC motor.
Currently i am playing with the Servos.c file in the PIC C library, but my servo is still now working.
Thank you guys, i really appreciate all the help. |
|
![](templates/subSilver/images/spacer.gif) |
RF_Geek
Joined: 24 Sep 2008 Posts: 9
|
|
Posted: Fri Oct 24, 2008 5:43 pm |
|
|
PCM and RLScott,
Thank you very much.
Yes you are right i need to vary the on and off time just changing the duty cycle is not enough.
I am currently trying to to use the Servos.c file in PIC C library.
Few questions?
Servo Left and Servo Right does it refer to two different servos?
Second when i am trying to compile the compiler is finding an error in the header file.
I am just trying to output PWM pulse, but its not compiling i would really appreciate some feedback.
Thank you.
The Error i am getting is mentioned below
Quote: |
*** Error 128 "SERVOS.c" Line 102(1,39): A #DEVICE required before this line
1 Errors, 0 Warnings.
|
Code: |
#include "main.h"
#include <servos.c>
#include <18F4550.h>
void main()
{
setup_oscillator(OSC_8MHZ|OSC_NORMAL|OSC_PLL_OFF);
init_servos()
void set_servo(left, forward, 1)
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
RF_Geek
Joined: 24 Sep 2008 Posts: 9
|
|
Posted: Fri Oct 24, 2008 6:11 pm |
|
|
Thank you PCM.
But i have a question here, i cannot use a trimpot in the project that this servo is intended for.
I am basically trying to take in a digital compass string and based on that bearing turn the servos.
I will get back to you.
Thank you. |
|
![](templates/subSilver/images/spacer.gif) |
RF_Geek
Joined: 24 Sep 2008 Posts: 9
|
Program doesn't work |
Posted: Sun Oct 26, 2008 3:13 am |
|
|
PCM,
Thank you for all your help, i am having some problems trying to compile the sample program you directed me to earlier, even when i copy the same program using the microcontroller it gives me the same error.
I am using CCS 4.057
The error
*** Error 128 "SERVOS.c" Line 102(1,39): A #DEVICE required before this line
1 Errors, 0 Warnings.
Please help i copied the code "as is" posted online.
Thank you |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
RF_Geek
Joined: 24 Sep 2008 Posts: 9
|
|
Posted: Sun Oct 26, 2008 2:24 pm |
|
|
No i am using CCS PIC C, but i do have the mplab 8 plugin installed. Could that cause the problems.
I am just copying the same program posted online and just compiling and it is finding an error in the Servos.c file " the file requires some #device". |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 26, 2008 2:37 pm |
|
|
It's all CCS PIC C.
Do you have MPLAB or the CCS IDE ? The "IDE" is sold under these
names: PCW, PCWH, or PCWHD. Do you have one of those ?
If you do, then someone else will have to help you with the "Device"
error message. I don't have the CCS IDE. I only have MPLAB and use
it with the CCS command line compilers.
Also, if you are using the CCS demo, you should tell us. |
|
![](templates/subSilver/images/spacer.gif) |
|