PElabs help
Vern
Posts: 75
Forgive me if this is the wrong place for this to be posted but I really need some help wrapping my head around whats happening in this code example in the book. The example code isn't commented and I can't figure out how it works, if someone could just step through it and explain what it is each line is doing and how it ends up creating a 3hz blink I would be very thankful.
I understand that
pin := 4 sets the variable pin to pin 4
rate := clkfreq/3 sets the rate variable to a 3hz frequency
reps := 9 obviously sets the variable reps to 9
dira and outa I get one is set to output the other set to an off or 0 state
Its the repeat loop I don't get.
Ok so the repeat loop loops 18 times correct.
Each loop it waits for 1.5 seconds before performing
!outa[pin]
!outa[pin] sets the pin4 to high but then it loops back around immediately to the waitcnt.
Wouldn't that make the blink to fast to see? Does !outa[pin] change the actual value stored by pin or does it simply output the opposite of what is stored in pin?
If it assigns a new value to pin4 then loops and waits a half second again that would explain the blink rate.
If it doesn't assign a new value to pin4 then why can I see the blink?
I'm confused and this is probably face slappingly simple but I could use a bit of guidance here.
'' AnotherBlinker.spin PUB Blink | pin, rate, reps pin := 4 rate := clkfreq/3 reps := 9 dira[pin]~~ outa[pin]~ repeat reps * 2 waitcnt(rate/2 + cnt) !outa[pin]
I understand that
pin := 4 sets the variable pin to pin 4
rate := clkfreq/3 sets the rate variable to a 3hz frequency
reps := 9 obviously sets the variable reps to 9
dira and outa I get one is set to output the other set to an off or 0 state
Its the repeat loop I don't get.
Ok so the repeat loop loops 18 times correct.
Each loop it waits for 1.5 seconds before performing
!outa[pin]
!outa[pin] sets the pin4 to high but then it loops back around immediately to the waitcnt.
Wouldn't that make the blink to fast to see? Does !outa[pin] change the actual value stored by pin or does it simply output the opposite of what is stored in pin?
If it assigns a new value to pin4 then loops and waits a half second again that would explain the blink rate.
If it doesn't assign a new value to pin4 then why can I see the blink?
I'm confused and this is probably face slappingly simple but I could use a bit of guidance here.
Comments
Thank you for the quick response.