stuck on first attempt!

frugmonkey

New Member
hi all.

its my first attempt at programming a picaxe chip. i bought a 28x1 chip and an experimenter board.
i'm trying to make a program to control an alcohol/water injection pump to go on my car. the idea is that the higher the boost from the turbo is, the faster the pump will run, the pressure is read from the map sensor in the intercooler which gives a 0-5 volt signal, i'm planning to have pots on two of the analogue inputs and the map sensor on another, so i can set a starting pressure of say 3psi (15% duty) up to 16 psi (100% duty)

ive written some of the program, but i'm getting a syntax error when i test the program, i'll paste it in below
i'm trying to get a range for the pump to operate across by subtracting the setting for the start boost from the maximum boost and then dividing it up so i can have 18 steps with a different pwm output for each step

the error appears under the 'w' in pwmout in the 6th line of curve 1?
main:
symbol test_button=pin0
symbol curve_1=pin1
symbol curve_2=pin2
symbol curve_3=pin3
symbol curve_4=pin4
symbol test_led=0
symbol fault_led=1
symbol led_20=2
symbol led_40=3
symbol led_60=4
symbol led_80=5
symbol led_100=6
symbol map_signal=b0
symbol min_boost=b1
symbol max_boost=b2
symbol range=b3
symbol rng_seg=b4
readadc 0, map_signal
readadc 1, min_boost
readadc 2, max_boost
if test_button=1 then gosub test
if curve_1=1 then gosub curve1

curve1:
readadc 0, map_signal
readadc 1, min_boost
readadc 2, max_boost
let range=max_boost-min_boost
let rng_seg=range/18

if map_signal=rng_seg <(2*rng_seg) pwmout 1 , 199,120
if map_signal=(2*rng_seg)<(3*rng_seg) pwmout 1 , 199, 160
led_20 high
if map_signal=(3*rng_seg)<(4*rng_seg) pwmout 1 , 199, 200
if map_signal=(3*rng_seg)<(5*rng_seg) pwmout 1 , 199, 240

if anyone can shed a little light on this it would be really useful to me as i'm a bit stumped, and being new to it i'm not really sure what i'm doing!

thanks in advance to anyone who might be able to help a little

jonathan
 

slimplynth

Senior Member
tentative posting from now on and deffinitely no drunken answers

Hi Frug

I'm sure someone with a far superior answer will post soon but maybe in the mean time try...

Code:
if map_signal=rng_seg <(2*rng_seg) then gosub Pw_1 

Pw_1:
pwmout 1,199,120
return
and do the same for the other PWM's
 

boriz

Senior Member
"its my first attempt at programming a picaxe chip"

LOL. What ever happened to flashing an LED? (The Picaxe equivalent of Hello World)
 

boriz

Senior Member
“if map_signal=rng_seg <(2*rng_seg) pwmout 1 , 199,120” is invalid syntax.

I have never used a 28x1, but I’m pretty sure you cannot use any maths in an IF statement. Also you are not using THEN or ENDIF. I’m also unsure what the ‘<’ sign is doing there after an ‘=’ sign.

I think the interpreter will get as far as “if map_signal=rng_seg” and then expect a jump label.

-Do any calculations before the IF statement.
-Only use variables or literals in the condition and make it a simple one, like = or <.
-Anything after the condition must be a GOTO or GOSUB label WHEN USING THE SINGLE LINE FORM.
-When using the multi-line form (like below), any code can be used between the THEN and the ENDIF (or ELSE).

EG:
Code:
tmp = 2*rng_seg
IF map_signal < tmp THEN
	pwmout 1 , 199,120
ENDIF
It’s all in manual2 under ‘IF’.
 

westaust55

Moderator
@frugmonkey

firstly welcome to the PICAXE forum.

Your code needs some further work. I presume you have only partially provided the code. please upload your entire code. It will be easier for people to see what is happening.
Also, add some comments describing what is to happen - makes it far far easier for others to understand your project and help you best First Time rather than making assumptions.

Next, please use the [code] and [/code] markers for code of more than a few lines. See the sticky README First post at the top of the forum active section.

Onto your program . . . .

where you have the lines:
Code:
IF curve_1=1 then gosub curve1 
Curve1:
READADC 0, map_signal
even if the IF staement test is false it will still drop through to the label "Curve1:"

maybe you need something like:
Code:
Main:

READADC 0, map_signal
READADC 1, min_boost
READADC 2, max_boost 

IF test_button=1 then gosub test
IF curve_1=1 then gosub curve1 
GOTO Main

Curve1:
READADC 0, map_signal

In your last 4 lines of code you have:

IF map_signal=rng_seg < (2*rng_seg) PWMOUT 1 , 199,120

What exactly are you trying to do/check here.

Firstly you have no THEN keyword to initiate/action the following command/fucntion (the PWMOUT 1 , 199,120 part)

secondly,
IF map_signal = rng_seg < (2*rng_seg)

what is the "rng_seg < (2*rng_seg)" trying to do?
are you treying to do two comparisons:
IF map_signal = rng_seg
and
IF map_signal < (2*rng_seg)

in which case you need something like
IF map_signal = rng_seg AND map_signal < (2*rng_seg)


AS Boriz has stated, you need to read PICAXE Manual 2 about the IF...THEN statements.
 

frugmonkey

New Member
thanks to all of you who have left a comment, i'm going to have a good look at the manuals and try and take some of it in.
its like trying to read chinese or something to me at the moment, but i'm sure i will pick up some of it.
i'll post back when i get a bit (hopefully) closer to what i think is right.

thanks again
 
Top