![]() cnt is a read-only value, you can't change the system clock, just read what it is. On bootup, cnt = 0 and it increments on each tick all the way to 2³² before rolling over to 0. If the Prop is running at 20kHz, it will = 20,000. If the Prop is running at 80MHz, clkfreq will = 80,000,000. clkfreq is a system variable equal to how many clock cycles (ticks) are in 1 second. The Prop can run at multiple clock frequencies, from 20kHz all the way to 80MHz. ![]() The next line is:īefore we break down this instruction, let me first explain clkfreq and cnt clkfreq Let's continue with out blinky lights program. If the pin is set as an input, ina will hold the current input value. Ina works just like outa and dira, except it's read only. Sense if the pin is connected to a low or high signal (high impedance state): It lets multiple pins share the same data channel and do stuff like charlieplexing. Each pin can be connect to ground, V+, or set in a high impedance state.Ī high impedance state lets the pin sense whether it's connect to ground or V+ without changing the signal. Note that outa is only meaningful if the pin has been switched to an output with dira.įurther, the Propeller uses Tri-state logic. outa works just like dira, you can set the output of a single pin (outa := 1) or a group of pins (outa := 1). Outa tells the propeller to connect the pin to ground or to V+. ![]() Note the soft gray lines under the repeat block? The Propeller Tool put those gray lines there to show you what code is in the repeat loop. This repeat block will repeat forever.Ĭode to be repeated is delineated by tabs. You can specify a repeat condition (repeat i from 1 to 100) or just repeat forever by not specifying anything else. Repeat tells the Propeller to run a block of code multiple times. To change P0,P1,P2, and P3, just use dira := 1. You can also change a range of pins with a single command. Can you guess how you'd set P10 to an output? dira := 1. The := is an assignment operator in spin. To set P0 as an output, we'll change the value of dira to 1. When the Prop boots up, each pin is set as an input, so we'll need to set P0 to an output. The next line is: dira :=1Įvery pin on the Propeller can be set to an input or an output. There are 2 more blocks, DAT and OBJ, but we'll skip those for now - OBJ is useful when incorporating someone else's code, and DAT is another place to hold variables, it's also where you put assembly code (if you want to use it).Īnyway - back to our original program. In the blinky lights program, I haven't used any system variables, but here's a version of blinky lights using variables Here's an example of the blinky light program using a CON block VAR If there's a constant you use throughout the program, the CON block allows you to change it once and it will be reflected every time you use it. The remaining blocks are not required for a valid program ĬON holds program constants. They have names (the name of this block is 'main'), and you can pass them values (function(passedval)). If you're familiar with php or BASIC or C, these operate a lot like functions. Let's break down each line to understand what it's doing PUB main The code will blink an LED connected to P0 every other second (1/2 Hertz) forever. It will quickly compile and load into the Propeller. ![]() Take the program above, put it into the Propeller tool and hit F10. Ready for your first program? Here it is: There are other languages out there, but I figured I'd talk about Spin because it's the one I know best. "Imagine if BASIC and PASCAL hooked up at bar time and 9 months later a new language popped out - well that’s SPIN for you." - Ben Heck Spin is the most commonly used high-level language for the Prop probably because it's (1) easy, and (2) there's a spin interpreter on the Prop. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |