help 4 a newbie

RMParkhouse

New Member
hey guys, im an electronics student doing AS electronics and im trying to get used to using PICAXE for a project so i set myself some problems to try and solve. this one is basically a car park which has 20 spaces, so i wrote the following:

symbol counter = b0
symbol in = 1
symbol out = 2
symbol open = 3
symbol full = 4
symbol cardI = 5
symbol cardO = 6
symbol sensorOUT = 7
symbol sensorIN = 8


main: for counter = 0 to 20
if cardO = 1 then flashOUT
if counter = 20 then stop
high open
if cardI = 1 then flashIN





flashIN:
high in
if sensorIN = 1 then flashIN
counter = counter + 1
low in
goto main



stop:
high full
low open
goto main


flashOUT:
high out
if sensorOUT = 1 then flashOUT
counter = counter - 1
low out
return

in is a barrier to get in
out is a barrier to get out
open is a light indicating spaces
full is a sign indicating no spaces
cardI is the card to get in
cardO is the card to get out
sensorIN is a sensor to check if the car is inside yet
sensorOUT is a sensor to check if the care is out yet

oh nd the pin numbers arent properly assigned but im not worried bout that, i just wanted to see if the program would work

now i know there are at least 3 or 4 mistakes so could people please point out what they are and maybe suggest some improvements, thnx

Edited by - RMParkhouse on 11/26/2005 10:29:20 AM
 

hippy

Ex-Staff (retired)
The idea and algorithm is generally sound, but a few problems and some things to think about ...

"Stop" is a reserved word and can't be used as a label.

"sensorIN" is defined as a constant and then used as a variable in an IF. It should presumably be defined as "input8" or "pin8", but then neither of those physically exist.

The same for "sensorOUT".

The "FOR counter = 0 TO 20" doesn't have a terminating NEXT, but is not needed anyway.

The "FlashOUT" routine terminates using "RETURN" when it has not been called by a GOSUB. It should probably be a "GOTO Main".

The "Main" routine falls through into "flashIN".

There's no "LOW full" in the program; both "Full" and "Open" lights will light at the same time.

The algorithm falls to pieces if there's a power cut and a reset happens while there are cars in the car park. Need to prevent "counter" going below zero.

Entry and exit cannot be done in parallel. If a driver maliciously stops under the in barrier or breaks down there, no one can leave until the car is removed. Similarly on the way out.

The entry process activates on "cardI", and if the driver forgets to take his card, enters and parks, the in barrier will go into a repeating up-down-up-down cycle.

The same when a driver leaves and forgets to take the card but, worse still, no one can enter until someone removes that card. An entirely empty car park can be put out of use.

There's a design flaw ( nothing to do with the coding ) in that nose-to-tail cars can enter and leave without cards. As long as "SensorIN" or "sensorOUT" is active cars the respective barrier stays up.

For user courtesy, the status indicator should really switch from "Open" to "Full" when the 20th driver inserts their card, not after they have entered.

What happens when a driver inserts their card on entry or exit, but then reverses up and doesn't actually enter or leave ? It looks to me like a mis-count will occur as "sensorIN" and "sensorOUT" are set when the vehicle is stopped in the position to activate "cardI" and "cardO". If not; inserting the card causes the barrier to rise briefly ( unnoticably in practice ) and then drop immediately.

If there is a power-cut and a reset while a car is entering or leaving the barrier can be brought down on the car.
 

RMParkhouse

New Member
thnks for the help, im not too bothered about the practical aspects, its more the code im trying to perfect, since this is only a problem to help me familiarise myself with BASIC. so, i tried doing what you said but i think ive made another mistake, heres what i got:

symbol counter = b0
symbol in = 7
symbol out = 8
symbol open = 3
symbol full = 4
symbol cardI = 5
symbol cardO = 6
symbol sensorOUT = input1
symbol sensorIN = input2


main:
for counter = 0 to 20
low full
low in
low out
cardO = 1 then flashOUT
if counter = 20 then halt
high open
if cardI = 1 then flashIN
goto main




flashIN:
high in
if sensorIN = 1 then flashIN
counter = counter + 1
low in
goto main



halt:
high full
low open
goto main


flashOUT:
high out
if sensorOUT = 1 then flashOUT
counter = counter - 1
low out
goto main

i know iv made a few mistakes so could you, or anyone point them out so i can learn from my mistakes, thnx
 

Technical

Technical Support
Staff member
You are pretty much there, its just the 20 limit bit that not quite right. You don't need to use for..next

Your main section can just look like this

main:
low full
low in
low out
high open
if cardO = 1 then flashOUT
if cardI = 1 then flashIN
if counter > 19 then halt
goto main

You might want to think about when the LEDs are switched on and off - in the program at present they very briefly 'flash' off/on when they don't need to...but thats a minor issue you can look at trying to solve later.

Edited by - Technical on 11/26/2005 6:16:33 PM
 

bgrabowski

Senior Member
Ignoring Hippy's reply is your main mistake!

Why not set yourself a simpler initial task like traffic lights to work up your programming skills. This can then be a module in a pedestrian-controlled crossing programme, building complexity as you go but in easily debuggable stages.
 

RMParkhouse

New Member
ive already done a traffic light system and it works, also i have some experience using programmers so it is just a case if getting to grips with BASIC more than learning how to programme. but anyway thanks for the help
 

TomMystery

New Member
RMParkhouse, Hippy's analysis was of a great importance if you ever want to become a good programmer. By ignoring his analysis of your program, and being hardheaded, you will never be able to write a good and efficient program. While I'm sure that your traffic light program worked, I have no doubt that it could have been written more effeciently.

In the future, you should respect the time that people spend in order to answer your posts, especially if they are trying to help you diagnose possible problems that you could run into in the future.

- TomMystery

Edited by - TomMystery on 11/30/2005 7:53:16 PM
 
Top