Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:08 28 Oct 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PICAXE program fault

Author Message
Chrisk

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 137
Posted: 09:35am 22 Sep 2025
Copy link to clipboard 
Print this post

Hi Guys
Can someone advise me why  the program below does not work.
I doesn't seem to get past the loop until C.3 = 1
If I change the trigger from low to high nothing happens.

After all this time I still don't how to put the code into that "Blue code Box"
Maybe someone could advise on that too.

Chrisk

'my attempt PICAXEFinal.bas  22/9/2025
'Overview: If Trig is 0 then loop and wait
'If trigger goes high start 2 min timer
'at end if still high set output C2 High for 2 min
'repeat until trigger goes low then output goes low
'at end of 2 min timing cycle.
'
#picaxe 08m2 'Identify the PICAXE being used as an 08M2.
#no_data     'No data tranfer required

Symbol X=b0 'Variable for the timer loop needs to be here ???

OUTPUT C.0 'C.0 not used
OUTPUT C.1 'C.1 not used
OUTPUT C.2 'MOSFET driver
INPUT  C.3 'Trigger
INPUT  C.4 'C.4 not used

Low C.2 'FAN/MOSFET OFF ensure on power up
Main:
Do
Do:Loop until PinC.3=1  ' pinC.3 = 0 then Low C.2 FAN/MOSFET OFF
pause 1000
loop
gosub Timx  ' wait 2 min before FAN/MOSFET ON
do
If pinC.3 = 1 then High C.2 ' Trigger High FAN/MOSFET ON
pause 1000
loop
else  ' Trigger has gone Low
gosub Timx  ' Fan continues for 2 min
Low C.2  'FAN/MOSFET OFF
gosub Main
endif

Timx:
for x=1 to 5 ' 1 to 120 for 2 min - 5 for test purposes
pause 1000
next x
return
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5398
Posted: 10:10am 22 Sep 2025
Copy link to clipboard 
Print this post

Hi Chrisk,

Indenting code helps in understanding how the flow is.

'my attempt PICAXEFinal.bas  22/9/2025
'Overview: If Trig is 0 then loop and wait
'If trigger goes high start 2 min timer
'at end if still high set output C2 High for 2 min
'repeat until trigger goes low then output goes low
'at end of 2 min timing cycle.
'
#picaxe 08m2 'Identify the PICAXE being used as an 08M2.
#no_data     'No data tranfer required

Symbol X=b0 'Variable for the timer loop needs to be here ???

OUTPUT C.0 'C.0 not used <--------------- C.0 IS PROGRAMMER PIN, DO NOT RE-CONFIGURE
OUTPUT C.1 'C.1 not used
OUTPUT C.2 'MOSFET driver
INPUT  C.3 'Trigger
INPUT  C.4 'C.4 not used

Low C.2 'FAN/MOSFET OFF ensure on power up
Main:
Do
 Do : Loop until PinC.3=1  ' pinC.3 = 0 then Low C.2 FAN/MOSFET OFF
 pause 1000
loop
gosub Timx  ' wait 2 min before FAN/MOSFET ON
do
 If pinC.3 = 1 then High C.2 ' Trigger High FAN/MOSFET ON
   pause 1000
   loop <-------------------------- WHAT IS THIS DOING HERE ?
 else  ' Trigger has gone Low
   gosub Timx  ' Fan continues for 2 min
   Low C.2  'FAN/MOSFET OFF
   gosub Main
 endif
<-----------------------------LOOP MUST BE HERE ???

Timx:
for x=1 to 5 ' 1 to 120 for 2 min - 5 for test purposes
 pause 1000
next x
return

PicomiteVGA PETSCII ROBOTS
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4100
Posted: 12:04pm 22 Sep 2025
Copy link to clipboard 
Print this post

Also, the gosub Main within Main is asking for trouble.

John
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3437
Posted: 02:06pm 22 Sep 2025
Copy link to clipboard 
Print this post

As above, LOOP in the wrong place, and you probably don't need 2 loops--just one and no "goto Main" (which you perhaps meant instead of the very wrong "gosub Main").

The PICAXE debugger is your friend. You can single step through your code to see what is actually happening (which all to often is different from what one thinks is happening).

To get your posted code in the "blue box", you can click on the "code" button and paste your code within the forum tags that have then been inserted in the edit window.

~
Edited 2025-09-23 00:10 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025