Help with basic pin toggling via smart pins
DavidZemon
Posts: 2,973
My first foray into the smart pins is attempting to flash an LED. It seems mode 10 should be simplest, but I can't get it to work with the following code.
I'm trying to blink four different LEDs here: 56 via basic software loop, 57 slower via basic software loop, 58 via manually triggered interrupt and (the problem pin) 59 via smart pin. 56, 57, and 58 are all working great, but no light from 59.
If my math is right, this should yield 300ish Hz LED. Well... not ideal for an LED, but I have my scope hooked up and have been double checking it there.
These smartpins are very cool in how powerful they are, but yowzer are they complicated! What an amazing number of configuration options!
I'm trying to blink four different LEDs here: 56 via basic software loop, 57 slower via basic software loop, 58 via manually triggered interrupt and (the problem pin) 59 via smart pin. 56, 57, and 58 are all working great, but no light from 59.
CON LOOP_COUNT = 10 PERIOD = 65535 UINT_MAX = 4294967295 MODE = $2A ' tt=01 and mmmmm = 00101 dat org hubset #0 init mov ijmp1, #my_fancy_isr dirl #59 wrpin mode, #59 wxpin period, #59 wypin uintMax, #59 dirh #59 blink waitx ##1_000_000 drvnot #58 djnz index, #blink trgint1 drvnot #57 mov index, #LOOP_COUNT jmp #blink my_fancy_isr drvnot #56 reti1 index long LOOP_COUNT period long PERIOD uintMax long UINT_MAX mode long MODE
If my math is right, this should yield 300ish Hz LED. Well... not ideal for an LED, but I have my scope hooked up and have been double checking it there.
These smartpins are very cool in how powerful they are, but yowzer are they complicated! What an amazing number of configuration options!
Comments
and try moving the WYPIN instruction to after the DIRH instruction.
Thanks! I tried wypin after dirh at some point in my testing, and I found the incorrect TT bits after posting.... but I didn't go back and try swapping the dirh after fixing TT.
IMHO the labels in PNUT are case insensitive, so you should get an error if the constant and the register have the same name.
Andy
Thanks for the heads up. I'll keep that in mind for future programs.
@"Dave Hein", I don't know if you want to care to implement that "feature" or not, but there appears to be a language discrepancy since the p2gcc package compiled this program quite happily.
Ohhh, quite clever. And I am, indeed, using the -c option in my Makefile for building .spin2 files. Now I know why
Here's a little test program that uses smartpin to blink P56.
Used scope to measure frequency with different settings, see comments.
IMHO, there is a small typo at your SPIN2 code, as follows:
Won't the comment should say:
Henrique
Question please:
mov x,##$0001_0000 'Toggle every 16 base period
How did you figure this part out.
Thanks
That confused me as I was using an adc calculator to try to figure it out. But where does the: ##$0001_0000 come from. I moved the one around and it changed the freq. I have been looking in docs don't immediatly see anything.
Thanks.
@cheezus
Thanks I will use it and see what it does.
The mode Rayman chose Chip has called NCO frequency. This mode has base period, phase and cycle portion. It's a small brain twist to picture how the portion adding function (NCO) functions. You can think of the portion parameter as a fractional accumulate per base period, where a whole one is a Z accumulation of 2**32 to cycle the output ON then OFF again.
So if X = $8000_0000, the half fraction, then every base period would toggle the output. And two base periods give a whole output cycle in this case.