Shop OBEX P1 Docs P2 Docs Learn Events
Disable interrupts while in an isr? — Parallax Forums

Disable interrupts while in an isr?

For learning purposes I have written an rctime program using smart pin mode TIME_A_HIGH with an isr set to look for data ready. However, when I charge the RC circuit (after getting a reading) I think the event handler sees the pin go high and triggers an unwanted interrupt (see screen shot).

So I put a 'hack' in the code to scrub unwanted rdpin values .

1) Is there a way to disable the interrupt within the isr?
2) Where can I find a good document of P2 interrupts and pre-defined event types?
3) I also am looking for a document covering pre-defined Smart Pin Constants and usage.

I have a lot of history with P1 but am trying to garner skills with the P2. One of my problems is coping with the lack of documentation. It seems many instruction in the PASM2 manual do not have descriptions or snippet examples. Much of my effort has been trial and error.

Comments

  • evanhevanh Posts: 16,027
    edited 2023-07-14 18:16

    Definitive documentation is the three Google docs written by Chip - https://www.parallax.com/propeller-2/documentation/
    I have used Google Docs file menu to download a set of PDFs that I use all the time.

    The Spin2 Language Doc is the one with all the symbol definitions listed at the end.
    The Prop2 Silicon Doc has its font messed with though, so not easy to read right now. Err, it's been fixed. :)

  • evanhevanh Posts: 16,027

    Try adding Schmitt Trigger to the pin mode to reduce noisy triggers - P_HIGH_TICKS | P_SCHMITT_A

  • JonnyMacJonnyMac Posts: 9,158
    edited 2023-07-15 01:49

    I'm a simpleton, so forgive my simplistic approach.

    Are you wanting to read an old-school joystick that uses an RC circuit? If not, wouldn't the P2s analog input capability be easier?

    Back to the RC circuit, it might take a few more lines of code, but would using a timed interrupt and state driven code work? Like you, I have a lot of experience with the P1, including several commercial devices. In one, a simple WAV audio player, I run a background loop at 1ms and read the RC circuits like this.

    var
    
      long  lvolpot                                                 ' left volume pot level
      long  rvolpot                                                 ' right volume pot level
      long  lvollast
      long  rvollast
      long  pottimer                                                ' timer for pots measurement
    
    
    pri read_vol_pots                                               ' call only from support()
    
      case pottimer
        00 :
          dira[L_VOL] := 1
    
        02 :
          phsa := 0        
          dira[L_VOL] := 0
    
        05 :
          lvolpot := (0 #> ((phsa >> 4) - 33) <# 400) >> 2    
    
        10 :
          dira[R_VOL] := 1
    
        12 :
          phsb := 0         
          dira[R_VOL] := 0
    
        15 : 
          rvolpot := (0 #> ((phsb >> 4) - 33) <# 400) >> 2     
    
      if (++pottimer => 24)                                         ' read pots 40x/second
        pottimer := 0
        wav.set_left(LVol * lvolpot / 100)
        wav.set_right(RVol * rvolpot / 100)
    

    It's simple, but it works, and with 40 updates/second, there is no detectable "steppiness" when changing volume during playback

  • evanhevanh Posts: 16,027

    Another refinement to the pin mode is make it like an open-collector where the HIGH is driven but a LOW is not driven. Then the smartpin doesn't need turned off to use OUTH/DRVH to rechange the capacitor. - P_HIGH_TICKS | P_SCHMITT_A | P_OE | P_LOW_FLOAT

    Note: P_LOW_FLOAT removes any ability to drive low. This is important since the smartpin redirects the DIR pin control signal to itself, which means, with P_OE set, the pin is always driven at the logic control level. So FLTx and DIRx can't tristate the pin.

  • You have to love this forum. The smart pin re-definition making the smart pin a Schmitt trigger with open collector worked. There is no need to cancel the smart pin mode, but it is necessary to reset the smart pin after the charge cycle to accurately get the discharge time.

    You can't argue with success. I need to go back and study the pin circuitry.

    My reason for playing with the old RC pot circuit was to explore some of these P2 features. You are exactly right that I could just use the pot alone with ADC mode (which is my next thing to do). I do think a state timer will work, more or less the approach used by the P1 rctime routine.

    I still need to learn more about the interrupt behavior. Will the isr get interrupted by the pin high within the isr? It looks like the answer is no, but when does the interrupt flag get reset? Upon isr entry or exit? I presume the correct answer to my post question is no, you can't disable interrupts in the isr routine?

    Thank you both evanh and johnnymac. One of my original questions was concerning documentation. How can the pupil learn things like adding smart pin configuration modes together without a few examples?

  • evanhevanh Posts: 16,027
    edited 2023-07-15 03:29

    From the Silicon Doc:

    Interrupts loop through these three states:
    1) Waiting for interrupt event
    2) Waiting for interrupt branch
    3) Executing interrupt service routine
    During states 2 and 3, any intervening interrupt events at the same priority level are ignored. When state 1 is returned to, a new interrupt event will be waited for.

    @Phonos said:
    ... but when does the interrupt flag get reset? Upon isr entry or exit?

    From the Silicon Doc:

    When your ISR is done, it can do a RETIx instruction to return to the interrupted code. The RETIx instructions are actually CALLD instructions:
    RETI1 = CALLD INB,IRET1 WCZ
    RETI2 = CALLD INB,IRET2 WCZ
    RETI3 = CALLD INB,IRET3 WCZ
    The CALLD with D = [any register], S = IRETx, and WCZ, signals the cog that the interrupt is complete. This causes the cog to clear its internal interrupt-busy flag for that interrupt, so that another interrupt can occur.

    I remember Chip saying something about there being a special case for those CALLD combinations that are wired to manage the IRQ flag states.

  • evanhevanh Posts: 16,027
    edited 2023-07-15 04:04

    Documenting, and examples, seems to have stalled at Parallax. It might be falling on Chip's shoulders due to the extensive, and sometimes intricate, nature of the Prop2's features.

    Rayman and myself did a block diagram of the pins - https://forums.parallax.com/discussion/171420/smartpin-diagram-now-with-p-p-bit-mode-table/p1 - Latest edition is on last page.

    Chip supplied his schematic of the custom pins - https://forums.parallax.com/discussion/comment/1494131/#Comment_1494131

    I did a guesstimate of the final logic drive circuit a while back ... still looking for where that is ... https://forums.parallax.com/discussion/comment/1524494/#Comment_1524494

  • RossHRossH Posts: 5,477

    @Phonos said:
    1) Is there a way to disable the interrupt within the isr?

    Use the STALLI and ALLOWI instructions

    2) Where can I find a good document of P2 interrupts and pre-defined event types?

    See the section INTERRUPTS on page 49 of the Parallax Propeller 2 Documentation - https://docs.google.com/document/d/1gn6oaT5Ib7CytvlZHacmrSbVBJsD9t_-kmvjd7nUR6o/edit

    3) I also am looking for a document covering pre-defined Smart Pin Constants and usage.

    Good luck with that one! :)

  • Thank you for the notes.

    This looks like a complete answer: the isr will complete the single interrupt call and reset at the end. This implies that the real problem was the noisy signal, which the Smart pin Schmitt setting fixed. I did try STALLI to no effect because there was only one interrupt being executed, which was functioning just as it should. The interrupt feature is a good way keep multiple functions in one cog!

    I need to be more diligent reading ALL of the available documentation. It would help to have everything in one self-consistent doc.

    This has been a great exercise exposing me to a simple Smart pin application. I look forward to learning about more involved pin modes.

    Not that it is very significant but I will clean up the P2_RCTime code and offer it up to the OBEX.

  • I do not have a git account so am including my final version of the P2_rctime object here.

    Again, thanks for all of your help.

Sign In or Register to comment.