PDA

View Full Version : A few weird programming issues!



Gaby D.
11-08-2009, 09:37 AM
Edit: Another programming issued detailed in a below post. thanks!
What I need this thing to do is increase the set temperature by one every time I press this button...
But, what it does instead, is stay stuck on 1 FOREVER, and still increase the set temperature.

I can only get the IN9=0 if I.. stick my hand near the wires inside of the box.
If I move my hand outside of (what I assume to be) the electromagnetic field, it reverts back to 1 again. My project partner didn't believe me until he experienced it himself!

So, recap:
I press the button which gets IN9 = 1, the setTemp goes up constantly because it stays, and the only way to get IN9=0 is if I disrupt whatever the heck is going on with my hand, which doesn't have to include physical touching of any wires or components.

Is there any way I can
1) Get the set temperature to go up by only one, for every time the state is at 1 (in other words, every time IN9=1 it goes up by only 1)?
2) Minimize this field (or whatever on earth is causing the problem)

heres the snippet of messy test code we have so far:

setTemp VAR Word
setTemp= 60

DO
IF(IN9=1)THEN
setTemp=setTemp+1
PAUSE 100
ENDIF
PAUSE 100
DEBUG CRSRXY, 6, 3, DEC setTemp, TAB, DEC IN9, CR
LOOP

Post Edited (Gaby D.) : 11/9/2009 9:16:26 AM GMT

sam_sam_sam
11-08-2009, 09:51 AM
Please show how you have your switch hook up


DO
IF(IN9=1)THEN
setTemp=setTemp+1
PAUSE 100
ENDIF
PAUSE 100
DEBUG CRSRXY, 6, 3, DEC setTemp, TAB, DEC IN9, CR
LOOP

·Try this and see if this works better I know that you have your at Pin9 mine hook up on pin4

One Note if you hold the button it will keep going up by one until you release the button

' ================================================== =======================
'
'·· File......
'·· Purpose...
'·· Author....
'·· E-mail....
'·· Started...
'·· Updated...
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'
' ================================================== =======================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------


' -----[ Constants ]-------------------------------------------------------


' -----[ Variables ]-------------------------------------------------------

setTemp···· VAR······ Word


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------
·setTemp = 60

' -----[ Program Code ]----------------------------------------------------

Start:
· DO
·· INPUT 4
·· DEBUG HOME, BIN1 IN4, " setTemp ", DEC· setTemp
·· IF IN4=1 THEN
·· GOTO start
ELSE
·· IF IN4=0 THEN
·· setTemp=setTemp+1
PAUSE 300

ENDIF
ENDIF
· LOOP


' -----[ Subroutines ]-----------------------------------------------------



I hope this helps

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·http://forums.parallax.com/images/smilies/idea.gif·that you may have and all of your time finding them http://forums.parallax.com/images/smilies/smile.gif

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 11/8/2009 3:05:09 AM GMT

Gaby D.
11-08-2009, 09:55 AM
One end is wired into boebot VSS, one wire is straight into pin 9.
Its a button, not a switch if it matters any.

sam_sam_sam
11-08-2009, 10:43 AM
Vss....> .·10 k ohm resister ...>·. Button...>. VDD
··········································· · ··|
·········································· · ·^ . ...> 220 ohm·resister ....>·.PIN9······


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·http://forums.parallax.com/images/smilies/idea.gif·that you may have and all of your time finding them http://forums.parallax.com/images/smilies/smile.gif

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 11/8/2009 4:20:40 PM GMT

$WMc%
11-08-2009, 11:20 AM
Your input pin is left floating with out a button press. You need a 10k resister to pull the pin low.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············___$WMc%___······················ ······ BoogerWoods, FL. USA

Post Edited ($WMc%) : 11/8/2009 3:27:09 AM GMT

sam_sam_sam
11-09-2009, 12:17 AM
$WMc%

You are right I did have the input floating I re did it the right way Thanks for pointing that out to me

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·http://forums.parallax.com/images/smilies/idea.gif·that you may have and all of your time finding them http://forums.parallax.com/images/smilies/smile.gif

·
·
·
·
Sam

Gaby D.
11-09-2009, 02:59 AM
Wow, thank you guys so much! I really appreciate all of your help.
Hopefully one day I'll be knowledgeable enough to help people out too. :)

sam_sam_sam
11-09-2009, 09:55 AM
Gady D.

Did that work for you the way you want it to work

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·http://forums.parallax.com/images/smilies/idea.gif·that you may have and all of your time finding them http://forums.parallax.com/images/smilies/smile.gif

·
·
·
·
Sam

Gaby D.
11-09-2009, 05:12 PM
Yes, it worked perfectly. :)

But, I do have another programming related question.
We're assigning certain pins on the boebot to send out different voltages to an actuator to regulate a temperature. We want a range of temperature differences that would activate the pin. This is the code we used:


