Shop OBEX P1 Docs P2 Docs Learn Events
Any simple PASM2 code example to implement (SN74ALS869) chip function? — Parallax Forums

Any simple PASM2 code example to implement (SN74ALS869) chip function?

mashaikh23mashaikh23 Posts: 23
edited 2023-11-29 03:23 in Propeller 2

I want to learn the capabilities of built-in counter in P2 and looking for a sample code in PASM2 (preferred) or spin2. My idea is to implement the same function of this 8 bit chip using P2. Initially want to preset the counter with a value and start the count down and wait for an interrupt to trigger at zero. which will execute a block of code (in a cog)? TIA

Comments

  • roglohrogloh Posts: 5,173
    edited 2023-11-29 03:48

    Are you planning to expose all these SN74ALS867 signals via P2 pins, or are you keeping everything software based internally?

    If all software based, then it sounds like you just want some interrupt after X P2 clock cycles, where X is programmable. SPIN2 doesn't really do interrupts inherently, but you can do them in PASM2. There is a CT passed some CT1 limit event than can be setup if you are clocking from internal clock (CT is the internal P2 cycle counter). Look into the selectable events of the P2 as well as SETSEn, SETINT1, RETI, GETCT, ADDCT1 instructions in the Rev B/C Silicon Documentation.

    External clock counting and/or count enable gating from IO pins however probably needs a Smartpin and will be more complicated. If you look at the different Smartpin modes you might find a counter mode that can count to/from some value with optional gating and then source an interrupt event via the Pin when it reaches the limit. You'd map this to an interrupt via the SETSEn.

    That's where I'd start out anyway.

  • @rogloh said:
    Are you planning to expose all these SN74ALS867 signals via P2 pins, or are you keeping everything software based internally?

    If all software based, then it sounds like you just want some interrupt after X P2 clock cycles, where X is programmable. SPIN2 doesn't really do interrupts inherently, but you can do them in PASM2. There is a CT passed some CT1 limit event than can be setup if you are clocking from internal clock (CT is the internal P2 cycle counter). Look into the selectable events of the P2 as well as SETSEn, SETINT1, RETI, GETCT, ADDCT1 instructions in the Rev B/C Silicon Documentation.

    External clock counting and/or count enable gating from IO pins however probably needs a Smartpin and will be more complicated. If you look at the different Smartpin modes you might find a counter mode that can count to/from some value with optional gating and then source an interrupt event via the Pin when it reaches the limit. You'd map this to an interrupt via the SETSEn.

    That's where I'd start out anyway.

    You got it. Pins do not matter. I only care the hardware based count down timer synced with internal P2 clock and cause interrupt when reaches to zero and repeats, precision is important.

  • evanhevanh Posts: 15,198

    So no external inputs needed at all?
    Just an internal timer IRQ? If yes then look up using ADDCT for the event gen and SETINT for attaching to an IRQ. The Silicon Doc has the details on events and interrupts - https://www.parallax.com/propeller-2/documentation/

  • @evanh said:
    So no external inputs needed at all?
    Just an internal timer IRQ? If yes then look up using ADDCT for the event gen and SETINT for attaching to an IRQ. The Silicon Doc has the details on events and interrupts - https://www.parallax.com/propeller-2/documentation/

    Thank you, I will search any code using it as an example.

  • AribaAriba Posts: 2,682

    @mashaikh23 said:
    ...
    You got it. Pins do not matter. I only care the hardware based count down timer synced with internal P2 clock and cause interrupt when reaches to zero and repeats, precision is important.

    There is no such hardware count down counter. Why do you think so?
    There is a system counter that constantly counts up every cycle. You can set one of 3 compare registers, that can raise an interrupt when the system counter matches the value. For that you read the current system counter and add your interval time in cycles.

    Here is a code that sets up an interrupt and toggles a LED in the interrupt service routine, every 1/4 second (very exactly). It uses the ct1 compare and the interrupt level 3, which has the lowest priority.

    CON
      _clkfreq  = 160_000_000
      LED       = 60                                'LED pin
    
    PUB main()
      regexec(@cogcode)
      repeat
        'do nothing in main
    
    DAT
    cogcode       word      setup,codeend-setup-1   'define cogcode chunk
                  org       $80                     'target address in cog
    setup         getct     timer                   'get current system counter
                  addct1    timer,#200              'add 200 cycles for first interrupt time
                  mov       ijmp3,#isr3             'set address for interrupt service routine
                  setint3   #1                      'set ct1 interrupt source, use int3
                  ret                               'return to Spin
    
    timer         long      0                       'register that holds next interrupt time point
    
    'Interrupt service routine
    isr3          drvnot    #LED                    'toggle LED
                  addct1    timer,##40_000_000      'add interval time for next interrupt
                  reti3                             'return from interrupt
    codeend
    

    Andy

  • evanhevanh Posts: 15,198

    @Ariba said:
    There is no such hardware count down counter. Why do you think so?

    It's not hard to figure he was imagining it - Just assumed that's how a dedicated internal timer was built.

    He beat around the bush somewhat. The opening question should have have been: How do I do a timer interrupt on the Prop2?

  • evanhevanh Posts: 15,198
    edited 2023-11-30 01:48

    PS: It should be noted that while interrupts are supported in Pnut/Proptool implementation of Spin2, they not in Flexspin's implementation. regexec() is unsupported too. You are still free to start up a fresh Cog running some fancy Pasm in Flexspin.

  • RaymanRayman Posts: 13,906

    I’m not so sure one even needs an interrupt for this… if can afford dedicated cog…

Sign In or Register to comment.