Society of Robots - Robot Forum
Software => Software => Topic started by: navbot on February 27, 2011, 03:32:43 AM
-
Im using pic16f877A n i need it to run three modules of program in parallel:
*Motor control
*Sensor for obstacle detection
*Communication with bluetooth.
Will there be probs running these together in 1 pic??
-
The PIC is quite capable of doing this. Make use of the hardware resources and interrupt driven code to take the processing load off the CPU.
eg Motor control - use hardware pwm and interrupts then you only need to update a register every time you need to change a motor speed/position.
Communication - use RAM IO buffers along with the UART/I2C/SPI interrupts to load/fetch data only when it is necessary.
Sensors - use a timer and interrupts to regularly perform sensor reads, or pin change interrupts to react directly to sensor input, write the values to RAM.
These modules independently support a main control loop which polls for new sensor data and processes it, updates the motor speed/position registers as necessary, then polls for any new Comms input and does any output, and repeats.
Code in the interrupt routines should be kept as short as possible.
The PIC is more than capable... the only problems you face are coding the modules up to work together. ;)
Note - if you are about to do this in assembly, and don't have to or really want to, then think twice.
-
As hopslink said that PIC can do all three tasks using interrupts.
One of my Bots usies the PIC16F873, the 28pin version of the 16F877, and runs PWM for two motor, digital and analog inputs for sensors, I2C communication to Compass and another PIC and for and UART serial communication through an XBee.
Here is a good tutorial on PICs to help you get started:
http://www.gooligum.com.au/tutorials.html (http://www.gooligum.com.au/tutorials.html)
And here is a link to C code for I2C but this code also shows how to use TMR0 for a 'system tick' to schedule tasks in the main() code.
http://forum.sparkfun.com/viewtopic.php?f=6&t=22429 (http://forum.sparkfun.com/viewtopic.php?f=6&t=22429)