Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 23rd June 2007, 03:12 PM   (permalink)
Default PIC18F - Updating CCPR1 avoiding unexpected interrupt

Micro family 18F

Module CCP1 in compare mode against TMR1 in timer mode.

Setting: "toggle output pin (RC2) on match condition".

My application currently loads alternatively CCPR1H:L with HALF_T1 and HALF_T2 and restarts TMR1. (It works OK like that).

Trying to follow the frequent advice received, to leave TMR1 running alone and ADDING the next value to CCPR1H:L, here is my question:

How to add the low and high bytes of next HALF_Tx, without risking to have an undesired match BEFORE both are added? In extreme cases this actually WOULD happen in my application. Tested.

For other settings I know how to do it (changing CCP1M0) but no for "toggle on match". Any change of a single bit from CCP1M3:CCP1M0 would enter in an undesired condition, so I discarded that.

I find this problem mentioned somewhere but no solution explained for this case.

I want to retain the "toggle on match" setting.

Help appreciated.
__________________
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
atferrari is offline   Reply With Quote
Old 24th June 2007, 02:09 AM   (permalink)
Default

The problem can be fixed by altering the order that things are done. When you add to CCPR an interrupt may be generated and so you have to make sure that this spurious interrupt doesn't cause a problem. If you have not changed the direction of the output pulse then the spurious interrupt will not have any effect.

The order things should be done is,
Write to CCPRL/H.
Toggle CCP1M0.
Clear CCP1IF.

Mike.
Pommie is online now   Reply With Quote
Old 24th June 2007, 03:37 PM   (permalink)
Default

Sorry Pommie; from my orginal post:

I want to retain the "toggle on match" setting.

I will keep trying and post the outcome even if takes me long time.
__________________
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
atferrari is offline   Reply With Quote
Old 25th June 2007, 12:20 AM   (permalink)
Default

Sorry, I should have read your original post more carefully. I don't understand why you want to keep the toggle on match setting but as you do, can you simply decrement the high byte before writing low then high of CCPRL/H. This should eliminate any spurious matches.

Mike.
Pommie is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Question about Interrupt tinhnho Micro Controllers 3 11th February 2007 07:07 PM
how to give 120degree phase shift i've written a code esconele Micro Controllers 18 16th February 2006 12:49 PM



All times are GMT. The time now is 04:59 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.