How do you control 8 servos with one CCPR1? I mean how is it loaded.. If the CCPR1 is servicing 8 different values.. Am I missing something?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
unsigned int servo[] = { 1500, 1500, 1500, 1500,
1500, 1500, 1500, 1500 };
void interrupt isr() //
{ static unsigned char mask = 0; // servo output pin mask
static unsigned char n = 0; // servo array index, 0..7
if(CCP1IF) // if "special event" interrupt
{ CCP1IF = 0; // clear the interrupt flag
if(LATB ^= mask) // toggle the servo output pin
{ CCPR1 = servo[n]; // servo "on" time, 1000..2000 usecs
} //
else
{ CCPR1 = 2500 - servo[n]; // servo "off" time, 500..1500 usecs
mask <<= 1; n++; // setup for next servo
} //
if(mask == 0) // if last servo (20-msecs)
{ mask = 1; n = 0; // reset mask and index
}
}
}
This made me remember something, The compare match clears timer1 and so the above code is wrong. The lines setting CCP1 shouldn't be += just =. I.E CCP1 = servoPos[n] etc. The Special Events Trigger mode has (unfortunately) been removed from the newer chips.Please note that unlike the other "compare" modes, the special event trigger mode resets the CCPR1 register pair on a compare match.
Some of the newer chips have PWM "pulse steering" which works quite nicely for servos. Unlike the "soft" servo methods, it's a hardware solution (no jitter) and since the PWM module is buffered you have plenty of time to service the PWM driver interrupt (you can turn off interrupts for short periods of time, if necessary, without affecting the servos). It's really a pretty nice hi-rez low-overhead servo solution...The Special Events Trigger mode has (unfortunately) been removed from the newer chips.
In my 18F2321 (I know we are talking of a 16F) the compare function allows to reset the timer not the ECCP.Please note that unlike the other "compare" modes, the special event trigger mode resets the CCPR1 register pair on a compare match.
With PICs, to use PWM for servos, the "secret" so to speak, is to have an additional prescaler allowing to output a frequency, low enough, as required by them.
That is common (not sure if with all PICs) with ECCP modules. In some of the manuals (if not all) the example on how to reach 50 Hz is detailed with numerical values.
IIRC, 18F4431 is one.
That is not how you use the PWM module to drive servos. Did you even bother to read this thread?As I said in a very early post, you cannot get the prescalers to slow to 50Hz pwm. You also need to slow the CPU clock speed from 4MHz to 500kHz. That allows hardware to control the update.
Alternatively, a servo sets with a couple 50Hz pulses and holds x
For some time if you want to set other servos and then loop to check and update each servo
As I said in a very early post, you cannot get the prescalers to slow to 50Hz pwm. You also need to slow the CPU clock speed from 4MHz to 500kHz. That allows hardware to control the update.
Alternatively, a servo sets with a couple 50Hz pulses and holds x
For some time if you want to set other servos and then loop to check and update each servo
Did you not read the thread either?Here you have it. As I said, at 40 MHz; nothing less.
Sorry it is the Power Control Module.
View attachment 122178
Any chance you or Gophert can provide an example? Does the method provide a usable pulse width resolution?
TIA... Mike
/* * PWM registers configuration * Fosc = 1000000 Hz * Fpwm = 62.00 Hz * Duty Cycle is about 12.2 % (2 mSec) * Prescaler is 16 * Config pwm pin as output */ PR2 = 0b11111011 ; T2CON = 0b00000111 ; CCPR1L = 0b00011110 ; CCP1CON = 0b00101100 ; // If you want 1 mSec for other extreme, set...
|
Wow, 4 bits of resolution. Oh well.
Mike.
Let's not start a war!! Christmas an all!! There are some places where 16 levels would be fine... All's good..Do you constantly need some kind of validation? If you think everything in life is a competition, professional help is available and happiness is possible. Keep your local suicide prevention hotline number available - the holidays are difficult for people with your symptoms.