Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Counter/compare special event interrupt
22-05-2013, 12:00 PM,
#1
Counter/compare special event interrupt
Hi folks,

I have a question concerning the interrupt handler in case of special event trigger.
Basically i want to have a periodic counter running (which is actually the purpose of this special event trigger) but i want to be able to modify the period of this counter. In the targeted application i need for efficiency reason, to modify the period in the interrupt itself. Here a draft of what i want to do:

void setup{
disable interrupt
configure timer
configure CCPCON for special event trigger
//optinally set high priority bit on this interrupt
set initial CCPR value
enable interrupt
start timer
}
void loop {
do stuffs here;
}

voit userinterrupt() { //or voir userhighinterrupt
if if (PIE1bits.CCP1IE && PIR1bits.CCP1IF){
do some stuff;
CCPR = new value
PIR1bits.CCP1IF=0;
}

I know that this type of code is at least compiling, but it doesn't seem to work properly on my pinguino 18f2550 (mainly looks like to enter either in infinite loop, or sometime reset, or sometime run for a time but do not seem to modify the register then stop working) depending of what is coded in the main loop.
For info, i have also defined the necessary defines so that my interrupt code is taken into account) and i know that it is working because on very simple interrupt (like toggle a port) the interrupt do its job.
Since i know also (since recently) that my uploader code is abit buggy (rev685) i wonder if this can be linked to the buggy uploader (to be honest i didn't verify the hex file on the PIC), or if this type of operation is simply not permitted/allowed/doable (and why ?)

What do yout think?
Regards
Joël
Reply
22-05-2013, 02:43 PM,
#2
RE: Counter/compare special event interrupt
It would be better to replace voit userinterrupt() with void interrupt() which is the right syntax for user interruption.
I don't see any problem in your "draft" except :
- CCPx pin should be configured as an input by setting the corresponding TRIS direction bit.
- Timer1 (or Timer3 depending how you configured CCPxCON) should be running in Timer mode or Synchronized Counter mode.
A piece of real code would help a bit more.
The uploader issue was (it has been fixed) only for boards with bootloader v4 and code > 16K.
Good luck.

(22-05-2013, 12:00 PM)joel Wrote: Hi folks,

I have a question concerning the interrupt handler in case of special event trigger.
Basically i want to have a periodic counter running (which is actually the purpose of this special event trigger) but i want to be able to modify the period of this counter. In the targeted application i need for efficiency reason, to modify the period in the interrupt itself. Here a draft of what i want to do:

void setup{
disable interrupt
configure timer
configure CCPCON for special event trigger
//optinally set high priority bit on this interrupt
set initial CCPR value
enable interrupt
start timer
}
void loop {
do stuffs here;
}

voit userinterrupt() { //or voir userhighinterrupt
if if (PIE1bits.CCP1IE && PIR1bits.CCP1IF){
do some stuff;
CCPR = new value
PIR1bits.CCP1IF=0;
}

I know that this type of code is at least compiling, but it doesn't seem to work properly on my pinguino 18f2550 (mainly looks like to enter either in infinite loop, or sometime reset, or sometime run for a time but do not seem to modify the register then stop working) depending of what is coded in the main loop.
For info, i have also defined the necessary defines so that my interrupt code is taken into account) and i know that it is working because on very simple interrupt (like toggle a port) the interrupt do its job.
Since i know also (since recently) that my uploader code is abit buggy (rev685) i wonder if this can be linked to the buggy uploader (to be honest i didn't verify the hex file on the PIC), or if this type of operation is simply not permitted/allowed/doable (and why ?)

What do yout think?
Regards
Joël
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
22-05-2013, 03:21 PM,
#3
RE: Counter/compare special event interrupt
Yes Thanks Regis,
i hadn't the code under my hand when i posted this thread... so the "draft"
but indeed the CCP and timer are configured as you write here
For the uploader i did'nt know that the issue was only for v.4 bootloader and code over 16k (which is,actually, the case of my test). HEnce i will test with a V2 bootloader and write a smaller test case (which i will post here).
For the fixed code with v.4 i know that it has been fixed recently, but i am unable to run properly (on win 7 64bits) the svn version (either the IDE do not start, or i have issue when compiling) and i am still "stuck" with the 685 version
Regards
Joël

(22-05-2013, 02:43 PM)regis Wrote: It would be better to replace voit userinterrupt() with void interrupt() which is the right syntax for user interruption.
I don't see any problem in your "draft" except :
- CCPx pin should be configured as an input by setting the corresponding TRIS direction bit.
- Timer1 (or Timer3 depending how you configured CCPxCON) should be running in Timer mode or Synchronized Counter mode.
A piece of real code would help a bit more.
The uploader issue was (it has been fixed) only for boards with bootloader v4 and code > 16K.
Good luck.
Reply
22-05-2013, 11:59 PM,
#4
RE: Counter/compare special event interrupt
Hello Regis, all

I have tested my idea for updating the periodic register in the interrupt core and it works like a charm.
Here is attached a crappy Big Grin but functionnal example
Tested with pinguino rev685, bootloader v2 on pic18f2550
(so far still have problems with the svn version. now it's gpasm which is stopping working suddenly rahhh)

.pde   test_sequencer.pde (Size: 4.41 KB / Downloads: 2)
Now dealing with accelleration or decelleration ramps of steppers or other little mechanical thingies in a (very) controlled way will be "delightful" Smile
Reply
24-05-2013, 03:37 PM,
#5
RE: Counter/compare special event interrupt
Hello all,

actually this example do not work really as nice as i told you in the previous post. Yesterday i took a brand new PIC, programmed the bootloader and updloaded this litltle code...and nothing happen on the pin which should be toggled with variable rythm...Sad
After many trials, tired, i finally get back to another code, lot more larger and complex, with serial com and other things (amongst them some interrupts too). This second code was working for the tested part (communication mainly). hence since this was working ok, get back to the code above,recompiled it, uploaded it...and the code was working...
So i believe that there is something initialized/setted in my large code, not erased by the upload which is necessary to make the code work..but what...Huh ((my idea is that the serial code set or unset some registers/configs necessary to make the interrupts works..but.
i have to test that with a new blanked PIC, put a serial com in my sample above, and see what happens!



Joël
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)