using the if command

jcat

New Member
hi I have been writing a program to push a button using the if pin to get the program to switch between a 1+15minutes (hour time )and a 2hour time the problem is that it works fine on the simulator but when transferred to 08m picaxe it does not run on the two hour section ? Another problem that I over come was by using a reduction drive small motor as at the start of running it does 2 little jumps on ,there is not enough energy to move the motor

Can any one come up with an answer page 25 section 3 of the manual is being used to use the switch ??

So to recap the 1.15min section is ok the 2hr ?? why ??

The 2hour section is a copy of the one hour section with just the next loop extended

Code:
main:' 1 June 2021  to turn on Clear click by press the button down

pause 2000


if pin3 =0 then one
if pin3 =1 then two

goto main

one: 'turn motor on first push button on
high 0 'turns 0 on
pause 770 'rotate motor
low 0 'turn off 0 and motor

for b4 = 1 to 75 ' start of next loop (75 is 1 hr 15 minutes)
wait 60 ' 60 seconds 1 minute
next b4 'next loop


pause 200
high 0 ' turn on 0 / turn motor on and push button

wait 1
pause 999 'rotation of motor to new position
low 0 'turn off 0

end


two: ' turn motor on push button on

high 0 'turns 0 on
pause 770 'rotate motor
low 0 'turn off 0 and motor

for b4 = 1 to 135 ' start of next loop (135 is 2 hr 15 minutes)
wait 60 ' 60 seconds 1 minute
next b4 'next loop


pause 200
high 0 ' turn on 0 / turn motor on and push button

wait 1
pause 999 'rotation of motor to new position
low 0 'turn off 0

end
 

lbenson

Senior Member
A typical problem causing this is that the input pin is "floating"--is in an indeterminate state where electrical "noise" can cause it to fluctuate rapidly between what your program sees as 0 and 1. The simulator will not reveal this.

Do you have the 10K resistor shown in the diagram? If not, the fix is to connect a "pulldown" resistor (10K is usually a good size) between your input pin and 0V.

I admit to some confusion: the switch in the diagram doesn't go to an input pin--it appears just to be a power-on/power-off switch (if we're looking at the same version of the manual).
 
Last edited:

inglewoodpete

Senior Member
lbenson has raised a question about the input switch.

Now, a question about the other end of the equation: how have you connected your motor? For the uninitiated, motors can be difficult to drive from a microcontroller.
 

jcat

New Member
2) the motor is connected via a mosfet we built our own push bike motor controller using mosfets so have some knowledge

1) yes there are 10k pull down resistors and the 1k between that and pin 3
early in the day I went back to bread board with the ov and output (pin7 normal ) connected from the bread board this did work so using a sliding switch copied what I had done via the 2 dig in the book again the 2 part does not run it sound that when pin 3 is o volts that it does not switch the relay

with volts on pin 3 then the first part of the program runs

the switch in the manual I have is the switch goes to pin 0 there are 4 switches above on the page then it shows 5v through a switch then 1k with the junction going to 10k to 0v / looking at picaxe 08m section 1 page 6 infrain/in 3 (pin 4 normal IC)

we have not used a switch on only 1 pin before

thanks for the replys
 

AllyCat

Senior Member
Hi,
the switch in the manual I have is the switch goes to pin 0 there are 4 switches above on the page then it shows 5v through a switch then 1k with the junction going to 10k to 0v / looking at picaxe 08m section 1 page 6 infrain/in 3 (pin Leg4 normal IC)
That doesn't look like the diagram in Section 3, Page 25 ("Output Device 12 - Smart Wire & Smart Springs") of my Manual either. It's always better to quote Title/Descriptions, not page numbers. Also, Pin 0 (Leg 7) is an "Output Only" on the 08M{2} so couldn't be used as a switch (input).

But using that pin ( {C.}0 ) as an Output to drive a motor is also a "Bad Idea": It's the Serial/Programming Output which may do "unpredictable" things during a program download and prevents you using it for the DEBUG facilities (which should help you solve most problems after a program has been downloaded to the Hardware).

