View previous topic :: View next topic |
Author |
Message |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
CCP, PWM and Hobby servo |
Posted: Thu Jun 07, 2007 7:53 am |
|
|
Hello,
I am working on an application which involves moving a hobby servo, in function of the ADC conversion of the RSSI signal.
Up till now - I think it was easier - I was always thinking on using 2 PIC processors, one for the ADC and another one for the servo.
In this version the two pics were talking to each other over HW UART, and that works well.
However a response to one of my posts got me thinking, that I could use the hardware CCP to time the pulses for the servo - this would eliminate the second PIC.
Can this be really done by the HW CCP module, I mean the PIC would be multitasking? Because I need the code to run on the PIC and in the mean time provide a stable pulse signal for the servo. The pulses for the servo are variable depending on the values received from the ADC between 0.7ms to 2.3ms - and these occur every 20ms.
I plan to use the 16F88 for this application.
Thankx, Ox. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Jun 07, 2007 8:29 am |
|
|
This should be feasible. When you write the code for the A/D don't use the built-in functions but rather set the 'GO/DONE' bit to start the conversion and then monitor it to detect when it is finished. Do all of this in your main() so that the CCP module can take priority over the A/D.
Ronald |
|
|
Ttelmah Guest
|
|
Posted: Thu Jun 07, 2007 9:43 am |
|
|
You can use the inbuilt functions:
read_adc(ADC_START_ONLY);
will start the ADC, and not wait for it.
read_adc(ADC_READ_ONLY);
Returns the last conversion.
You can monitor go/done, or just ensure there is enough time delay between these.
Best Wishes |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Jun 07, 2007 12:49 pm |
|
|
The servo has a minimum pulse width of 0.7ms. That should be plenty of time for the A/D.
Start the servo output
Start the A/D
Read the A/D
Do math
Wait the rest of the 0.7ms
Wait the calculated time
Stop the servo output _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|