IF (currentTemp-setTemp) = (20 OR 19 OR 18 OR 17) THEN
HIGH 7
LOW 1
LOW 11
LOW 10
LOW 8
PAUSE 100
ELSEIF (currentTemp-setTemp) = (16 OR 15 OR 14 OR 13) THEN
HIGH 8
LOW 1
LOW 11
LOW 10
LOW 7
PAUSE 100
ELSEIF (currentTemp-setTemp) = (12 OR 11 OR 10 OR 9) THEN
HIGH 10
LOW 8
LOW 7
LOW 1
LOW 11
PAUSE 100
ELSEIF (currentTemp-setTemp) = (8 OR 7 OR 6 OR 5) THEN
HIGH 11
LOW 8
LOW 7
LOW 10
LOW 1
ELSEIF (currentTemp-setTemp) < 5 THEN
HIGH 1
LOW 11
LOW 10
LOW 8
LOW 7
ELSEIF currentTemp=setTemp THEN
LOW 10
LOW 11
LOW 8
LOW 7
LOW 1
PAUSE 100
ENDIF

it doesn't seem to work too well, any idea why?
We also tried something like ELSEIF (currentTemp-setTemp) <= 30, suggested to us by our professor, but that didn't work too well either.
We're all pretty frustrated with the code at this point, any ideas?

allanlane5
11-09-2009, 10:41 PM
Using "OR" that way does not work. You need separate clauses like:
'*** The Right Way ***
TempDiff VAR WORD

TempDiff = CurrentTemp - setTemp
IF (TempDiff >= 17) AND (TempDiff <= 20) THEN

' *** The Wrong Way ***
The value of (20 OR 19 OR 18 OR 17) is a single number -- namely the value of 20 or-ed with 19, then that result
or-ed with 18, then that result or-ed with 17. 20 Decimal equals $14 Hex equals %00010100 binary. 19 decimal equals $13 Hex equals %00010011 binary. So %00010100 ORed with %00010011 is %00010111, == $17, == 23 Decimal.

Which I'm pretty sure is not what you wanted to do. So while in English it "sounds" right, mathematically it doesn't do what you wanted to do.

Gaby D.
11-10-2009, 02:35 AM
Oh! Okay. I looked in the manual and saw "OR" was supported under BS2, so I guessed that was a valid means of using it as any other way.
That means my professor was on the right track with his suggestion.

Now the program appears to work, but now the boe-bot (or SOMETHING) isn't. Each pin was individually tested to reassure connectivity, and they all work, but for some reason when I throw it all together with everything else it doesn't want to work.
I displayed the statuses of each pin on the debug screen to make sure the right pins were activated, and they are, but the actuator isn't responding in the associated manner. The only time the actuator will respond is if pin7 is active, and even then it opens to some place that we never calibrated. We have a chart of the voltage readings for when each pin is activated, and the number we're getting doesn't correspond with any of them. If we move the number out of pin7 territory, the actuator closes itself like its getting no voltage.

This project just doesn't want to reach full functionality!

Post Edited (Gaby D.) : 11/9/2009 7:03:55 PM GMT

allanlane5
11-10-2009, 03:07 AM
An "actuator"? What's that? And it "opens"? It has a "position"?

You're going to need to describe your "actuator" in more detail.

Also the statement "if we move the number out of pin7 territory" is very vague. Do you mean "When TempDiff is not in the range 17 through 20"?

Gaby D.
11-10-2009, 04:15 AM
An actuator is something that controls a mechanical system through different means, depending on what type you have.
http://en.wikipedia.org/wiki/Actuator
We have a Proportional NSR ball valve actuator. You attach a ball valve to it, and itll open the valve proportional to the voltage you give it. Right now we have pins set up that will give off 0.6V, 0.68V, 0.95V, and 1.15V, each assigned to different pins that are triggered by the variable TempDiff.

And yes, that's what I mean. If TempDiff is not in the range that triggers pin7, it acts like its getting no voltage, and totally closes.
If the variable hits pin7s range, it gives us 0.9V, which is close to one of our values, but not the one assigned to pin7. Pin 7, when high, will give the actuator 1.15V.

sam_sam_sam
11-10-2009, 09:02 AM
Gady D.
·
ELSEIF (currentTemp-setTemp) = (16 OR 15 OR 14 OR 13) THEN

Try this routine also allanlane5 told you the same thing that what you have above will not work

ELSEIF (TempDiff··>·13)·AND ( TempDiff<·16)THEN

or

ELSEIF ( TempDiff·>·= 13)·AND (TempDiff·<·= 16)THEN

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·http://forums.parallax.com/images/smilies/idea.gif·that you may have and all of your time finding them http://forums.parallax.com/images/smilies/smile.gif

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 11/10/2009 1:13:15 AM GMT

stamptrol
11-11-2009, 02:06 AM
You haven't got the voltages of the different pins tied together have you?

What I mean is, if you have 4 pins for 4 values, those values are driving the same valve, right?

If a pin is supposed to be on, but the others are set to LOW, your output voltage will be some resultant of all 4, and most likely lower than expected.

You may have to make sure any pin not being used is set to be an input so its high impedance won't affect the actual value you want.

A schematic would be a great help here.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk

http://www.siskconsult.com
·

allanlane5
11-11-2009, 02:57 AM
The BS2 can use "PWM" to generate an analog voltage across a capacitor, I believe ( I haven't used this approach myself). Sounds like you've implemented a "resistor ladder" approach to make a digital-to-analog conversion. I think a schematic would help a lot here too.