View previous topic :: View next topic |
Author |
Message |
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
multiple timer functions on 16F877 |
Posted: Sat Dec 31, 2005 12:39 pm |
|
|
I've separately coded and tested most of the functions that I want on a robot but I now have to put them together in one program on a 16F877. I'm now wondering if that is even possible and was hoping that somebody with a feel for this type of thing could offer some insight.
I'm got functions for the following:
1. A gyro input. I use timer_o to create a 1500 uS pulse.
2. A gyro output. I use CCP_2 to get the duty cycle.
3. Accelerometer output. I use CCP_1 to get the duty cycle.
4. PWM for 2 motors. I previously used CCP_1 and CCP_2 for these.
5. I have a future need for a timing cycle for 2 wheel encoders.
I think I can use timer_2 for function 5. but obviously I can't do 4. with 2. & 3.
Any suggestions?
Thanks.....Harry |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 31, 2005 1:24 pm |
|
|
I would use a multi-tasking system to control things that run at a
relatively low speed, and then use PIC modules for a hardware
assist, for things that run at higher speeds. By "low speed", I mean
things that can be timed or supervised at a 10 ms rate ("tick"), such
as debouncing a push-button switch. By high speed, I mean performing
a tachometer function with the CCP. Thread on multitasking:
http://www.ccsinfo.com/forum/viewtopic.php?t=17189
It may be that you have too many high speed processes, and you
don't have enough PIC peripheral modules to handle all of them.
You might have to use two or more PICs. I think this is why the
topic of using a PIC as an i2c slave comes up on this board so often. |
|
|
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
|
Posted: Sun Jan 01, 2006 11:09 am |
|
|
Thanks PCM, that was useful information.
PCM programmer wrote: | It may be that you have too many high speed processes, and you don't have enough PIC peripheral modules to handle all of them. You might have to use two or more PICs. I think this is why the topic of using a PIC as an i2c slave comes up on this board so often. |
I know that using another PIC would be a fallback solution but one that I would like to avoid. I'm using a commercial board and adding another chip would take some effort.
I'm using timer_0 as a 'tick' for the gyro input. That leaves me with 4 high speed requirements that are best done on CCP1 and CCP2. Two are PWM functions and two are capture functions.
I'm a little fuzzy on how timers and interrupts work when several are being implemented in one program. If I were to try to implement this on one chip could I put the 2 DC motors on CCP1 and CCP2 for PWM and still use timer_1 to write some code within a function that emulates the 2 'capture' routines? Or would I have to resort to using timer_2 to try to do this? Is anything like this even possible?
Thanks....Harry |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 02, 2006 6:12 pm |
|
|
I think the best thing would be to look at a robotics website, and see
if they have figured out a way to cram that many features into one PIC. |
|
|
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
|
Posted: Tue Jan 03, 2006 1:38 pm |
|
|
PCM programmer wrote: | I think the best thing would be to look at a robotics website, and see
if they have figured out a way to cram that many features into one PIC. |
I went to another website and got the following advise.
Quote: | 1. leave it on TMR0
2, 3, 5: if ~ 10us resolution is OK you can set up timing loop. Alternatively
use PORTB interrupt on change to capture timing
4. Use hardware PWM. |
I'm trying to implement this scheme now.
Thanks...Harry |
|
|
|