Shop OBEX P1 Docs P2 Docs Learn Events
pin in/out at top speed — Parallax Forums

pin in/out at top speed

TCP71TCP71 Posts: 38
edited 2011-04-21 07:47 in Propeller 1
Once again, please forgive my ignorance.
I am trying to test an input pin for a specific state and then toggle another pin as quickly as possible once the state has been reached. What is the fastest method to have this happen. It seems that waitpeq in spin code, followed by an "outa" instruction seems to take almost 9uS to occur. This is probably completely simple to do in assembly, but I'm the furthest thing from a programmer you can imagine. Any (simple?) ideas would be appreciated.

Comments

  • tonyp12tonyp12 Posts: 1,951
    edited 2011-04-20 15:37
    So you want to do it in spin.

    I wonder if you can set up the counter in spin, in a set and forget?
    I'm not sure, as I'm a assembler dude.

    Logic modes of operation
    Modes %10000 through %11111 operate differently that the other modes of operation.
    In these Logic modes, APIN and BPIN are inputs into the counter which dictate when
    the FRQA register is added into the PHSA register.
    Only when the logic equation specified by the mode is true is the FRQA
    register added to the PHSA register.

    The %10000 (LOGIC never) mode is equivalent to mode
    %00000 (Counter off), since the FRQA register is never added to the PHSA register.
    The %11111 (LOGIC always) mode is similar to the system clock in that the FRQA
    register is added to PHSA register every cycle.

    The remaining modes accumulate when the mode’s logic equation evaluates as
    true. These modes operate on buffered inputs, so the values present at the APIN
    and BPIN of the previous clock cycle are used in the equation for the present clock cycle.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-04-20 21:23
    You should be able to do this with the counters...

    Set one counter to your desired "toggle ... as quickly as possible" ... this can be up to 125MHz

    Set another counter pointing to the same output pin as a 'POS detector with feedback' or 'NEG detector with feedback' depending on the pin state you want to look for. ... <-- you could do this using the ina and dira but the time required to execute ina and dira in SPIN would defeat the purpose. The way that the dir and out registers are OR'd ... 'POS detector with feedback' is the proper way to do this.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-20 21:32
    You should be able to do this with the counters... ..

    You might look at this attached info on counters.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-04-20 21:59
    Here is a small test program written in SPIN that uses both counters and completely runs in the background. If the input pin is pulled down to Vss with a 1k resistor or so, then a HIGH signal on the pin will enable the output pin with a 10kHz square wave.
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    Input_Pin         = 1           { Event detector } 
    
    Output_Pin        = 0
    Output_Frequency  = 10000       { in Hertz }
    Output_Counter    = "A"         { Use Counter A to generate output frequency }
    
    OBJ
    Hz           : "Synth"
    
    PUB Demo
        Hz.Synth(Output_Counter,Output_Pin,Output_Frequency)
        ctrb := %01001 << 26        { POS detector with feedback }
        ctrb |= Output_Pin << 9     { Set 'Bpin' as the defined output pin }
        ctrb |= Input_Pin           { Set 'Apin' as the defined input pin }
    
        repeat
    
  • TCP71TCP71 Posts: 38
    edited 2011-04-21 07:47
    Thanks. I will look at the counters a bit closer. Sorry Tony, that may as well have been Swahili. Beau, I will work on trying to understand what you've done in the program above and apply it to my code. I really just need to monitor pin 0, when it goes to ground, i need to set pin 5 high ASAP. That's it. I really appreciate all your help.
Sign In or Register to comment.