Programming HELP!!
daniellockhart104
Posts: 7
Heres the code I have so far: with an LED on pin[0] and a button on pin[17]
Pub control
Dira[0] := 1
Dira[16] := 0
Dira[17] := 0
repeat
if ina[16]
outa[0] := 1
ina[16] := 0
waitcnt(clkfreq * 5 + cnt)
outa[0] := 0
This part of the code does exactly what I would like it to do. Where I am having trouble is I would also like for when Ina[17] receives HI from button to stop everything immediately and return to the beginning. I am very new at all of this and am having a blast learning.... some gentle shoves into the right direction would be greatly appreciated and corrections to however I posted anything wrong here are absolutely welcome.....like i said.... HELP
Things I have already tried, but prolly executed wrongly are:
an additional "if" statement saying
if ina[17]
Outa[0] :=0
A "next" statement with another repeat loop that turns outa[0] :=0
A "quit" statement that responds to ina[17] button pressed.
waitpeq
Right now I am using an LED in place of what I hope to be a solar/battery powered FAN in the future. the current code that currently works properly will run that fan for 2hours (code says 5 sec for testing purpose) after the solar source is lost ( ina[16] ). what I would like ina[17] to do is sense temperature. If the temp is fine and is sending a signal to ina[17] but solar is still present on ina[16], then shut everything off and restart once solar is sensed on ina[16] again. I got this to partially work but it would still wait for the "waitcnt" to finish before clearing outa[0]
I would also like to add an additional sensor for battery voltage on ina[18] that will stop all operations immediately, no matter what code is left.
Pub control
Dira[0] := 1
Dira[16] := 0
Dira[17] := 0
repeat
if ina[16]
outa[0] := 1
ina[16] := 0
waitcnt(clkfreq * 5 + cnt)
outa[0] := 0
This part of the code does exactly what I would like it to do. Where I am having trouble is I would also like for when Ina[17] receives HI from button to stop everything immediately and return to the beginning. I am very new at all of this and am having a blast learning.... some gentle shoves into the right direction would be greatly appreciated and corrections to however I posted anything wrong here are absolutely welcome.....like i said.... HELP
Things I have already tried, but prolly executed wrongly are:
an additional "if" statement saying
if ina[17]
Outa[0] :=0
A "next" statement with another repeat loop that turns outa[0] :=0
A "quit" statement that responds to ina[17] button pressed.
waitpeq
Right now I am using an LED in place of what I hope to be a solar/battery powered FAN in the future. the current code that currently works properly will run that fan for 2hours (code says 5 sec for testing purpose) after the solar source is lost ( ina[16] ). what I would like ina[17] to do is sense temperature. If the temp is fine and is sending a signal to ina[17] but solar is still present on ina[16], then shut everything off and restart once solar is sensed on ina[16] again. I got this to partially work but it would still wait for the "waitcnt" to finish before clearing outa[0]
I would also like to add an additional sensor for battery voltage on ina[18] that will stop all operations immediately, no matter what code is left.
Comments
You have pin 16 set as an input, so I'm not sure what you are trying to do with the "ina[16] :=0" line ???
To make it end when pin 17 goes high you'll need to make a loop to check pin 17 instead of waiting the whole 5 seconds at one time.
Something like: (warning untested code)
I hope this helps. Please let us know.
P.S. If you post the WHOLE program, it makes it easier for us to test it.
Bean
Here is my code.. hopefully posted correctly this time... here it goes:
The ina[16] :=0 line starts the waitcnt when the button is released and keeps the fan/ LED on for the specified time. I first entered it without the " := 0 " thinking it should be fine since pin[16] was set as an input but got the message "variable needs an operator". with ":= 0" added it works just as desired, on that half of it any ways.
I tried out your code and couldnt get the desired results, I tried manipulating it to see if I could get it to work but couldnt. I dont really understand the "Temp" commands and could not find it in the Propeller Quick Reference.
About the P.S.: This is all the code I have so far, and would work great if I could just get pin[17] to turn pin[0] low even though pin[16] is still trying to keep it at high. When I actually have everything hooked up, and since the fan is 12v, I will be using a MOFSET with pin[0] at the gate.
All other code I have tried has been like walking around in the dark desperately feeling around for a light switch. Seems like that kind of code would be useless, besides, because it did not work I did not save it.
Do you mean to write "repeat while ina[ 16 ]" to wait for pin 16 to become zero?
I know it's really overwelming when you start, the best advise I can give you is to don't take offense of people trying to help you. There is a wide range of personallities on the forums so you have to try not to read things into people's comments.
Here is how you can help us help you. Post the entire code you are using formatted with code blocks (you did this in you post, so far so good). Tell us EXACTLY what it did or didn't do. "couldn't get desired result" tells us nothing. Did the LED not come on ??? Did it come on for a short time ??? Did it catch on fire ??? We need to know all the details to help.
As Mike stated I think you want "repeat while ina[16]" if you want the code to wait until pin 16 goes low. "ina[16] := 0" does nothing constructive.
A saying we use at work might help you "If it was easy...Everyone could do it." Programming is NOT easy. It takes alot of time and you have to stick with it. But it IS very rewarding once you get the hang of it.
Bean
The code I posted (properly this time..yay!) is the only code I have so far. I will do my best this time, from the top, to explain exactly what I am trying to do. Forgive me for trying to be clear about something that is so unclear to me so far. But dont worry... I LOVE programming so far, so I will stick with it.
Here goes nothing.....
Elements in my project:
- 12v fan (represented by an LED on PIN[0]
- solar panel (PV) (represented by the button on PIN[16]
- temperature sensor (represented by the button on PIN[17]
- voltage sensor (prolly going to use a schmitt trigger) represented by button on PIN[18]
- I would like the fan to operate all day, as soon as the PV is lost (night time) Id like to wait for 2 hours until the fan shuts off (5-10 sec for testing purposes is good).
- BUT, if its cooler out than the set point I give the temp sensor, Id like that signal stop the fan even if there is still signal from the PV (pin[16])
- BUTTIF (my new programming language) The voltage from the battery is low, ignore pin 16 and 17, stop all code and shut the fan down.
- Then of course being able to repeat all this each day.
Ive been using buttons and the LED to test the logic, id like to get the programming right before I start diving into the MOFSETs and triggers and sensors and wires and more resistors and more diods..... if you are wondering if I know that I am in way over my head on this one the answer is YES, YES i do. I enjoy a good challenge.
After doing tons and tons of internet searching to find a product already made to do the above with no success, I decided to head over to FRY's electronics to see if I might be able to wire something up myself. After more endless searching, because I had no clue about electronics, I stumbled across the PEK 40-pin DIP. I knew it wasnt going to teach me the foundation of electronics, but I also knew if i could grasp it just a little, I would hit the ground running... or, land on my face. Seems I was wrong and am doing both simultaneously. Either way, I am enjoying it immensely. I bought a book from the shack called Getting Started in Electronics.... its a great book! really has helped me a lot. I still wish I had someone to sit next to and help me out. I could learn so much faster!
Thanks again for your time and help Bean,
Daniel
Also happens to the professionals, but they don't like to tell anyone about it...
I wouldn't call 'writing to an input' for an 'illegal operation' as the program still runs.
Doing a 'Divide by Zero' though, that's a bit on the bad side. On other platforms, attempting to write to a memory segment that's read-only or belonging to another process may be 'illegal'.
As far as I see it, we have:
Working instructions,
waste of time instrutions(everything from good old 'NOP', to manually clearing registers or flags that doesn't have any influence on the next operation, and anyway will be changed by that next instruction anyway)
Then there's the 'Undocumented' instructions(feel free to pick up a good book on the Zilog Z80 CPU once and study the list of instructions, including the well known 'undocumented' ones. Some are a waste of time, but others are pretty useful. Unfortunately, we can't use them in commercial systems/programs as they aren't verified OK on the chip by the manufacturer)
The illogical instructions or also known as 'werd things happen' instructions, such as what you did, by writing to an input. Mostly, these doesn't DO anything, but sometimes... things happen...
And finally, 'illegal instructions' which brings the house down.
If there's anything really wrong with your code, it's that there's no comments.
There's a saying 'Real programmers doesn't comment code. If it was hard to write it should be hard to read'...
And I can tell you from personal experience that a program that has been left untnded for a month or more will look like just that much gobbledygook when you try to pick up where you left.
At a minimum, a decent description of what a procedure does at the beginning of it, preferably add a description of what the variables are for, too.
Remember, comments doesn't add size to the executable, so no need to keep them brief. ;-)
As you're a beginner, you still have time to make this a good habit.
Now heres my new code.... pretty easy, I know.
I see the value of commenting on your own code. I can imagine how complicating it can get for some of the larger projects. Also, it kind of shows me my level of understanding of what each command really does.
That said.... feel free to comment on my comments. Those comments are how I understand things so far and would love to be set straight early on if my understanding is incorrect.