Shop OBEX P1 Docs P2 Docs Learn Events
Quick Question: Periodic Interrupts AND pin-triggered interrupt? — Parallax Forums

Quick Question: Periodic Interrupts AND pin-triggered interrupt?

SteelSteel Posts: 313
edited 2008-09-18 21:34 in General Discussion
Unfortunately, I don't have my dev board with me, and I need to select a chip for a layout.

for a project, I need to do a PWM output, and I need to monitor a portB pin to trigger an interrupt.

Can I use the SX-28 and set the Interrupt to be periodic (to run a pwm) *AND* still trigger an interrupt from the PortB Pins (to execute other interrupt code)?...or do I need to use the SX-48 and have the·PWM running in a different section?


Sorry for asking.· I wish I had my chips in front of me to find out myself, but I don't.· [noparse]:([/noparse]


·

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-18 19:52
    You can, but since the timer doesn't have its own interrupt pending bit, you have to check it on entry and before exit from the ISR to see if it rolled over (or will roll over before the RETI) while servicing the pin interrupt. It's tricky, but doable.

    -Phil

    Addendum: Here's the ISR structure I use to accommodate both kinds of interrupts (assumes turbo mode and 1:4 RTCC prescaler):

            ORG     isrPG
    ISR     MOV     W,#2            ;If RTCC low enough, then must be timer interrupt...
            MOV     W,RTCC-W
            BANK    sysREGS
            JNC     :RTCISR         ;Yup, must be timer interrupt.
    ;       
            MOV     RTCCQ,W         ;Nope, save current value minus 2 for later check.
    ;
            MODE    M_WKPND         ;Access port B pending registers... (M IS NOT RESTORED!!!)
            MOV     !RB,#%00000000
            AND     W,#SCLKM        ;The interrupt we're interested in.
    ;
            JZ      :CKRTC          ;If no serial clock interrupt, we're done here.
            
    ;-------------------------------------------------------------------------------------------
    ;       Code for pin interrupt goes here (synchronous serial clock, in this case).
    ;-------------------------------------------------------------------------------------------
            
    :CKRTC  MOV     W,#3            ;Will a timer rollover occur before the RETI?
            ADD     W,RTCC
            JC      :CKRTC          ;  Yes. Wait for it. (No carry when RTCC hits zero.)
            MOV     W,#2            ;Look at ISR entry value of RTCC.
            ADD     W,RTCCQ
            MOV     W,RTCC-W        ;Is the current value lower?
            SNC                     ;  Yes: A rollover has occured.
            RETI                    ;  No: No rollover. Just get out.
            
    :RTCISR
    
    ;-------------------------------------------------------------------------------------------
    ;       Code for timer interrupt goes here.
    ;-------------------------------------------------------------------------------------------
                    
    :RTCEND MOV     W,#RTCON        ;Add constant to RTCC on way out for proper rate...
            RETIW
    
    
    

    Post Edited (Phil Pilgrim (PhiPi)) : 9/18/2008 9:37:54 PM GMT
  • SteelSteel Posts: 313
    edited 2008-09-18 21:25
    Thanks, Phil. I appreciate it.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-18 21:34
    Steel,

    I forgot to note: my code example is for turbo mode with a 1:4 prescaler on RTCC. Other settings will entail changing some constants in the code.

    -Phil
Sign In or Register to comment.