I am too stupid to blink a LED .-.
DragonRaider5
Posts: 13
in Propeller 1
Hey,
I am currently struggling to make a LED blink every second - I'm not sure wether I should laugh or cry xD But whatever, here is my code (thanks in advance to anyone who reads it in order to help me )
DragonRaider5
I am currently struggling to make a LED blink every second - I'm not sure wether I should laugh or cry xD But whatever, here is my code (thanks in advance to anyone who reads it in order to help me )
CON _CLKMODE = XTAL1 + PLL16X ' The clock frequency is equal to 96MHz = 6MHz * 16X PLL. _XINFREQ = 6_000_000 ' PUB start cognew(@INIT, 96_000_000) repeat DAT org 0 INIT or dira, LED mov tmp, cnt add tmp, delay waitcnt tmp, #0 :loop or outa, LED mov tmp, cnt add tmp, delay waitcnt tmp, #0 andn outa, LED mov tmp, cnt add tmp, delay waitcnt tmp, #0 jmp #:loop tmp res 1 LED long %1_0000_0000_0000_0000_0000 delay long 96_000_000It blinks the LED but in an interval of like 10 - 12 seconds
DragonRaider5
Comments
Here's a version that lets you pass pin#, on-, and off-timing values (in milliseconds) to the background cog; this will let you create the same blink output regardless of system frequency.
Note that I have start and stop methods so I can change the blink behavior at any time. Note, too, that the second parameter of cognew() is intended -- though it can be used for other things -- to pass the hub address of parameters used by the background cog. It can only pass one address, so the background cog assumes the others are in a specific order.
Final note: This program doesn't keep track of the blinking pin or timing once started. This is why I can point to the parameters block of the start_blink() method. Method parameters are always longs, and stored on the stack in the order they're defined. The timing is converted from milliseconds to ticks and then the address of the method parameters is used to start the background cog. It doesn't take long to start that cog but it's a good idea to ensure it's started before returning when you use the method's parameters when starting the background cog. Since the background takes the pin high first, we just watch for that.
Yes, this is more than simple blinking. What I'm encouraging you to do is think beyond where you are in the moment and how you might apply it to future projects.
Move your
after
For an explanation of why this is important, it's best to read Page 340 of the Propeller Manual (v 1.2).
Also, after your initial delay is calculated in tmp, all you need to do is
each time you pause. This will automatically increment tmp by the amount in delay. That way you can get rid of the
(Edit: LOL! That's what I get for stepping away in the middle of the reply to eat a waffle! At any rate, still make sure to read the PDF reference above.)
If you not want to hardcode the clkfreq (96000), you can not pass the value 96000 as parameter in cognew. This par register is only 14 bit wide and the 2 LSBs are '00', it is meant for passing an address of a long variable.
But you can read the clkfreq from hub address 0 in the PASM code: so the delay is always correct also with different crystals or PLL factors.
Andy
thanks alot. This code was just to test if my pasm code works with my c code, that's why it wasn't as extensive also I know about the incrementive feature of waitcnt, I just didn't use it to avoid any problems - thx for the reference page, that's what "caught me".
DragonRaider5