Look at my code and schematic-comment-before I plug it in.
Bill C Cooley
Posts: 18
Hello,
I have written some code that didn't complain until I tried to... refer to, start, call a little subroutine called SafetyFirst. I just don't know the correct syntax for that. (or how to return when done)
But mostly I want to know if I have missed something that will take out one of my components when I power this thing up. That has already happened to me once, I'm Leary now.
The RF portion is still under development and far from done, but the switching to pulse mode and the motor test moves or code or approach
Any comments, hints, cautions, suggestions will be greatly appreciated.
Both code and a schematic are attached.
Bill Cooley
I have written some code that didn't complain until I tried to... refer to, start, call a little subroutine called SafetyFirst. I just don't know the correct syntax for that. (or how to return when done)
But mostly I want to know if I have missed something that will take out one of my components when I power this thing up. That has already happened to me once, I'm Leary now.
The RF portion is still under development and far from done, but the switching to pulse mode and the motor test moves or code or approach
Any comments, hints, cautions, suggestions will be greatly appreciated.
Both code and a schematic are attached.
Bill Cooley
Comments
Thanks for looking at my code. Could I direct your attention to the words SafetyFirst, currently apostrophed out, near the beginning of the main program. That is an attempt to run the 'PRI SafetyFirst', but it is the wrong syntax, or worse, not done that way at all.
Could you show me how to correctly go to that sub routine and return to the main program when done.
Thanks in advance for your efforts Kwinn.
repeat 'Endless Loop Waiting for Radio Input
PRI JogForward
repeat
PRI JogReverse
repeat
They need a condition that exits the repeat loop. See repeat until, repeat while, and repeat from/to/step in the propeller manual.
+1 on this.
I know when the Propeller first came out, resistor values as low as 1K were said to be okay when used with 5V devices but apparently you really need about 3K to be safe. The current through the clamping diodes is supposed to be limited to 0.5mA.
One trivial thing I noticed was the identical resistor values on the RGB LED. Since the drop across the red LED is likely less than the blue and green LEDs, it's common practice to use a high resistor value on the red LED. This just makes it a bit easier to get a nice white color but this can be adjusted with software so it's hardly worth mentioning and I wouldn't bother changing it unless it's really easy to do so.
PUB (I moved it up to PUB)
repeat 'Endless Loop Waiting for Case Open P6 to go High
if ina[6]<>0 'If Pin 6 goes High (case open) then
serial[0].str(string("{S}")) 'Change to Pulse Mode (effectively disabling button Inputs)
OutA[17] :=0 'Blue LED On in Jog Mode / Safe Mode / Case Open
OutA[16] :=1 'Green LED Off in Jog Mode
OutA[15] :=1 'Red LED Off in Jog Mode
else 'When case closes then
serial[0].str(string("{R}")) 'Return to Serial Mode
OutA[17] :=1 'Blue LED Off
OutA[16] :=0 'Green LED On Returning to normal mode ]
On one hand I want it to always be on the lookout for the case to open or already open on power up, but send the {R} only when needing to leave {S} or as [6] goes to back to 0. Will it behave that way now? ( I don't think it's right yet)
I guess it's obvious, this is my first attempt at spin code, I'm very grateful for your comments and assistance. I think I need binoculars to see beginner from here.
Bill
I did see that the values were different some where in some ones code. What are the good resistances, at least for 3.3v? I am changing the 2.2Ks for 3.3k.
Hey Thanks again, I'm so new to any code writing & microcontrollers that each of these tips is helping a lot. When kwinn told me you must provide an exit "see repeat while" in the manual, I'm ashamed to say its the first time I'd ever seen the manual, That will help a ton. I couldn't find the !outa command, but in use it looks it toggles the state ea visit, but both high and low would have the same wait time.
Bill
If you want post a snippet of code, use the code tags <code> and </code> where the "<" and ">" are square brackets. This keeps the indentation correct.
I would strongly suggest that you use named constants for pins -- it is very easy to forget what a pin does, and by using "magic numbers" in all your dira and outa instructions, you're opening up a big opportunity for a bug and confusing others looking at your code. Likewise with magic numbers in waitcnt instructions.
Most of the code I write is for public consumption hence I tend to be very conservative and verbose in my approach. I suggest you start there, too. Not that you were wondering, "What would JonnyMac do?" -- but I moved your code into my standard template style. This is my style and, ultimately, you will develop your own. What that style should avoid, however, is magic numbers in the code. Note that by using named pins and a few constants, the code can become somewhat self-commenting.
My version of your program allows safety_first, jog_forward, and jog_reverse to exit.
WOW, WOW, Wow. Thanks so very much. That was a big effort. Well, as you could no doubt tell, I had learned only 3 or 4 things and tried to start making my gizmo. As an electrician, I've made a lot of gizmos, but usually bigger like retractable dark room, using limit switches, relays. This is my first venture into microcontrollers and code. I didn't realize how first grade my try was. It's going take me quite some time to absorb how your code works, all the cool tricks, the naming convention. I am blown away, I can barley read it. Again I can't thank you enough. Boy, That hill is always much farther away once you start walking it.
Really just Great!
Bill
Sorry to say, I don't know. In my RGB arrays I use 100 ohms for the green and blue LEDs and 150 ohms on the red. The voltage on the RGB arrays is closer to 5V which makes it easier to control the current through the green and blue LEDs. Since the green and blue LEDs have a forward voltage pretty close to the Propeller's 3.3V output, it's hard to know how much of the voltage drop will be across the resistors. I personally don't think you need to worry about this. I'd just leave the resistor values as they are.