Topics Topics Edit Profile Profile Help/Instructions Help Member List Member List  
Search Last 1|3|7 Days Search Search Tree View Tree View  

PIC18F - Updating CCPR1 avoiding unex...

:: EPE Chat Zone ­:: ­Radio Bygones Message Board :: » EPE Forum Archives 2007-2009 » Archive through 30 June, 2007 » PIC18F - Updating CCPR1 avoiding unexpected interrupt « Previous Next »

  Thread Last Poster Posts Pages Last Post
  ClosedClosed: New threads not accepted on this page        

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

atferrari
Frequent Contributor
Username: atferrari

Post Number: 400
Registered: 05-2005


Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 23 June, 2007 - 03:55 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

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 - Buenos Aires - Argentina
Top of pagePrevious messageNext messageBottom of page Link to this message

epithumia
Frequent Contributor
Username: epithumia

Post Number: 438
Registered: 06-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 23 June, 2007 - 10:33 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Hi Agustín,

You've really got me thinking here. Microchip's documentation glosses over this issue. I found an application note that just does a 16 bit add with no precautions, but it didn't explain why that was OK.

I had assumed that CCPR1H:L was one of those special registers where you write one byte but it doesn't transfer to the real register until you write the second byte, but I was wrong.

If Microchip were smart then the output wouldn't toggle while the interrupt flag was still set, but the datasheet doesn't say that they were smart!

I think you've already spotted the robust solution:
avoid the toggle mode and get your interrupt routine to switch between 'set on match' and 'clear on match', making sure that this is not done until after CCPR1H:L is added. (Also don't clear the interrupt bit until after the add, of course). As I recall, your code already toggles between two different add values, to altering CCP1M0 is no real overhead.

I'd like to hear if there's a solution using the toggle mode. I looked on the Microchip forum, but you got there first!

Just to be clear, is this just an academy question about whether it's possible to use toggle mode instead or set/clear, or are you really stuck?

Regards,
Rob
If you need me, Neil and me will be hanging out with the Dream King. - Tori Amos
Top of pagePrevious messageNext messageBottom of page Link to this message

epithumia
Frequent Contributor
Username: epithumia

Post Number: 439
Registered: 06-2006

Rating: N/A
Votes: 0 (Vote!)

Posted on Saturday, 23 June, 2007 - 10:41 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

The other simple solution, which would only work if adding a big enough number, is this:

TempH:L = CCPR1H:L + HALFT1
CCPR1H = TempH
CCPR1L = TempL

If updating CCPR1H puts the next event far enough in the future then there's plenty of time to tweak CCPR1L.

Rob
If you need me, Neil and me will be hanging out with the Dream King. - Tori Amos
Top of pagePrevious messageNext messageBottom of page Link to this message

atferrari
Frequent Contributor
Username: atferrari

Post Number: 401
Registered: 05-2005


Rating: N/A
Votes: 0 (Vote!)

Posted on Sunday, 24 June, 2007 - 04:48 pm:   Edit Post Delete Post Print Post    Move Post (Moderator/Admin Only)

Thans for the input, Rob.

Tomorrow I expect to have time to spend with MPSIM in my laptop.

Sure I will post the outcome. I want a robust solution to be able to forget this problem, forever.

Intuitively (I could be dead wrong) I feel that I should mess first with the high or lower part of CCPR1, according to the values (of what...?) .
Agustín Tomás - Buenos Aires - Argentina

Administration Administration Log Out Log Out   Previous Page Previous Page Next Page Next Page