need help with Picaxe

Thread Starter

appleLady

Joined Nov 15, 2010
11
can someone help me fix the code?
i dont know what's wrong with if..else command

the code :
'===================
main:
readadc 0,b1

if b1<0 then short
else if b1>=3 then normal
else alarm
end if
goto normal


short:
high 1
low 2
low 3
goto main

normal:
low 1
high 2
low 3
goto main


alarm:
low 2
low 1
high 3
pause 2000
low 3
goto main

'=====end====


condition :
b0<0 short
b0>=3 normal
b0 = infinity alarm
 

Rbeckett

Joined Sep 3, 2010
208
I might suggest that you join the Rev-Ed forum and present that code to them. They are 100% Picaxe and will get you going pretty darn quick over there. Its here http://www.picaxeforum.co.uk/. Free to join and the biggest forum for those chips and programming language. I am a member too, same user name.
Bob
 

Thread Starter

appleLady

Joined Nov 15, 2010
11
already registered but i cant post any thread.

"appleLady, you do not have permission to access this page. This could be due to one of several reasons:

Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation."
 

Rbeckett

Joined Sep 3, 2010
208
already registered but i cant post any thread.

"appleLady, you do not have permission to access this page. This could be due to one of several reasons:

Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation."
PM Me the info and the question and I will post it for you if you would like. It will be a little slower, but at least get it into the Picaxe pro's arena. Hope this helps.
Bob
 
Which PicAxe chip are you using? The changes below
will work with an 18X

' === code===
main:
readadc 0,b1
IF b1=0 THEN
' minimum value of b1 is 0, maximum value is 255
' b1 < 0 can never happen
GOSUB short
ELSEIF b1 >= 3 THEN
' 3 to 255 is a VERY wide range!!
GOSUB normal
ELSE
' this will happen ONLY if b1 = 1 or b1 = 2
GOSUB alarm
ENDIF
PAUSE 2000 ' so you can see the output conditions
GOSUB normal ' return outputs to "normal" (??)
GOTO main ' do it all again

short:
high 1
low 2
low 3
RETURN

normal:
low 1
high 2
low 3
RETURN

alarm:
low 2
low 1
high 3
pause 2000
low 3
RETURN

' === end code===
 

Thread Starter

appleLady

Joined Nov 15, 2010
11
i used picaxe14

sorry didn't mention it earlier.
i think i used the wrong value.
The want to detect if the value of voltage is within the range of 2v to 3V, then the circuit is normal. other than that, trigger the alarm.
IF the voltage is zero, then the wire is short circuit.
 
#rem

In a "perfect" world, the ADC for each voltage measurement:

0.0vdc b1=0
0.5vdc b1=26
1.0vdc b1=51
1.5vdc b1=77
2.0vdc b1=102
2.5vdc b1=128
3.0vdc b1=153
3.5vdc b1=179
4.0vdc b1=204
4.5vdc b1=230
5.0vdc b1=255

But, without having a circuit diagram I can only guess the actual values.

Remember, you should have a current limiting resistor on the ADC input (and a prevention circuit to keep the input between 0vdc and 5vdc) which will affect the ADC values!

#endrem


IF b1 > 154 THEN ' 154=3.1vdc
GOSUB alarm ' input is greater than 3.1vdc volts
ELSEIF b1 >= 102 then ' 102=2.0vdc
GOSUB normal ' input is between 2.0v and 3.0v
ELSE ' everything not covered above
GOSUB short ' below 102 - less than 2.0vdc
ENDIF



 
I quickly sketched up an interpretation of your schematic.

Since you didn’t include a “download” circuit, I added the “advanced” circuit. You may stick with the “basic” circuit if you wish.

I popped in a typical “7805” power supply, feed it with 8-12VDC. Keep the caps as close as possible to the 7805. The 1n4007 across the 7805 protects the 7805 and circuit when power is removed.

The input 1n4007 protects the circuit from input reversal. (I have a bucket full of 1n4007’s, that’s why I use them verses a 1n4002, or 1n4003…)

Unless you’re using LED’s with built in resistors, you’ll want to add a 330R (typical, for red LED’s) for each LED, as shown.

You must have a decoupling capacitor (104 / .1uF ceramic) located as physically close to the power pins of the PicAxe as possible.

Any unused inputs (IN4/IN3/IN2/IN1) must be tied either to ground V0 (recommended) or to V+ through a 10K0. “Floating” inputs will only cause you grief. Unused outputs may be left floating.

Between the POT (RV1) and the ADC pin of the PicAxe you’ll want a low value resistor (100R) or you can use two low value resistors between the POT and V+ and another at V0 to limit current to the input pin. Although it’ll change your ADC value, you can easily make up the difference in the code. (I have another bucket full of 1KR’s so I use them, again – simple to adjust for in code.)

