Spin programing that I cannot figure out
msiriwardena
Posts: 301
I am trying to figure out How the "Time constants were drived" and how the " dt := clkfreq /4620 - How the divisor(4620) was derived.
This comes from an exercise from I/O timing Basics in the "Propeller Education Kit Labs"
Thank you
Siri
This comes from an exercise from I/O timing Basics in the "Propeller Education Kit Labs"
''File: LedFrequenciesWithoutCogs.spin ''Experience the discomfort of developing proceses that could otherwise run ''indendently in separate cogs. In this example, LEDs blink at 1, 2, 3, 5, ''7, and 11 Hz. CON _xinfreq = 5_000_000 ' 5 MHz external crystal _clkmode = xtal1 + pll16x ' 5 MHz crystal multiplied → 80 MHz T_LED_P4 = 2310 ' Time increment constants T_LED_P5 = 1155 T_LED_P6 = 770 T_LED_P7 = 462 T_LED_P8 = 330 T_LED_P9 = 210 PUB Blinks | T, dT, count dira[21..16]~~ ' Set LED I/O pins to output dT := clkfreq / 4620 ' Set time increment T := cnt ' Mark current time repeat ' Main loop T += dT ' Set next cnt target waitcnt(T) ' Wait for target if ++ count == 2310 ' Reset count every 2310 count := 0 ' Update each LED state at the correct count. if count // T_LED_P4 == 0 !outa[16] if count // T_LED_P5 == 0 !outa[17] if count // T_LED_P6 == 0 !outa[18] if count // T_LED_P7 == 0 !outa[19] if count // T_LED_P8 == 0 !outa[20] if count // T_LED_P9 == 0 !outa[21]
Thank you
Siri
Comments
They want the loop to be fast as possible without missing the time window for the waitcnt.
Edit: I don't know if they measured the time directly or if they just kept trying smaller time intervals and kept the smallest interval that would work.
4620 =
02 x 2310
04 x 1155
06 x 770
10 x 462
14 x 330
22 x 210
Enjoy!
Mike
Just the numbers do not explain the logic.
Where did the #4620 derived from why not any other number.How are the other numbers related to 1Hz,2,3,7 and 11Hz.
Siri
Not that it matters much but count will start with an undefined value and could glitch when it overflows. From then on it's confined to 0..2309.
Thank you very much - now it is crystal clear ,how these values calculated.
Siri