Shop OBEX P1 Docs P2 Docs Learn Events
Trouble resetting the RTCC timer — Parallax Forums

Trouble resetting the RTCC timer

baba40baba40 Posts: 13
edited 2009-07-12 19:17 in General Discussion
HI to all those whose skill sets exceed mine (suspect that's just about everyone on this forum.)

I have created some SX/B code that starts a one minute timer using·the RTCC timer.· I attempted to write
the code so that when the minute elapses, the RTCC is reset and the whole process starts over again.· While
the process works for one pass, it does not loop and start again.· It just appears to stop.· I have added
and LED based trace (which is included in the attached file), and it appears the second pass stops at the
OPTIONS=$88·command at the end of the "start:" routine.

I suspect there is register (or some other basic housekeeping chore that has escaped me) that needs to be
reset that I am missing as I can restart the process by hitting the reset button.· Ideally, I would like to reset
and restart·the RTCC timer without going through a full cold start.

Any help or insights would be greatly appreciated!

Best

Nimbus43

Comments

  • 5ms?5ms? Posts: 21
    edited 2009-06-29 22:24
    Hi baba40.
    In SX-Key Help, There is a SX/B Example: Clock / Timer .

    5ms
  • Me_LeeMe_Lee Posts: 7
    edited 2009-06-29 23:37
    Have a look at this, I think it will help.

    www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol8/col/nv152.pdf
    nv152 said...

    SX/B as Task Master
    This is the biggest and most involved update to SX/B 2.0 is task management. Using tasks allows us to setup and
    schedule automated processes; this are like subroutine but are called by a task scheduler instead of by us. For
    example: let’s say we want to check a sensor every 100 milliseconds no matter what else is going on in the program.
    With tasks we can do that pretty easily.
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-06-30 00:33
    You can use the rate parameter of the INTERRUPT keyword to have SX/B set the correct RTCC return value automatically. If, for example, you wanted the interrupt to run every 10us you would use

    INTERRUPT 100_000

    ... where the rate is 100,000 interrupts per second.
  • baba40baba40 Posts: 13
    edited 2009-07-01 22:29
    Hi,

    I want to thank those who have responded to my query.· While the idea of converting my timer to a task based process
    is something I never considered, in looking at Jon's code, the program that will incorporate the timer can't suffer the fair
    amount of additional code. I will, however,·keep the task concept in mind for other adevntures.

    I am investigating the rate parameter suggestion, but wonder just how big the value could be?· for example would a 10
    minute timer using a value of 1,000,000 be too large.· Put another way, is there any documentation around covering the
    use of the interrupt·rate parameter?

    And finally,·could 5ms? tell my where I can·find his reference to SX-Key help.

    You guys have been great and have vastly expanded my horizons.· I didn't expect to be taken to the places·referenced
    in your responses.· I·look forward to your comments to the above.

    Best,

    Nimbus43

    ·
  • PJMontyPJMonty Posts: 983
    edited 2009-07-02 06:01
    Nimbus43,

    Regarding the help file:

    1 - Start the IDE.

    2 - Open the menu Help->SX/B Help.

    3 - Expand the section that says "Example Projects" in the help file.

    4 - Locate the project and read it.

    Thanks,
    PeterM
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-07-02 16:58
    You need to set the INTERRUPT rate parameter based on timing needs of your program. For example, I have an intervalometer (time-lapse controller) that uses an interrupt rate of 80_000 so that I can use the ISR to modulate an IR LED at 40kHz. I also need a one-second timer to run in the ISR and this was built, manually, using assembly and three bytes (you can't count to 80_000 with a word).

    The point is that you can do what you want to do -- you just need to think it through and find the lowest common denominator. Remember, the faster your INTERRUPT rate, the less time you have between interrupts which means you limit the amount of code you can place in the ISR. My suggestion is that you make the ISR rate as low as possible to do what you want to do. And avoid tasks if possible as they add a GIGANTIC amount of [noparse][[/noparse]necessary] overhead to the ISR.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-07-08 17:46
    Hello,

    I’m not sure about some of the things you’re doing with the RTCC settings…based on the delay length you want I would think you would set the prescaler to RTCC rather than WDT and you would set a higher prescaler value instead of 1:2/1:1. In any event I see where you’re enabling the RTCC in your main code and I see where it is being disabled in the interrupt code. Unfortunately I don’t see anywhere where you’re attempting to re-enable it. This would support the idea of the loop running once and not again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-07-08 20:44
    Nimbus
    I agree with Chris; there seems to be no re-enable.
    Just curious about this too:
      ....
    

     if minutes<>1 then iout
    ' minutes roll over to main program
       OPTION=$C8
       p=1
       goto Start
    
    iout:
    'RETURNINT 50 'This doesn't appear to work.  Had to implement assembler
    'retiw instruction that follows.
    ASM
    mov w,#-50 'Interrupt very 1us
    retiw
    ENDASM  
                                 
    ' =========================================================================
    PROGRAM Start
    ' =========================================================================
    
    Start:
    

    ...
    

    Was the goto start there when you tried the RETURNINT 50?

    cheers,
    - Howard

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-07-08 22:47
    Oh wow Howard! I didn’t even see that! So it seems the code is not returning properly at all. In fact it would/should hit the other OPTION command, but I’m not sure the effect of never returning from the interrupt…the shadow registers would not be restored nor would the PC be popped from the interrupt stack. Oh this is going to get messy.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • baba40baba40 Posts: 13
    edited 2009-07-09 16:43
    Hi to all who are contributing to this dialogue.· I especially want to thank Chris and Howard for their
    recent contributions.

    I hope it is not premature to say that I am somewaht releaved to learn that I am not going nuts!
    The logic is so simple that I originally thought I was over looling something obvious (may not be out
    of the woods on that, yet).

    Just a brief note on the use of assembler for the ISR return.· While the SX/B compiler allows you to
    to replace "retiw" and the use of the offset (in this case -50), when I tried it, it did not work properly.
    While the code executed, it appeared that the timing loop slowed down by one or two orders of
    magnitude so that instead of executing:

    if minutes<>1 then iout················ 'set for a one minute period for debugging

    and causing the process to fall out of the interrupt after one minute, it would take over 10
    minutes.· By replacing "RETURNINT" (supposedly you do not need to include the offset value[noparse][[/noparse]-50] as
    with "retiw") with the following snippet of assember, I was·able to restore the correct timing created
    by the interrupt code.

    iout:
    ASM
    mov·w,#-50···················· 'Interrupt very 1us
    ·retiw
    ENDASM

    I look forward to the continuing dialogue·on this issue and want to thank Chris (and perhaps others withing Parallax), Howard and
    all those who have and may add their insights going forward.· Thanks for your help with this and the restoration of my mental
    health (I hope).

    Baba40
  • baba40baba40 Posts: 13
    edited 2009-07-09 16:57
    HI again,

    An additional brief note to my last response. It appears from traces I have run that the OPTION=$C8 does execute as I can validate proper
    sequecing both after the "if minutes<>1 then iout 'set for a one minute period for debugging" instruction (i.e. the program correctly
    jumps to start after the prior OPTION command, and that the init code carried in "start" routine executes properly UP TO the OPTION=$88
    statement.

    Hope this helps.

    Baba40
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-07-10 21:03
    Baba40,

    So after removing the GOTO in your ISR you’re still having problems?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • baba40baba40 Posts: 13
    edited 2009-07-11 15:02
    Chris,

    If you are referring to the GOTO in the following snippet, yes.

    ' minutes roll over to main program
    OPTION=$C8
    p=1
    goto Start

    The program appears to successfully jump to "Start" (so I assume that the OPTION=$C8 is
    executing properly and disables the RTCC timer). From the LED trace it also appears the the
    "Start" sequence executes properly UP TO the OPTION=$88 (RTCC enable) where the program
    stops. If I hit reset on the dev. board the program commences at start and the the OPTION=$88
    does execute causing the program to jump to org 0 initiating the interrupt timer routine.

    So, at the end of 1 or 10 minutes, depending on how I set the value in the loop, the sequence falls
    through the loop executing the OPTION=$C8 and the jump to "Start". Consequently, it appears that
    either the OPTION=$C8 or OPTION=$88 or both do not execute and that the only way to force the a
    second or n number of enablings of the timer is to hit reset.

    I hope this clear. As I said before, this coding sequence is not rocket science, so I am at a loss to
    under stand why only a hard reset is the only way to relaunch the timer.

    As always, I appreciate your continuing help.

    Nimbus43
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-07-11 19:59
    I may be missing something but you seem to be going about this the hard way. I actually needed a similar 1-second timer for my time-lapse controller. The way I did it was to use a cascading timer in the ISR that would set a flag when one second had elapsed, then the timer would restart at 0. The foreground code monitored this flag and when it was detected, acted on it and then cleared it so that the ISR could set it again at the end of then next elapsed second.

    The attached program works the same, toggling an LED every 10 minutes. Looking at the compiled output I determined that no __PARAMx vars are used in the ISR so the NOPRESERVE option is fine.

    Post Edited (JonnyMac) : 7/11/2009 8:05:44 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-07-12 19:17
    I would really look at what JonnyMac has to offer. I can find some bugs or issues in your code, but getting good programming advice for your application is what you really need right now. I am all for having reference designs for anything, including code. Why re-invent the wheel? =) Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.