Shop OBEX P1 Docs P2 Docs Learn Events
Need to simulate an interrupt — Parallax Forums

Need to simulate an interrupt

T ChapT Chap Posts: 4,198
edited 2006-10-06 11:34 in Propeller 1
I was having a problem with a circuit, and someone suggested a remedy whereas I take an input to the Prop, and on a high pulse turn off an output for a specified time. That time off may range from 10us to 20us. I am trying to learn whether this can be done in Spin or is assembly req'd. I can devote a cog to it, but there are 3 pins to monitor and 3 pins to switch depending on the input state. My understanding is that in Spin 80k instructions can run a sec. If there are 3 pins to monitor, and 3 outputs to manage, is this time doable in Spin? I can't write assembly so I hope it can.

Post Edited (originator99) : 10/5/2006 5:36:03 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-05 05:22
    The Propeller can handle simple serial I/O at 19.2kB in SPIN which is about 50us per bit. Given the 80k instructions / sec., that's about 12us per instruction (I think it's somewhat better than that ... depends on the complexity of the instruction). The WAITCNT statement has a granularity of a clock tick which is normally 12.5ns, but there may be some slop once the WAITCNT is finished and one or more SPIN statements have to be executed to, say, turn off a pin. You will probably have to use a WAITPNE or WAITPEQ to be able to respond to the input promptly. You may need to use a COG for each input pin to get anywhere near the response time you're looking for in SPIN. What do you actually have to do with the pins? It may be trivial to do in assembly with great precision and a good learning experience.
  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2006-10-05 05:41
    Mike's suggestion is correct, but you only need one COG. The WAITPNE or WAITPEQ can use a pin mask to look at several pins (All 32 if you want) at the same time.

    Read the pins initially to create a mask ... subsequent readings through WAITPNE or WAITPEQ will cause a "Propeller interrupt" if the state of the pins change.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • T ChapT Chap Posts: 4,198
    edited 2006-10-05 05:41
    Thanks Mike

    For current reguation, I am going to monitor a sense resistor, trip a comparator at 2 amps(.2 volts on the REF pin on the comp). The comparator goes to a pin on the Prop, the respective output pin is attached to a quad AND gate that is receiving 4 phase signals from the Prop as well for stepper control. When the comp is tripped, the Prop turns off the pin to the AND for x duration, the coil de-energizes, the comp drops, and the whole thing starts over. The concept is true fixed off time after every over limit current.

    This describes one of 3 sets, there are actually 3 comparators, 3 AND gates to manage.

    Post Edited (originator99) : 10/5/2006 5:51:26 AM GMT
    1076 x 654 - 167K
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-05 06:00
    If any comparator can trigger at any time, you probably need one cog for each. You can use the same routine for each, just pass the pin numbers needed in the COGNEW statements like:
    VAR long stack1[noparse][[/noparse]16], stack2[noparse][[/noparse]16], stack3[noparse][[/noparse]16], cog1, cog2, cog3
    PUB startup
      cog1 := COGNEW(trip(comp1,trip1),@stack1) ' pass pin number for comparator and for quad AND
      cog2 := COGNEW(trip(comp2,trip2),@stack2)
      cog3 := COGNEW(trip(comp3,trip3),@stack3)
    PRI trip(compPin, tripPin) | time
      time := (clkfreq / 1_000_000) * 10 ' clock ticks for 10us
      repeat
        waitpne(0,|<compPin,0) ' wait for high state
        outa[noparse][[/noparse]tripPin]~ ' turn off quad AND
        waitcnt(time + cnt)
        waitpeq(0,|<compPin,0) ' make sure low state
        outa[noparse][[/noparse]tripPin]~~ ' turn on quad AND
    
    
  • T ChapT Chap Posts: 4,198
    edited 2006-10-05 06:13
    Great Mike! I'll test it right now. Many thanks.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-05 06:16
    I didn't put in anything to make the "trip" pins outputs. I assumed that would be setup during program initialization along with initializing the output state to high.
  • T ChapT Chap Posts: 4,198
    edited 2006-10-05 07:12
     time := (clkfreq / 1_000_000) * 10 ' clock ticks for 10us
    
    



    Just FYI Anything below * 5 doesn't work, 5 will run, but 4,3,2,1 = 0 out. Once I get my circuit dialed in, I believe this will be just what I need.

    Thanks a million Mike, you are the man!

    Post Edited (originator99) : 10/5/2006 10:11:01 AM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,547
    edited 2006-10-05 15:34
    originator99,

    This is because there is a finite amount of time required for the waitcnt instruction to execute. 381 clocks in Spin to be exact.

    In the formula:

    time := (clkfreq / 1_000_000) * 10 ' clock ticks for 10us

    If clkfreq equals 80MHz, then at * 5 you get a result of 400. * 4 you get 320 which is below the required 381 clocks of the
    waitcnt instruction, so what happens is that you have to "wait" for the cnt to overflow at 32-bits and loop back around.
    This takes about 54 seconds at 80 MHz.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • T ChapT Chap Posts: 4,198
    edited 2006-10-06 11:34
    Thanks Beau for the explanation

    I have been struggling for many hours trying to solve way to use the compartor interrupt Mike created to set up a fixed off state for 2 of 4 pins that are turning on in sequence. The two pins being one of two coils.

    For example

    1010 is Coil 1A high and Coil2A high

    There is sense R on both coils, each with their own comparator, and inputs to the Prop. In the Spin file below, 6 is comp1, 7 is comp2 in. I want to take Mikes code, and instead of firing an output to external parts, I want to do this:

    IF Comp1 = 0 hold CoilA off for a fixed time(presetable), i.e. 5 us, then let it come back on, if it were to be on according to the indes table that it. If such a case as the motor move was complete, it should not come back on as it would cause problems.


    Motor Move:
    1010 'appropriate index location turns on in the sequence
    IF Comp 1 = 0 then
    00_10 CoilA off, CoilB stays unaffected
    wait 5 us
    10_10 CoilA back, CoilB stays unaffected.

    Same capability for CoilB

    The second problem is, I want to apply full power on each initial motor move, and then after a fixed time allow the comparators to take affect as needed for regulation. I am having major problems leaving the comps in full time, while the motors are stopped and PWMing, they don't want to ramp back up while the PWM is still present. So, I am bringing the whole ball of wax inside the Prop to deal with the masking and fixed off time PWM.

    I have tried a lot of ways, and nothing is working right. One effort was to affect the pins from another function, but it was not changing anything on the pins for some reason.

    Any advice on a concept would be greatly appreciated.

    Post Edited (originator99) : 10/6/2006 11:46:05 AM GMT
Sign In or Register to comment.