I couldn’t make out the detail on your Q1 (my old eyes) but you may want to consider adding a base resistor and maybe another on the collector.

I can’t determine the connections or the purpose of your D3.

Have fun!!

:) joe
 

Attachments

Thread Starter

appleLady

Joined Nov 15, 2010
11
if i run the code,

Rich (BB code):
IF b1 > 154 THEN ' 154=3.1vdc 
GOSUB alarm ' input is greater than 3.1vdc volts
ELSEIF b1 >= 102 then ' 102=2.0vdc 
GOSUB normal ' input is between 2.0v and 3.0v
ELSE ' everything not covered above 
GOSUB short ' below 102 - less than 2.0vdc
ENDIF
syntax error
"syntax check for picaxe-14M failed
elseif alarm<=128 then gosub normal

Error : Elseif without if
 
Last edited by a moderator:

bertus

Joined Apr 5, 2008
22,278
Hello,

With the code tags you can do better formatting of the programs.
This can make readabilty better.

Is it possible to use a case command in your compiler?

Bertus
 
Last edited:

Thread Starter

appleLady

Joined Nov 15, 2010
11
i'm not sure if i can do it using case.
What i need to do here is to detect if the copper wire is cut.
since the copper wire got resistance, i replaced the copper wire with potentiometer as i need to done the circuit in simulation only.
 
@AppleLady
I've changed the code to reflect the schematic I sketched.

@Bertus Yes, CASE can be used and I prefer it.

Rich (BB code):
#picaxe 14M
SYMBOL LED1 = output3 ' short LED
SYMBOL LED2 = output4 ' normal LED
SYMBOL BUZ1 = output5 ' alarm buzzer 
SYMBOL AdcPot = b1
main: 
readadc 0,AdcPot
 
SELECT CASE AdcPot
CASE > 154   ' 154=3.1vdc 
  GOSUB alarm
CASE >= 102   ' 102=2.0vdc
  GOSUB normal
CASE < 102  
  GOSUB short ' below 102 - less than 2.0vdc  
ENDSELECT
GOTO main
short: 
  high LED1 
  low LED2 
  low BUZ1 
RETURN 
normal: 
  low LED1 
  high LED2 
  low BUZ1 
RETURN 
alarm:
  low LED2
  low LED1
  high BUZ1
  pause 2000
  low BUZ1
RETURN
Using IF/ENDIF
Rich (BB code):
#picaxe 14M
SYMBOL LED1 = output3 ' short LED
SYMBOL LED2 = output4 ' normal LED
SYMBOL BUZ1 = output5 ' alarm buzzer 
SYMBOL AdcPot = b1
main: 
readadc 0,AdcPot
IF AdcPot > 154 THEN ' 154=3.1vdc 
  GOSUB alarm ' input is greater than 3.1vdc volts
ELSEIF AdcPot >= 102 THEN ' 102=2.0vdc 
  GOSUB normal ' input is between 2.0v and 3.0v
ELSE ' everything not covered above 
  GOSUB short ' below 102 - less than 2.0vdc
ENDIF 
GOTO main
short: 
  high LED1 
  low LED2 
  low BUZ1 
RETURN 
normal: 
  low LED1 
  high LED2 
  low BUZ1 
RETURN 
alarm:
  low LED2
  low LED1
  high BUZ1
  pause 2000
  low BUZ1
RETURN
joe
 
i'm not sure if i can do it using case.
What i need to do here is to detect if the copper wire is cut.
since the copper wire got resistance, i replaced the copper wire with potentiometer as i need to done the circuit in simulation only.
Oh, well, that changes things significantly.

Is this what you're thinking will happen? The RED-X indicates the open circuit.
 

Attachments

Maybe.

(My back is really screaming today. I was struck by a car, awaiting back surgery and I'm not thinking clearly. )

Is the power supply feeding the PicAxe the same power supply feeding your "copper" wire? If both are using the same power supply, then yes, it'll work. How long is your "copper" wire?

If not, you might want to look at an inexpensive opto-isolator.

joe
 

Thread Starter

appleLady

Joined Nov 15, 2010
11
OMG!
Are you ok?

The copper wire will be about 2km.. I already calculate that the value of resistance is about 165.7Ω and if i put 4.7kΩ in series with the potentiometer, i got the value of 2.5V
 
2km? As in, over a mile? ‘Round these parts we call that an antenna or lightning rod. It would not be wise to connect a wire that long to an input of any PicAxe, or many other chips!

You’ll need to come up with something to interface to the PicAxe. To cut down on wire resistance (2km, really?) you might want to think about running a low voltage alternating current through your wire, then change it to DC for input to an opto, then to the PicAxe.

I’ll stew on some alternatives. Today is a “screaming back” day, I’m not sure what my brain will let me consider. Tell us more about this 2km length of wire.

joe
 
Top