Shop OBEX P1 Docs P2 Docs Learn Events
Waitpne for an external IRQ can you timeout with Counter Duty? — Parallax Forums

Waitpne for an external IRQ can you timeout with Counter Duty?

tonyp12tonyp12 Posts: 1,951
edited 2015-02-02 20:50 in Propeller 1
What is known, a Cog uses the actual electrical state of the pin when reading INA.

What I need:
Cog sleeps but wakes up every 100mS to run a quick SPI-read-routine, but if the external device pulls IRQ low I need to do the SPI-read-routine asap.

Could I simulate a IRQ ever 100mS by having a Counter pulling (internally) this pin low even though DIRA is set a input?
I don't want to waste any Prop pins by running external pins to each other.
What could I do, as waitcnt and waitpne don't mix well.
attachment.php?attachmentid=113032&d=1422768553
413 x 509 - 51K

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2015-02-01 00:20
    You cannot force a pin low, only force it high (because it is OR'ed). For this you need to make the pin an output too (ie set DIRA=1).
  • altosackaltosack Posts: 132
    edited 2015-02-01 09:00
    Hi Tony,

    I assume power consumption is an issue, since you said you want the cog to sleep. If it is not, you could use a tight loop reading INA that also checks if the time has passed 100 ms. You would need to check if your latency is compatible with the time that your external device pulls the IRQ pin low.

    If power consumption is an issue but you have an extra cog, you could waitcnt with it, but instead of pulling the pin low with OUTA, make DIRA high (with OUTA low) for a brief time every 100 ms. This would allow the external device to pull it low for the IRQ when it needs to, and would leave both cogs sleeping most of the time.
  • tonyp12tonyp12 Posts: 1,951
    edited 2015-02-01 10:31
    After some thoughts
    As INA, Waitpne and Counters all use the actual electrical state if pin there is no way that the cog could exit a waitpne by having its counter toggle the pin as it of course have to remain an input.
    A second cog cogs counter could not do it either as if it sets that as an output, that pin is now no longer an "true" input for any cog.

    Wasting an Prop pin that externally with a mosfet pulls the line low could work, or keep polling INA at 50uS intervals and at least got some sleep in there.

    If you don't need interval timing, but just a way to signal the other cog
    Have another cog use DIRA to force a state as to signal the other cog that is locked in a Waitpne state,
    Should use a series resistor unless the IRQ line is open drain in the first place.
  • fridafrida Posts: 155
    edited 2015-02-01 14:51
    CON
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
    
    var
        long stacka[100]
    
    
    pub Start
        cognew(sync,@stacka)
        dira [16..17] := %11 ' color led
    
        repeat
            outa[16] := 1 ' led on
            waitcnt(clkfreq / 10 + cnt)
            outa[16] := 0 ' led off
            waitpeq( |< 19, |< 19, 0) ' wait for active switch or sync time 
    
    
    pub sync | time
        dira[19] := 0 ' set pin as input
        outa[19] := 1 ' set pin to 1 because my switch is active high
        time := cnt   ' set sync time
        
        repeat
            repeat 40
                waitcnt(time += clkfreq/1)
                dira[19] := 1 ' short puls
                dira[19] := 0 ' on output
    

    It works fine with both sync time and a switch.
    My switch is active high, so change it, if it is active low.
  • jmgjmg Posts: 15,173
    edited 2015-02-01 15:23
    tonyp12 wrote: »
    Waitpne for an external IRQ can you timeout with Counter Duty?
    I don't want to waste any Prop pins by running external pins to each other.
    With no buried pins, or opcode support to include Counter timeout, there is no pin-less solution.
    If you are using the EEPROM pins only for loading, then you may be able to 'borrow' SDA as the signaling pin,
    or dual-purpose some other pin ?
  • msrobotsmsrobots Posts: 3,709
    edited 2015-02-02 20:50
    As @jmg said use SDA as signal for your counter/timer pin. You do not need to wire anything. So start counter with SDA as pin and then wait. waitpne can wait for more then one pin to change at the same time. it is a mask, not a single pin.

    So if your counter hits SDA will change and if your external sensor changes your input pin will change.

    Enjoy!

    Mike
Sign In or Register to comment.