I am looking to control three motors via PWM and have with me a 16F877 as the main PIC. I also have a spare 16F88 so an idea dawned on me.
I can connect the OSC1 pin from the 16F877 to the OSC1 pin on the 16F88, leaving the OSC2 pin open on the 16F88. If mounted close enough, they should run in sync from a single oscillator which is connected to the OSC1 and OSC2 pins of the 16F877.
Since the host (a PC) will be sending commands to the PIC to drive the PWM signal, it is a one way direction of communication, and therefore could tie the RX line of the 16F877 and 16F88 together.
If both of them were to run with an interrupt on the RX receive, but each PIC scans for an 'identification' code within the stream of data - I could potentially be able to utilize the CCP1/CCP2 on the 16F877 to drive two motors and the CCP1 on the 16F88 to drive the third motor.
The alternative would be to dump the 16F88 and run two motors via the CCP1/CCP2 and use a regular I/O and software to control the third motor. However, I would like to run all the PWM using the on-board hardware peripherals if possible.
Does anyone think this is a good or bad idea? Any comments would be extremely appreciated - thanks!
Microchip has a free compiler for the 18's called the C18. The only restriction is that you can not do some optimizations after 60 days and you code get larger. Not a problem most of the time.
I think and ICD2 clone should be able to program the 18F1330 under MPLAB.
Seems that in the independent mode, the signal of PWM0 is duplicated on PWM1. However, in complementary mode, PWM1 would be the compliment of PWM0 after an OFF period called “dead time” between the going OFF of one pin to the going ON of the complementary pin of the paired pins.
Thanks picbits; luckily I only have three motors to control
bit 2-0 PMOD2MOD0: PWM Output Pair Mode bits
For PMOD0:
1 =PWM I/O pin pair (PWM0, PWM1) is in the Independent mode
0 =PWM I/O pin pair (PWM0, PWM1) is in the Complementary mode
For PMOD1:
1 =PWM I/O pin pair (PWM2, PWM3) is in the Independent mode
0 =PWM I/O pin pair (PWM2, PWM3) is in the Complementary mode
For PMOD2:
1 =PWM I/O pin pair (PWM4, PWM5) is in the Independent mode
0 =PWM I/O pin pair (PWM4, PWM5) is in the Complementary mode
Given the speed of these chips one could use a loop like this. It would allow one to use many output as a PWM.
Code:
forever {
turn on all that are active
set timer for time to first off
wait for timer
turn off first
set timer for time from 1st to 2nd off
wait for timer
turn off second
...
...
turn off last
set timer for time from last off to end of duty cycle.
wait for timer
}
convert it to use interrupts and it might work fairly well. One would need to pick a granularity that allowed enough time between interrupts.
I have never tried it.
Following the link brings up " RGB LED & PIC 18F876"
then it goes on to say,
"Decided to play with an RGB LED I got in one of my last orders. I happened to have a 16F876 on a breadboard for some reason, so it got used."
Following the link brings up " RGB LED & PIC 18F876"
then it goes on to say,
"Decided to play with an RGB LED I got in one of my last orders. I happened to have a 16F876 on a breadboard for some reason, so it got used."