Shop OBEX P1 Docs P2 Docs Learn Events
Interesting TIMER observation — Parallax Forums

Interesting TIMER observation

Craig43Craig43 Posts: 11
edited 2005-03-03 16:37 in General Discussion
I am using TIMER 2 in the CAPTURE/COMPARE MODE. When the capture 1 pin is triggered the TIMER copies the contents of the counter register to the capture 1 register and then initiates an interrupt.

What's interesting is that if you read the capture register in the interrupt service routine (ISR), and save it for use outside of the ISR, then it works. But if you read the capture register outside of the ISR then you always get $FFFF for the value.

It appears that you MUST save the contents of the capture register in the ISR, because when you leave the ISR, you lose it. Is this correct?

Also, because you have to read the capture register in the ISR, it means you have to change the MODE register. But when you enter the ISR, the MODE register is not automatically saved. And since it may be in use at the time the interrupt occurred, it seems like it is necessary to save the MODE register in the ISR before using it. Is this correct? And if so, can you read the MODE register?

Craig

Comments

  • Craig43Craig43 Posts: 11
    edited 2005-03-02 17:48
    I just noticed a discrepancy in the documentation.

    In the SX-KEY Development System Manual, Version 2.0, Page 175, it indicates that the MODE register is not saved when an interrupt is initiated.

    In the SX48 Data Sheet it DOES indicate that the MODE register is saved when entering an ISR. Great, that answers the second half of my previous question.


    Craig
  • pjvpjv Posts: 1,903
    edited 2005-03-03 03:05
    Hi Craig;

    Just to make sure of the facts; only the SX48/52 save the mode in a shadow register. The smaller units do not.

    Peter
  • Craig43Craig43 Posts: 11
    edited 2005-03-03 08:01
    Hi Peter,

    That's correct, I have an SX48 here. I would have thought that when the Timer transferred the contents of the counter to the capture register that you could read the capture register any time and get the value. It would only be changed when the next capture event occurred.

    But for some reason if you read the capture register outside of the ISR you get FFFF. Really strange. I know the code is good because all I do is cut and paste from the foreground task to the ISR. In the ISR I get a valid result, outside of the ISR I get FFFF.

    I can't find anything in the DataBook about that.

    Craig
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-03-03 11:40
    Peter (pjv),

    do you know if the SX 48/52 devices have just one shadow register for mode, or do they have a 2-level shadow stack, similar to the other shadow stacks. If so, is there another secret instruction to deal with the mode shadow stack?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • pjvpjv Posts: 1,903
    edited 2005-03-03 15:00
    Hi Guenther;

    I had been wondering about that myself; for some reason I can't remember why, I believe it is only single level deep, but I'll check that out.

    Peter (pjv)
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-03-03 16:37
    Hi Peter,

    would be interesting for me to know for keeping SXSim up-to-date. For now, I have implemented just one mode shadow register. This will be available in the next version of SXSim to be released soon.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
Sign In or Register to comment.