The first thing to discover is if Pin.3 is actually being read as either a "0" or "1", which could be done with a SERTXD (#pin1) instruction, or by flashing a test LED on another pin. Also, whenever any "power" component like a motor is being driven, it's advisable to provide some test that the program is not being "accidentally" Reset by "noise" on the supply rail. That's easiest with a simple SERTXD("Starting ") at the top of the program.

Then I would change the program so that it doesn't take 2+ hours to test !! Note also that the "goto main" loop will never be repeated because the sections "one:" and "two:" are terminated by an END.

Cheers, Alan.
 

jcat

New Member
Hi Alan. Im Keith ? Im in new zealand and the shops are no longer stocking picaxe overseas seem very expensive for the freight as well as cost of chips ?

OK the motor is used to press a button I have a clear click box that lets you record programs to usb drive or sd card I record train videos which are one or two hours so the the button is pressed to start the recording and pressed again after 1 hour or 2 hours then yes the program ends the switch being to ajust the duration of the time required the motor has a off set arm that presses a leaver to hit the button The train videos are around 11pm at night so dont want to stay up that late

WE tried going straight to the motor with out the relay just using the most fet the trouble with that is the picaxe gives 2 little bursts not programed in before turning on via the program?

When testing I ajust the program so 1 hour does 1/2 a turn and the 2 hour does 3 turns of the motor.

I can say that the picaxe is being read with no volts on the pin (I'm using a 12volt gell cell battery) for the first part of the program

with volts on the pin it should run section 2

I will try putting a small value cay on pin 3 (.001)

Manual input device interfacing

on the test board I have a led via pin 7 and a 330ohn resistor

I may be repeating my self yesterday I have a small bread board with its own battery supply so using that I set it up and jumped leads over to the motor board o volts and pin 7 altering the switch it all worked so built the switch as per what i used on the bread board but on testing it was back to its old ways

I have not used the commands you have included in your note so will do some reading Thanks for you input Keith
 

AllyCat

Senior Member
Hi Keith,

PICaxe components are still easily available in Australia so you might find them at a more acceptable price. I can't check the shipping myself (with no NZ postcode) but you might try Wiltronics.* However, you don't need a "new" PICaxe, the M2 PICAXEs have more features, but an 08M should be fine for your program, and is fully supported by the latest Editor Software (PE5 or PE6).

But particularly for the 08M it's important to differentiate between the "Port.PIN" names and the "Leg" numbers. The 08M and 08M2 have only one Port (normally called "Port C") but you can still use the "modern" names with the 08M. Thus, calling the "Input Only" pin "Pin C.3" or "Leg 4" will avoid any confusion caused by descriptions such as "Pin 3" or "Pin 4".

As indicated also by others, "Hardware" does not necessarily behave in the same (or the expected) way as the Simulator, so it's important to have a strategy to "Test and Debug" any new hardware. PICaxe supports this very well by using the "Programming Interface" (in particular the Serial Out, Leg 7, pin c.0) combined with the "Terminal Emulator" within the Program Editor. Therefore, "Pin 0" (Leg 7 on 08M) should not be used for the "application" (Motor, LEDs, etc.) unless/until ALL the other pins are already being used. There are many perfectly satisfactory ways to write and test a Program, but here is an example using some of the more "modern" PICAXE features (which also can be used with the 08M).

Code:
' 11 June 2021 ; To turn on Clear click by press the button down (Revised)
#picaxe 08m                    ; Or 08M2, etc.
#terminal 4800                ; Open the Debugging Terminal when program runs
pause 2000                    ; Wait for the Terminal and PICaxe to stabilise
sertxd (cr,lf,"Starting")        ; Report when the Program (Re-) Starts
DO                                ; Optional Repeating loop
    sertxd (" Pin3=",#pinc.3)    ; Report the Pin Level
    if pinc.3 = 0 then
        b3 = 75                ; Delay in minutes (75 is 1 hr 15 minutes)
    else
        b3 = 135                ; Delay in minutes (135 is 2 hrs 15 minutes)
    endif
    high c.1                 ' Turn on Leg 6 (motor)
    pause 770                 ' Rotate motor
    low c.1                     ' Turn off Leg 6
    for b4 = 1 to b3      ' Start of delay loop
        wait 60                ' 60 seconds = 1 minute (Reduce/Remove for testing)
    next b4
    high c.1                 ' Turn on Leg 6 turn motor on and push button
    pause 1999                ' Rotate motor to new position (~2 seconds)
    low c.1                     ' Turn off Leg 6
    end                        ; Optional stop after only one pass
LOOP
*EDIT: Hmm, Wiltronics seem rather expensive for shipping, even to Australia, and they price the 08M2 as high as the 14M2 :( . But, as we discovered in another thread last year (post #58), Rev. Ed. (in UK) appear to have a "sweet spot" in their Worldwide Shipping charges up to an order value of around $20. ;)

Cheers, Alan.
 
Last edited:

jcat

New Member
Hi Alan Thanks for the reply I got on to a company in nz that says they will have 08m this week $6.95 plus most likely $7 post from the South Island the guy said it can take them 6 to 8 weeks now to get container of assorted stuff from over seas



My friend has let the smoke out of his only one and I only have the one at this stage.We were getting concerned that they had gone off the market all together

Last night I recorded using just the front part set up for two hours IT recorded for 2hr and 16 minutes so recorded both 1hr shows

The clear click box I use goes between a raspberry v4 HDMI out to the box then the tv set HDMI then I record to sd card 32 g 1080 x1920 I past life I was a camera man for tv allso a radio ham not been on air for some years no 80years

WE used picaxe them many years ago to make a cat control for letting a cat in and out all so for a water system with a sola cell charger but apart from that have not learnt a lot of the program so what you are sending me is a steep learning curve

I was reading last night that a 27k resistor on pin 2 Input program input is need I will test that soon and other non used out puts should be tied to 0V with 10k resistors You comments

I will check out post58 And its good to have a person to learn from thanks Keith
 

AllyCat

Senior Member
Hi,
I was reading last night that a 27k resistor on pin 2 Input program input is need I will test that soon and other non used out puts should be tied to 0V with 10k resistors You comments
Yes, a pull-down resistor (the value is not very important) on Leg 2 (pin c.5) to Ground is absolutely essential for reliable operation of the PICaxe chips (EDIT: If the normal programming circuit has not been fitted). That's one reason why (IMHO) it's a "bad idea" to omit a programming interface from any PICaxe board.

Is it really an 08M (not 08M2) that your supplier is offering? That hasn't been manufactured for more than 10 years! However, for "simple" programs the two types are generally interchangeable. But the 08M2 is potentially a much "faster" chip (and it also has the new "time" facility of all M2s), so connecting the "recommended" decoupling capacitor (typically 100nF and/or 10uF) between Legs 1 and 8, becomes even more important. Omitting this capacitor or the Pull-down resistor are probably the two most common reasons why some PICaxe "Hardware" doesn't work in the same way as the Simulator suggests it should.

From here, it looks as if Rev-Ed (in UK) will ship a single 08M2 by Air Mail for about 4.38 UKP (around NZ $9 in total) [EDIT: perhaps technically correct, however, it's not "sensible" or viable to ship a single 08M2 half way around the world ! ], and I accept that Import Taxes/Duty can add "complications". PayPal can make "foreign" purchases very easy now, even if you don't have an account. Maybe one of our members in NZ or AU can give their opinion?

Cheers, Alan.
 
Last edited:

inglewoodpete

Senior Member
*EDIT: Hmm, Wiltronics seem rather expensive for shipping, even to Australia, and they price the 08M2 as high as the 14M2 :( . But, as we discovered in another thread last year (post #58), Rev. Ed. (in UK) appear to have a "sweet spot" in their Worldwide Shipping charges up to an order value of around $20. ;)
Wiltronics' pack-and-post price (only), for 2 x 20X2 chips, for me 3,000 km away on the "other side of" Australia is A$8.52 (GBP4.65), which I consider to be reasonable. I would expect delivery in about a week.

I went through the same exercise on the Rev-Ed website and the overall price for 2 x 20X2 plus airmail to Australia was about half the price - very reasonable! The challenge of ordering from the UK, due to the COVID-limited transport UK-->Australia at the moment, is the mail could take several weeks to reach me. (Sorry Clive, I cancelled the 'order').

The biggest component of chip prices here in the antipodes is the handling cost due to our relatively small population(s) and consequent small market - hence the unit prices for any chip begin the merge.
 
Last edited:

jcat

New Member
Hi,

Yes, a pull-down resistor (the value is not very important) on Leg 2 (pin c.5) to Ground is absolutely essential for reliable operation of the PICaxe chips. That's one reason why (IMHO) it's a "bad idea" to omit a programming interface from any PICaxe board.

Is it really an 08M (not 08M2) that your supplier is offering? That hasn't been manufactured for more than 10 years! However, for "simple" programs the two types are generally interchangeable. But the 08M2 is potentially a much "faster" chip (and it also has the new "time" facility of all M2s), so connecting the "recommended" decoupling capacitor (typically 100nF and/or 10uF) between Legs 1 and 8, becomes even more important. Omitting this capacitor or the Pull-down resistor are probably the two most common reasons why some PICaxe "Hardware" doesn't work in the same way as the Simulator suggests it should.

From here, it looks as if Rev-Ed (in UK) will ship a single 08M2 by Air Mail for about 4.38 UKP (around NZ $9 in total), but I accept that Import Taxes/Duty can add "complications". PayPal can make "foreign" purchases very easy now, even if you don't have an account. Maybe one of our members in NZ or AU can give their opinion?

Cheers, Alan.
13 June 2021
Hi Alan you have moved past mine and my friends understanding of programing I tried running your sample with the simulator but no luck as at this stage with only 1 picaxe I 'm trying not to write to it to many times The ones if they come will be the 80m2 type

Now i'm sure I have seen the high c.1 some where but could not locate it in the manual the simulator turned up illegal character and having not used sertxd etc or debug left the picaxe alone

its 6.30am and very dark but not cold Mt Egmont has some snow on it at its top by now it is usually covered New Plymouth is the area .

I'm printing out your reply s do you use viber or skype

so your sample program

#picaxe 08m2 (does this id the chip) # ?

#terminal 4800 (ok so when the chip is programed this runs) ?

I will go one step at a time to get a under standing

I just noticed that you are using Leg 2 (pin c.5) so will make a card with only the c.5 etc numbers at the right legs

Cheers Keith
 
Last edited:

AllyCat

Senior Member
Hi,

First, are you using the PE5 or PE6 Program Editor? It doesn't matter which, but they do work differently, so I don't want to give confusing descriptions. It's certainly worthwhile to fully check out any new program in the Simulator before programming a real chip, although you're very unlikely to "wear it out". However, another advantage of programming the PICaxe in the "final" PCB Hardware is that there's no risk of damaging the chip when you move it between the "programming" and "application" boards.

Yes, the "#" instructions make sure that we (and the computer) are talking about the same PICaxe type and that the Editor/Compiler/Simulator are setup in similar ways. Often, there are better (and more recent) descriptions of the PICaxe commands in the PICAXE > BASIC Commands Tab at the Top (left) on the Forum page. An "illegal character" message is possibly a confusion between dot/comma or zero/Letter0 or digit1/small-L, etc., but the Program Editor should show the line number and often a "Pointer" (^) to the approximate position.

The pin numbering is quite easy with the 8-pin chips; The (physical) "Leg" numbers count Anti-Clockwise upwards from Leg 1 at top-left, whilst the "Port.Pin" numbers increase Clockwise from Zero at the "Programming Output" pin just below the Earth Pin at top-right. The "C." (port identification) is always "C" and "optional" with the 8-pin chips, but a useful verification that it's a "Pin" and not a "Leg" number.

That's probably enough for now. Our 12 hour time difference is a slight hindrance, but there may be others "watching" this thread, particularly in Australasia.

Cheers, Alan.
 

jcat

New Member
Hi Alan lunch has been and gone rain is coming Hi

I put the 27k on c.5 and a .1cap from +V to 8oV on running a test this has made things worse.

I'm running xp and 5.1.5 I do have 6 on another computer but it is harder to program from (not 6 just the set up ) so the serial out to a home built board for programing this has work ok with past 08 work as you said 08 ten years ago that is about when we made the cat door and garden water system time goes past..

I just copied your line ( high c.1) and took it up in size it is a dot
I made a small program with high c.1
main:
high c.1 = 0 then sat ' Turn on Leg 6 (motor)
pause 770 ' Rotate motor
low c.1 ' Turn off Leg 6

goto main

Sat:

pause 300
goto main


error : Unknown symbol -c

Understood the # thank you

line number and often a "Pointer" (^) to the approximate position (yes I'm seeing this and maybe understanding it )

Talked with my friend and we are now going to use c.1 etc but as above this looks like not such a good idea as a radio ham have build all sorts using ic's so picaxe throws a spanner in the works. He can't help trying things out untill we get new 08?

because of adding the resistor and the cap will have to back track and see if I can sort out what is happening
Cheers Keith
 

AllyCat

Senior Member
Hi,

Do you mean version 5.1.5 ? The latest is 5.5.5 (or strictly there's a "patch" to 5.5.6). PE5 is still available in the "Obsolete" section of the Downloads Tab, if needed.

I don't think "high c.1 = 0 then sat ' Turn on Leg 6 (motor) " is a valid instruction. There should be a High c.1 somewhere and a separate line such as "IF PINc.3 = 0 THEN .....". But it's time for bed......;)

Cheers, Alan.
 
Last edited:

inglewoodpete

Senior Member
Hi,

Do you mean version 5.1.5 ? The latest is 5.5.5 (or strictly there's a "patch" to 5.5.6). PE5 is still available in the "Obsolete" section of the Downloads Tab, if needed.

I don't think "high c.1 = 0 then sat ' Turn on Leg 6 (motor) " is a valid instruction. There should be a High c.1 somewhere and a separate line such as "IF c.3 = 0 THEN .....". But it's time for bed......;)

Cheers, Alan.
All a bit confusing. If you're still using an 08M (rather than an 08M2), then the code should be:
Code:
main:
if pin1 = 0 then sat        ' Go and turn on Leg 6 (motor)
pause 770 ' Rotate motor
low 1         ' Turn off Leg 6

goto main

Sat:
high 1        
pause 300
goto main
Perhaps not the greatest piece of logic but it should work.

(I camped on the side of Egmont a couple of years ago! A pretty cool night from memory.)
 

AllyCat

Senior Member
Hi,
I put the 27k on c.5 and a .1cap from +V to 8oV on running a test this has made things worse.
In what way is the 27k and/or 0.1uF capacitor making things "worse"? Note that the "27k" is only required IF the normal programming circuit has NOT been fitted (I've edited my post to emphasise this). If it is added to a "normal" programming circuit, it may indeed STOP it working. Also, the capacitor should be connected directly to the PICaxe (socket) Pins (i.e. Legs) 1 and 8.
Code:
main:
    high c.1 = 0 then sat                 ' Turn on Leg 6 (motor)
......
error : Unknown symbol -c
The line of program that I quoted above does not pass a syntax check. It looks as if a {newline or : } "IF pinC. ?" has been omitted before the = . "Unknown symbol" suggests that there a "-c" (perhaps between spaces) somewhere in the program listing, but I can't see it. Or you have a VERY old version of PE5 ?

If you already have lots of "finished" Hardware which uses "Pin c.0" (to drive a motor, or anything else) then that can still be used. But it's more sensible to first develop the Program using a pin which allows the "Debugging" facilities to be used. The "correct" way to do this is with a "SYMBOL" command (e.g. Symbol Motor = C.0), but I didn't want to introduce too many "new features" at the same time.

Cheers, Alan.
 

jcat

New Member
Hi Alan Yesterday I went back to square one and used a bread board that has 3 1.5v cells watching the simulator made the decision to cut the pcb track and make output on c.1 I got a result and the short burst of volts to the motor cleared up the set up is now sitting on the (full) 2hour test still has a hour to run so see what happens

the picaxe is the 08m I will still get some new ones it the company has them arrive in NZ

the cap is across the 1 & 8

Not sure if version 6 will run on XP will remove 5 and see what happens

ok the rain has slowed down we get you weather 2 days after it has passed AU

Cheers Keith
 

AllyCat

Senior Member
Hi,

Yes, PE6 will run on XP (slowly !) but there is no need to "remove" PE5, the two programs can be installed (and even run) at the same time. I have PE5 and PE6 installed on all of my PCs (including Win 10) and probably still use PE5 as much as PE6, because it loads and runs so much faster.

Our hottest day of the year so far, and they're talking of more than 30 C. :(

Cheers, Alan.
 

papaof2

Senior Member
I still prefer the speed of PE5 for the things which it can do and it covers most of my PICAXE programming needs.

High today was 90F / 32.2C here in Georgia, USA Current humidity is 86% which translates to hot and muggy.
Tomorrow's prediction guess is 92F / 33.3C with humidity of 62 to 70%.
 

jcat

New Member
Hi to all to conclude
I cut the track on c.0 and made the output c.1 in the past we have all ways used c.0 but have never used a switch on just one input

On testing several times it is now executing the program 1HR OK 2HR ok

So using the IF command with a switch must use c.1 as out put

I had a wall wort 240ac to 12dc it did not have a earth pin and I could feel a bit of (something) on the 0 volt side it would be a switch mode / this was upsetting the mosfet and most likely the rest of the circuit

The board is being run from a 12volt battery /

With out the earth pin it should have been ok In NZ the Neutral and Earth are connected together at the switch board on the house with them going to a ground stake out side

Next job is to dig up a wall wort with the 3 pins on it and check out what happens

Alan thank you for your input NZ is in early winter and raining the train videos I record for a friend (94) who builds small steam trains run on a track to give children a ride Off sbs via Kodi

I have a Vast receiver new sitting on a shelf (may be some one needs a set) When Au change the satellite system they did not leave it over nz

before the vast system we could receive AU Pity

Alan I suggest that A new File is started if you are interested in teaching people and the IF is closed Cheers Keith
 

AllyCat

Senior Member
Hi,

The IF command is quite complex because it can be used in many different ways, as described in the On-Line Command Reference HERE and HERE. It can read ANY of the pins on most PICAXEs, but there can be "complications" when using the {C.}0 and {C.}5 pins on the 08M{2}. Surprisingly, nearly ALL the Command Reference "Code Examples", don't appear to work with the 08M{2}. :(

Certainly the {C.} 1 , 2 and 4 pins can be controlled as Outputs by an IF command (and by many other other methods), but {C.} 3 and 5 cannot, because they are "Input Only" pins. Also, {C.} 0 can be driven as an output, but it's not recommended unless all the other pins are already being used for other purposes.

Cheers, Alan.
 
Last edited:

jcat

New Member
Hi Alan we should have some 08m2 by the end of the week total cost 35.76 for 5 with freight the freight would be 7D

I have a saying (what are you going to use it for ) only when you get something that requires a item do we learn

May be If I life long enough we may meet I just had the prostate removed and if you are getting on in years you'll know what i'm talking about
What part of AU do you live in

Thanks for all your input take care I will see if I can dream up something new to build Cheers K
 
Top