Any simple PASM2 code example to implement (SN74ALS869) chip function?
mashaikh23
Posts: 23
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
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.
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.
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.
Andy
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?
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.I’m not so sure one even needs an interrupt for this… if can afford dedicated cog…