Book for absolute beginners. Propeller 101
Harprit
Posts: 539
I am in the process of writing a book on the Propeller for absolute beginners
Emphasis on SPIN language and software development and hardware interactions
Everything will use the Prop Edu Kit
Here is my program to blink the OLD LED
The next one I post will be on how to connect and use a 16x2 LCD. Though this is a bit advanced, we need something
to see what we are doing in our project so this will be next. I promise to make it so you can understate it even if you are a beginner
I will follow the format I use in my books on "How to make Instruments and controllers" and "How to run motors with Micro controllers"
I sincerely welcome your corrections suggestions and criticisms
Harprit
Emphasis on SPIN language and software development and hardware interactions
Everything will use the Prop Edu Kit
Here is my program to blink the OLD LED
The next one I post will be on how to connect and use a 16x2 LCD. Though this is a bit advanced, we need something
to see what we are doing in our project so this will be next. I promise to make it so you can understate it even if you are a beginner
I will follow the format I use in my books on "How to make Instruments and controllers" and "How to run motors with Micro controllers"
I sincerely welcome your corrections suggestions and criticisms
Harprit
Comments
The Propeller needs more written information published.. Nice to see others getting involved.
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?
Getting started with a Propeller Protoboard?
Check out: Introduction to the Proboard & Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card connected? - PropDOS
See picture for wiring
Harprit
Thanks for the encouragement from the Oldbitcollector
I guarantee that the book will be published
Yes, detailed wiring diagrams and very detailed explanations and descriptions will be in the book
I am putting the programs out here to get feedback that they are suitable for the intended audience
After getting the LCD program finished we will proceed to inputs and outputs. All of course in SPIN
If you want to stand out from the "crowd", puts lots of detailed comments in the code. I can never get enough.
good luck,
Mark
Thanks for comments, They are very important and they are appreciated very much.
Typo picked up on all the lines
As you can see I am heavy on commenting each and every line of code so there should be no concern on that.
There is even more in the way of explanations in the text so there is much more
Please keep the comments coming
Every post will help the beginners
Specially I need to know what you did not understand so I can fortify that.
Every line needs to be understood
Harprit
·
·
As you can see I am heavy on commenting each and every line of code so there should be no concern on that.
This was very easy ·for me to understand how to write SPIN
I wish there was more of this easy to understand code out there
This so very true
Every line needs to be understood
·Mark
·
If you want to stand out from the "crowd", puts lots of detailed comments in the code. I can never get enough.
You are on the right track the best to you on this project··· ·
·······················································································································
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 12/13/2008 2:15:10 AM GMT
In program1.spin Not a big deal, but can confuse..
pin =21 {select the pin to be used for the LED}
.
.
dira [noparse][[/noparse]pin]~~ {sets pin 16 to an output line}
Thanks for the corrections and comments to all. They have been picked up. Obtuse commenting will continue and hopefully more will write to tell what whey need so I can be as responsive as possible. No comment is trivial.
I am almost done on the LCD display. Should be on line in a day or two. Its working but I need to get the commenting up to par so all will understand a rather complicated program. I need more feedback on Program 2 so I can cover all bases before the next release.
HSS
harpritsan.com
Question from a beginner are at the end of the lines of code.
My answers are at the end of this correspondence
[noparse][[/noparse]code]
{{The first program turns an LED ON an OFF and demonstrates the use of subroutines
in an absolutely minimal way.
}}
{{Define the constants we will use. We do not have to specify a clock configuration
the default condition will be used
}}
CON {CON defines the constants} --ok
_clkmode = xtal1 + pll16x {tell the program the clock mode to use. Not necessary} -- why not necessary
_xinfreq =5_000_000 {specify the frequency to use. Not necessary} -- -- why not necessary
pin =21 {select the pin to be used for the LED} -- ok
waitPeriod =5_000_000 {set the wait period} -- of what? 5 million what ( i know it is clocks) but it could be us,ms?
blink_count =20 {number of times to blink} -- ok
high =1 {define the High state} -- ok
low =0 {define the Low state} -- ok
{{Define the variables we will use, if any. We will not use any but one is defined
as a byte it would mean that we could have a value from 0 to 255 in the variable numbr
}}
VAR {Defines the variable here. Not needed in this program} -- so why define one?
byte numbr {Have to have at least one defined variable here} -- why?
{if we use (-- a) VAR. We will not use 'numbr' anywhere} -- confusing. I am assuming that if we assign a variable 'numbr' we can't use that label for anything else.
{{This is the main part of the program.
Everything else is in the 3 subroutines
}}
PUB Start
dira [noparse][[/noparse]pin]~~ {sets pin 16 to an output line} -- you might go over this in the book but a parsing of the dira function would be nice. what does ~~ mean
repeat blink_count {specifies how may times to repeat}- ok
turnOn_the_LED {these 4 subroutines care called by name alone} --ok
wait {these 4 subroutines care called by name alone} --ok
turnOff_the_LED {these 4 subroutines care called by name alone} -- ok
wait {these 4 subroutines care called by name alone} -- ok
{this blank line ends the repeat command} --why?
{this blank line ends the start routine} -- why
PRI turnOn_the_LED {subroutine to set the LED line high} -- what is the diff between a PRI and A PUB? why should i use one or the other?
outa[noparse][[/noparse]pin] :=high {line that actually sets the LED high} -- same question as dira. what does := mean?
{this blank line ends this subroutine} -- again why?
PRI turnOff_the_LED {subroutine to set the LED line high} --see above
outa[noparse][[/noparse]pin] :=low {line that actually sets the LED low}
{this blank line ends this subroutine}
PRI wait {subroutine defines the delay} -- ok
waitCnt(waitperiod +cnt) {wait till counter reaches this value} -- this is a totally non intuitive line. waitCnt?(5,000,000 + cnt? ) It would be nice if you
started timing with something that has a 'real world' equivalent such as ms. It is hard for a beginner (me) to visualize 5,000,000 clock cycles. It just becomes a nebular
number that has no meaning other than bigger is longer.
{this blank line ends this subroutine} -- ok
Thank you very much for our notes. I will of course answer each point that you have raised.
You need to at least have the propeller manual on hand. It can be downloaded of free. I will explain a lot of what you are asking me. However, here goes the rest!
It tells you on the top lines that the clock does not have to be defined. Then it defines it to show you how to do this if you need to do it. Both pieces of info can be useful.
Yes it is in clock cycles so the delay depends on what the clock speed is. In spin you work with clock cycles. Why? That's how it is!
Again you don't need a variable but if you did this is how you would define one. I am just showing you how and telling you that its not needed but this is how you do it.
If you use VAR then you have to have at least one variable defined, else it is an error, so I defined one you don't need and told you so. Now you know why.
You could use nmbr anywhere where you needed a variable that was between 0 and 255 because nmbr is defined as a byte and 8 bits will hold only 255 max.
dira is the direction of the 'a' port which is the 32 pins that are I/O on the propeller. ~~ means it is an output ~ means it will act as an input
The blank line ends the routine because that is how you end a routine in SPIN!!!
PUB means any one can call this subroutine PRI means only code in this program can call this subroutine
waitcnt means wait for the counter. The counter runs all the time so you wait for 'delay plus cnt'. This way it does not matter when you start waiting.
Basically all the above is in the manual so please download it and read along with me. I promise you your time will not be wasted.
HSS
Anyway, some topics that I would like to see addressed in published Propeller books:
Objects vs. Cogs
Inter-cog/Inter-object communication
Spin vs. Assembly and interpretation of each
Propeller Standard Library (most common objects in the obex, and their methods with parameters and the like.)
Step by step of interfacing with a chip (look at data sheet, find communication protocol, write code to fit)
Image analysis
Using Assembly for the Spin developer (not a assembly tutorial, rather a cut and paste type thing...)
Just some of my thoughts.
I will try to cover line 1 and 2 of your list approximately and that will take a good 300 pages
I cannot possibly cover assembly for the beginner. It is not a beginner thing
What you are asking for is an encyclopedia going from what is a variable? to fuzzy logic, image analysis!! and just about everything else. Lets keep it realistic and on the beginners table.
What you are asking for wont be in a beginners book
Even so you expressed some challenging idea and I will try to provide some of what you have suggested in the beginners format we are using
I assumed that if you want to play with the Propeller and 8 32 bit processors, you know what a variable is
By the time I get done you will have the confidence to program in SPIN and know how to interact with the COGS, that is the beginning, the rest is where you want to take it.
Did you read the stuff on the PID loop and what use did you think it was to my efforts? Should this be in the book?
Thanks for posting, every bit helps me
Harprit
If you do publish this book, expect me to buy it. I've had the prop since June and I am still struggling with using it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
All those things will be covered, in an orderly manner
If you have specific part numbers in mind please let me have them so I can get them ordered
Also let us make a list of things that need interfacing so they get discussed
Thanks for taking the time to post.
I need all the feedback and feed forward that I can get
HSS
As for the more advanced topics, I meant (maybe didn't get this through) that it would be nice to have overviews or at least a pointer in the right direction. It doesn't need to be blow by blow code analysis, just what to expect when working with such techniques. I recently read a book (The Robotics Primer by Maja J. Mataric) that was very small (about 200 pages) and it covered all the main points of robotics, from hardware to software. I particularly liked the software sections where she explained in clear detail each of the different types of popular code methods. Something like that but in Spin and Propeller oriented would be great.
Advanced techniques belong in a beginners book. Why? For the simple reason of giving the reader perspective, and a footing to grow. It's a rough world out there when you don't know what to look for, and I like having a book give me a general principle that I can then look up. Such coverage does not need to be exhaustive. Indeed, it should be simple and short in order to not turn the reader away in the first place.
Well said and I will keep your suggestions in mind towards the end of the book
Yes, very good indeed and thank you for posting
Harprit
From what I have read so far I like·it· a·lot·
It is easy to understand
I would add a few thing
I think that when you have a good understanding of how·to use and write code for
·VAR, ·CON,· PINS for Inputs·and·Outputs and·the like
Being able to write IF and·THEN Statements
Being able to write· ·DO ,·LOOPS·· /·· (·LOOP UNTIL·, DO WHILE and the like or that is· (=) to that)
And how to use and write code for ·a Ping Sensor , Motor Controller Time Chips
A better understanding of how the Video Code Routines and what each part dose
A better understanding of how the Key Board and ·Mouse Routines and what each part dose
Most of·what user would want to use in there project Just the Basic no real fancy stuff is need until you are ready for harder stuff
I hope all of the make sense
·This just my two cents for what it worth
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
This program lets you position the cursor where you want on the LCD
and then lets you write what you want starting there
This code can be added to any program to get information displayed on the LCD
Its not a universal print routine but rather a set of simply routines you can understand
without difficulty.
There are of course other ways to do this and we will develop those later
Need feedback!
Harprit
All that you want is coming, just like you want it.
Here I post the programs the rest I am busy writing in the book
It may surprise you that I did not know a thing about SPIN till a couple of weeks ago.
Yes its true and I am pulling may hair out too! Manual very hard for dummies like me!
So I am learning it along with you.
Slowly slowly we will catchy monkey.
What you said make a million dollars worth of sense.
Keep it coming. Send me feed back on every program every time.
So now you know why I need your feedback so bad, I am ignorant. Help me.
Harprit
I am NOT TRYING TO RUSH you by no means AT ALL
All GOOD WORK TAKE TIME
I understand that VERY WELL
·These· GUYS· are (·meaning ME )· going to have a lot of FUN·Soon
They may be able to learn how to write SPIN SOON
YES WE DO· some thing very easy to do and to understand not to the point of explaining what PID means
I think you explain what a PID dose very well·as far as it pertain to using and writing a simple Routine as an Example
·For all tutorial lovers there is a detailed description of a PID loop in plain English that I wrote for the current discussion going on on the PID loop. It is worth reading by all beginners. Please let me know if we need something like that in a beginners book.
Thank YOU for Your Hard Work for beginners
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 12/13/2008 9:45:59 PM GMT
I would really like to see a BASIC based compiler for the Prop. and ditch the SPIN all together.
But I could deal with the SPIN if I could better understand how it works.
___________________$WMc%______________Merry Xmas
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there
Well I'm working on it but I need your help.
Read what I have posted and tell me what you understand and don't understand
Its important that you participate
Harprit
We can now
' STATUS NOTES
' With this we have now developed the following skills
' Blink and LED, meaning we can control any line on or off
' Write anything you want to a 16x2 LCD
' Read a potentiometer and get any range we want in the answer (0-255 was chosen)
' I used a 10Mfd cap, the med size one in the kit.
' display the results on the LCD in all 3 formats
' Immediate Future Input reading goals are (more will be added as we go along)
' Read an incoming pulse width
' Read an incoming frequency
Need feedback. Need feedback. Need feedback. Need feedback. Need feedback. Need feedback. Need feedback.
No feedback=no improvements.
HSS
Hi Harprit,
very nice examples !
But I think there is a small mistake in program4:
The LCD-INITIALIZING must set after the DIRA-commands like in program 2 and 3 !!??
Stay tuned !
(I'm waiting for program5)
However, It runs, I just ran it.
Let me check it over gain and get back with you all because it works!!
Harprit
Turns out you got fooled and then you fooled me!
The "Initialize LCD" line is not a heading it is a subroutine call and it is not tabbed back like you quoted it.
This subroutine used to be further down the program about 10 lines and I moved it up as "better practice"
I should also confess that I make minor improvements as I go along like the fact that in
program 4 the cursor no longer blinks! This is because we no longer need to see it. When you first
start out and clear the LCD you can't tell it you did any good because there is no cursor. You might be
just hung up some place so a blinking cursor is needed to reinforce your first success.
So the rule it that you have to go over the entire program and find subtleties every time! Sorry!
I will try to call these out as we go along so the newbies are not lost in the woods.
Program 5 is having 3.3 vs 5.0 volt problems that I have to get a simple fix for before I post it.
Soon. It investigate what the signal that runs a R/C servo looks like by measuring both the up and
the down signal width. We will then use this pulse to put out half this pulse width so that the servo moves
only 90 degrees instead of the usual 180 degrees end to end.
This can be described as a simple signal processing task! No very high brow but, we can do
signal processing with a Propeller now
Even so, Thank You for a very careful reading and Thanks You for responding
I hope you will respond regularly. Every bit helps (Pun intended)
Harprit
Here is the problem
Here is what I think is a bug in the SPIN software
I came across this while trying to write a high pulse
So I converted it to a pulse to an LED
I eliminated all the rest of the code so there is no confusion
This is what I sent to Parallax
See if you can discover anything more
I think I have a bug to report
Take a look at the attached program
All you need is an LED on line 23 to run it an see the bug hang thing up.
Lines 91 and 94 are or interest. If the variable is 107 or less it works
If it is 108 or more it gets stuck at line 91 and fails/hangs up
Could you please try this and get back to me.
Harprit
160Mhz is a little bit fast for the prop !
Tharkun
Post Edited (Tharkun) : 12/15/2008 8:50:06 PM GMT
I would have never found it.
Now to put the code back into the program and get it finished
Soon
Harprit