View Full Version : Using CCP modules
steven114
11-02-2006, 11:59
I'm trying to count a fast-moving encoder, and instead of having thousands of interrupts firing every second I thought it would be a good idea to use the CCP modules in Capture mode to count the number of ticks. However, ifi_aliases.h says that CCP2-5 all have output buffers on them that prevent them from being used in Capture mode, even if you select USER_CCP in the code. Is it true that there is _no_ way to do this? If not, what happened to CCP1? I couldn't find it mentioned anywhere in the documentations, and cross-referencing from the PIC datasheet to the RC docs didn't turn up anything. Anyone know if CCP1 is available for use?
Thanks,
Steven
Kevin Watson
11-02-2006, 12:47
I'm trying to count a fast-moving encoder, and instead of having thousands of interrupts firing every second I thought it would be a good idea to use the CCP modules in Capture mode to count the number of ticks. However, ifi_aliases.h says that CCP2-5 all have output buffers on them that prevent them from being used in Capture mode, even if you select USER_CCP in the code. Is it true that there is _no_ way to do this? If not, what happened to CCP1? I couldn't find it mentioned anywhere in the documentations, and cross-referencing from the PIC datasheet to the RC docs didn't turn up anything. Anyone know if CCP1 is available for use?
Thanks,
StevenSection 17.1.2 of the data sheet might be of interest. This document might also help: http://kevin.org/frc/robot_controller_signal_map.pdf
-Kevin
steven114
11-02-2006, 13:05
Thanks very much for pointing those out - here's what I'm reading from them. ECCP2 can change which pin it uses, depending on how you set up the register. By default it is assigned to RC1, which is PWM13 and IFI says is unusable as a Capture input. If you are in microcontroller mode, it goes to RE7 which is not available for use. If not, it is attached to RE3 which is Relay 4 Fwd. Is it possible to use that as an input, or is there circuitry on the inside preventing this? Can I simply set the appropriate pin to input and not use relay 4? Are we in "microcontroller" mode? It seems to be set by the configuration register, which is programmed by IFI, correct?
Thanks for any pointers,
Steven
steven114
11-02-2006, 14:51
Ok, a few more things:
I tried to read the contents of CONFIG3L and CONFIG3H, which have the information regarding microcontroller mode and the ECCP2 multiplexing.
char *CONFIG3L = 0x300004, *CONFIG3H = 0x300005;
printf("Init CONFIG3L=%d CONFIG3H=%d",(int)(*CONFIG3L),(int)(*CONFIG3H));
prints out two sets of 0. Any reason this wouldn't work? It seems that most of the registers have handy named variables, but none of the CONFIG registers do. The documentation says that they are mapped into the memory space, so I don't see why a pointer dereference wouldn't grab the value... any other way to read these registers?
Kevin Watson
11-02-2006, 15:21
Ok, a few more things:
I tried to read the contents of CONFIG3L and CONFIG3H, which have the information regarding microcontroller mode and the ECCP2 multiplexing.
char *CONFIG3L = 0x300004, *CONFIG3H = 0x300005;
printf("Init CONFIG3L=%d CONFIG3H=%d",(int)(*CONFIG3L),(int)(*CONFIG3H));
prints out two sets of 0. Any reason this wouldn't work? It seems that most of the registers have handy named variables, but none of the CONFIG registers do. The documentation says that they are mapped into the memory space, so I don't see why a pointer dereference wouldn't grab the value... any other way to read these registers?Sorry, I don't really have time to research this. Try using the p18f8722.h header file for the memory-mapped variables.
-Kevin
Post a message over at ifirobotic's forum.
steven114
11-02-2006, 16:04
It doesn't have the CONFIG registers memory-mapped, unfortunately. Thanks for your help; I guess I'll have to go for an external solution or maybe just interrupt really quickly... If anyone else has any ideas (or has gotten it working in the past!), though, I'd be happy to hear them! :)
[EDIT] Joel: good idea, I think I'll do that...
steven114
13-02-2006, 12:43
For the record:
http://www.ifirobotics.com/forum/viewtopic.php?p=588#588
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.