Programming hang ups

scorpy

New Member
Is there any way that a picaxe28x can be reset if its programme gets lost without the use of the hard reset. is there any means of programming within the picaxe system that will detect a hung programme and reset it. i am having a lot of problems with this especially after using the programme several times, all counters et are set back to 0 before the programme loop starts again, any help would be appreciated

 
 

Rickharris

Senior Member
You need to post up your programme so we can have a look.

The picaxe itself should not hang and or require reset to go on. Reset will start the programme from the begining just as if you powered off and on again.
 

Fowkc

Senior Member
Probably the best way to do this is to use a spare output (if you have one) to regularly pulse during your program. Interface this with suitable timing and logic circuitry to reset the 28X via the reset pin if the pulses stop. It won't start your program from where it hung though.

The best way to stop your PICAXE hanging is through good design in all aspects, especially your power supply, high frequency and inductive components.

Edited by - Fowkc on 26/05/2006 01:55:50
 

scorpy

New Member
I thank you for your relies and i will post the full programme very shortly and i will also post a description of how the programme should work.
Please note this is my first attempt at programming, i can see you all smiling broadly now. i have a distinct feeling i have fallen into the software structuring trap as i have preogrammed this from my first conditions and basically what i require of the power supply at each step until it is fully running. I am sure you will tell me that i need to structure the programme so there is a core programme and the move off to differnt locations then return if signals are applied to the inputs.
i do not have a spare output at the moment but i believe i can use one output to two functions which occur at the same time.
I hope that i can just paste and copy the programme to this forum otherwise a lot of typing will be required.
I am sure some of you will find the programme of interest and perhaps i will get around to posting some of the circuits on this site that may be of use to you all in future projects
 

scorpy

New Member
let pins=%10000000

symbol ocl = pin0
symbol eng = pin1
symbol auto = pin3
symbol sstart = pin4
symbol ilock = pin5
symbol onoff = pin6
symbol thermal = pin7

symbol maincont = 0
symbol sstartcont = 1
symbol boost = 2
symbol trigger = 3
symbol status = 4
symbol aback = 5
symbol delaystandby = 7





main: pause 500
low delaystandby
pwmout 2,196,48
let b0=0
let b1=0
let b2=0
let b3=0
let b4=0
let b5=0
let b6=0
let b7=0
goto testmodecheck

testmodecheck: if eng=1 then ttripa
if eng=0 and thermal=1 then ttripa
if eng=0 and thermal=0 then testmode

testmode: readadc10 0,w0
if w0 >= 80 and w0 < 514 then testmodeaback
low delaystandby
goto testmode

testmodeaback: high delaystandby
high aback
goto testmodecheck

ttripa: let b0=0
let b1=0
let b2=0
let b3=0
let b4=0
let b5=0
let b6=0
let b7=0
if thermal = 1 then intlocka
low maincont
low sstartcont
low boost
low trigger
low aback
low status
goto ttripa

intlocka: if ilock = 0 then psuready
low status
low maincont
low sstartcont
low boost
low trigger
low aback
goto intlocka



psuready: high status
if onoff = 1 then onoffnormal
if onoff = 0 and auto = 0 then testmodechecka:
goto psuready


testmodechecka: pause 1000
if onoff = 1 then testmodecheck
if eng=0 then testmodea
low delaystandby
high maincont
goto softstartloop

softstartloop: for b0=1 to 250
if sstart = 0 then softstartcheck
if ocl = 0 then ocll
if ilock = 1 then intlocka
if thermal = 0 then ttripa
if onoff= 1 then psuoff
if b0>=250 then softstartloopa
next b0

softstartloopa: for b1=1 to 6
if sstart = 0 then softstartcheck
if ocl = 0 then ocll
if ilock = 1 then intlocka
if thermal = 0 then ttripa
if onoff= 1 then psuoff
if b1>=6 then softstartoff
if b1<6 then softstartloopb


softstartloopb: goto softstartloopc

softstartloopc: for b2=1 to 250
if sstart = 0 then softstartcheck
if b2>=250 then softstartloopd
if ocl = 0 then ocll
if ilock = 1 then intlocka
if thermal = 0 then ttripa
if onoff= 1 then psuoff
next b2

softstartloopd: next b1

softstartoff: low maincont
goto psuoff

testmodea: low delaystandby
high maincont
if thermal = 0 then ttripa
if onoff=1 or ilock=1 then psuoff
if sstart=0 then softstartchecka
if ilock = 0 and onoff = 0 then testmodea

softstartcheck: high sstartcont
for b3=1 to 250
if porta pin2 =1 then mainstart
if b3>=250 then psuoff
next b3

softstartchecka: high sstartcont
goto softstartcheckab

softstartcheckab: pause 500
if thermal = 0 or onoff=1 or ilock=1 then psuoff
if porta pin2 = 0 then psuoff
goto softstartcheckab

onoffnormal: if onoff = 0 then testmodechecka
low maincont
low sstartcont
low boost
low trigger
low aback
if ilock = 1 then intlocka
if thermal = 0 then ttripa
goto onoffnormal

mainstart: readadc10 0,w0
if w0 > 514 then ocll
high boost
high trigger
readadc10 0,w0
if w0 > 514 then ocll
readadc10 0,w0
if w0 > 514 then ocll
if sstart = 0 then psuoff
goto lampcheck

lampcheck: for b4=1 to 250
readadc10 0,w0
if w0 > 514 then ocll
if w0 >= 80 and w0 < 514 then lampon
if porta pin2 =0 then psuoff
if ocl = 0 then ocll
if ilock = 1 then intlocka
if thermal = 0 then ttripa
if onoff= 1 then psuoff
if b4>=250 then lampcheckloopa
next b4

lampcheckloopa: for b5=1 to 18
readadc10 0,w0
if w0 > 514 then ocll
if w0 >= 80 and w0 < 514 then lampon
if porta pin2 =0 then psuoff
if ocl = 0 then ocll
if ilock = 1 then intlocka
if thermal = 0 then ttripa
if onoff= 1 then psuoff
if b5>=18 then psuoff
if b5<18 then lampcheckloopb


lampcheckloopb: for b6=1 to 250
readadc10 0,w0
if w0 > 514 then ocll
if w0 >= 80 and w0 < 514 then lampon
if porta pin2 =0 then psuoff
if b6>=250 then lampcheckloopc
if ocl = 0 then ocll
if ilock = 1 then intlocka
if thermal = 0 then ttripa
if onoff= 1 then psuoff
next b6

lampcheckloopc: next b5

lampon: goto lampona

lampona: for b7=1 to 3
readadc10 0,w0
if w0 > 514 then ocll
high aback
low boost
low trigger
if b7>=3 then lamponb
next b7

lamponb: high delaystandby
goto run


ocll: pwmout 2,0,0
low maincont
low sstartcont
low boost
low trigger
high aback
high status
goto ocll

run: if ocl=0 then ocll
readadc10 0,w0
if w0 > 514 then ocll
if w0<= 60 then psuoff
if ocl=0 then ocll
if w0 > 514 then ocll
if ocl=0 then ocll
if porta pin2 =0 then psuoff
if ocl=0 then ocll
if thermal = 0 then psuoff
if ocl=0 then ocll
if w0 > 514 then ocll
if ocl=0 then ocll
if ilock = 1 then psuoff
if ocl=0 then ocll
if w0 > 514 then ocll
if ocl=0 then ocll
if onoff = 1 then onoffnormal
if ocl=0 then ocll
if w0 > 514 then ocll
if ocl=0 then ocll
if w0 >=60 and w0 < 514 then run

psuoff: low maincont
low sstartcont
low aback
low boost
low trigger
high delaystandby
let b0=0
let b1=0
let b2=0
let b3=0
let b4=0
let b5=0
let b6=0
let b7=0
if onoff = 0 and auto = 0 then psuoff
if thermal = 0 then ttripa
if ilock = 1 then intlocka
if onoff = 0 and auto =1 then psuready
if onoff = 1 then ttripa
goto psuoff
 

scorpy

New Member
Description of input pins..
Pin0 ocl..this is an over current signal from a comparator..0V = over current, this function also pulls the pwmout signaland maincont signal in hardware to 0v..off. This was done to ensure these signals are switched off as quick as possible.
Pin1..Eng..this is an engineering mode function, this programme has 2 eng modes depending on the state of the eng and thermal inputs..normal eng mode, eng=0 thermal=0 is to facilitate in the testing of aback and delaystandby. Intial state is aback o/p =0 and delaystandby o/p =1 If w0 is greater than 80, eg 0.3v then aback pin5 o/p is high and delaystandby is high.
Pin 2 is used for pwmout, this is set to approx 50us and 4us.
Pin3 is auto, if this pin is 0 and on off is 0 with all other conditions correct psu will start without any other prompting or looking for change of state in onoff.
Pin4 Sstart, this is for soft start, this is a signal which is reached at a pre determined hardware value to close the softstart relay and place full rectified mains onto large capacitor. This function is a timed function and has to be achieved in approx 1.75s after the main contactor has closed, this protects all softstart components from damage. This signal is ignored once the event has taken place until main contactor in dropped out and then brought in once more.
Pin5 ilock this is an external demand, 0v= ok
Unit must not turn on or must switch off if this state is high
Pin6 Onoff is an external demand 0v is on, unit must turn on if the correct functions are present and turn off when demanded, a delay can be tolerated to get rid of relay bounce. Please note if psu is not in auto mode this state must go from high to low to operate.
Pin7 Thermal this is an internal signal, high =ok low = overtemperature, this is achieved by 5v via a normally closed thermal switch. Unit must drop out or not switch on if overtemperature is present. Also once the thermal switch recloses the psu must not start up again even in auto mode unless the power is switched off or on/off changes state from low to high then back low again.

There is one further input pin utilising porta pin2, this is used to check the softstart relay has closed and it must drop out if the signal is not recived, this will be set to approx 500ms from the time startcont signal is sent high.

Ouptut Functions

Pins 0 to 5 all close relays via a uln2003an darlington driver with flywheel diode.

Pin0 main cont, this closes the mains contactor if thermal ilock and onoff is correct, or when auto is present with ilock and thermal

pin1 sstartcont, closes the softstart contactor when sstart signal is present within 1.75ms of the maincont signal.

pin2and 3 boost and trigger operate at the same time when the softstart closed signal is achieved. theses signals are present until a 7 second window has alapsed without w0 greater than 80 or if w0 is greater than 80 then these signal are switched low.

Pin4 Status, this signal is present when thermal and ilock is ok

pin5 aback, this signal is present when w0 is greater than 80, basically means current in output is flowing

pin7 delaystandby, this signal is switching a mosfet, it is present for 10ms after aback is achieved, this is to ensure the output device is stable.

If you have any futher questions about the programme or parts of it just ask.
 

hippy

Technical Support
Staff member
Phew, that's quite some program with a lot of complexity. I am not sure how much useful help you will get because it really is ( for me anyway ) just too much to take in and understand without having to study it in a lot of depth.

For a first programming exercise it's an ambitious task to take on, and that lack of experience shows in what you have. That's not a criticism in itself ( we all write bad code when we start, and I probably still do ), but it doesn't help in trying to understand what's going on here, and it makes following the code very hard. An example ...

- softstartloopa: for b1=1 to 6
- if sstart = 0 then softstartcheck
- if ocl = 0 then ocll
- if ilock = 1 then intlocka
- if thermal = 0 then ttripa
- if onoff= 1 then psuoff
- if b1>=6 then softstartoff
- if b1<6 then softstartloopb
-
- softstartloopb: goto softstartloopc
-
- softstartloopc:
- :
- softstartloopd: next b1
-
- softstartoff: low maincont

In this, 'IF b1>=6' will cause a jump out of the FOR loop, while the following 'IF b1<6' will always be true, and goto's a goto to a label which immediately follows, so the whole lot is redundant. The program flow goes all over the place. I won't say it makes one want to give up the will to live, but it does make it really hard to follow what the code is meant to be doing or to determine where it may be going wrong.

It's not particularly clear what is going wrong from your description in your first post. Downloaded programs don't ( under normal circumstances ) simply reset or get lost for no good reason but they can stop working when input signals or conditions are not as expected or combinations exist which haven't been catered for; they are the bane of programming.

The thing you need to do is to determine what does work, what doesn't, and where the program is when it stops doing what's expected, and from that you can hopefully work out how it got there and more importantly why. Often, not an easy task, and in a complex program like this, it could well be anywhere.

Debugging is a mix of science ( logical analysis, prediction etc ) and art ( experience, intuition, inspirational and lateral thinking etc ). It is sometimes easy, sometimes very hard, and especially so within a real-time system where debugging can alter what needs to be observed.

While we have the code and a description of I/O, it is not clear to me how the controller is meant to function, and I'm not familiar with such PSU's, so it's hard to tell if you have a design flaw or simple coding error.

The approach I would take is to trim the code back to its absolute bare minimum, removing test modes etc, and get that to work ( in an environment where faulty code won't destroy the PSU ). I'd do debugging by liberally adding SERTXD's to report where the code was getting to so its flow can be traced and verified as correct. Once that code is working, move on to adding more code ( for interlocks, testing etc ) incrementally, debugging each addition and checking the earlier code operation hasn't been compromised.

With a unique project like this there is the problem that no one else can test your code for you or properly simulate what is meant to be going on. I wouldn't recommend such a project to anyone unfamiliar with programming, but with a solid design to start from, by incrementally coding and verifying operation during development a satisfactory outcome should be achievable. The worst case is where ( because of the real time nature of the system ) complex code has to all work first time; it rarely does and it's a nightmare to deal with. Any silly error or even typo means nothing works, and it's hard to see why or where. The best approach there is to make what needs to work as least complex as possible.

I think that trying to debug the code you have, and determine where it is failing, is likely doomed to failure or will take a long time. The quickest route to a solution is to consider that code 'a prototype', use the knowledge you have gained so far, and re-write the code from new again. Many programmers spend their lives doing that, and it's a legitimate and valid means of development, and how most code is developed in its early stages.

It's possibly not what you wanted to hear, but it's probably the best way to move forward. I've spent hours banging my head on walls and pacing offices trying to understand why things don't work as expected, only to discover that, "Okay, let's start again", takes much less time and delivers a solution which does work.
 

MartinM57

Moderator
I haven't read all of this, but this looks a bit suspicious??

ocll: pwmout 2,0,0
low maincont
low sstartcont
low boost
low trigger
high aback
high status
goto ocll
 
<i>I haven't read all of this, but this looks a bit suspicious??

ocll: pwmout 2,0,0
low maincont
low sstartcont
low boost
low trigger
high aback
high status
goto ocll
</i>

Indeed it is. Setting pins 1,2,4,7 high with a readadc value on 0 higher than 80 (I used 90) causes this part of code to run forever.

Edited by - MichaelCollier on 29/05/2006 21:02:59
 

scorpy

New Member
Thank you for the replies, yes to the last two posts it does look suspect but i have examined this part in detail as it is intended to lock the program in a loop until the power is switch off. If the psu goes over current it must latch, as you can see from the programme the pwmout is removed and all contactor are dropped out making the psu safe and hopefully quick enough to stop any major explosions or any further damage. This loop is not the cause of the problem. i can operate fine until the main contactor comes in, then sometimes the programme will just lock leaving the contactor closed, othertimes it will work once, twice maybe three times before it no longer closes the main contactor. Please note this is when running in the second eng mode. i dont dare run it in full mode until these bugs are ironed out.
i know it looks complicated but all that is happening is switches are closed and opened on the inputs and relays are closed on the outputs, yes i have 2 engineering or test modes and a few timed functions for one function to occur after another. i dont think i am doing anything to complicated, basically most of this can be done with comparators and switches and relays but i do see that with the use of programmable ics it is easy to make changes to these functions for different needs without the hassle of much hardware changes
 

MartinM57

Moderator
...or more simply, once it starts, it never stops as it's an infinite loop (and there's no use of interrupts I can see that will cause any other code to execute)...

 

scorpy

New Member
Yes i have to admit that the softstartloop is silly, i had just tried a few changes before i posted the programme, I had set the b states to 0 at the start and when psuoff was recieved so once it was to start around the loop again it would be counting, i had just forgotten to take that line out and adjust as neccessary.
Please note ocll signal is only recieved when either w is greater than 514 approx 25 amps or the comparator i have on my control pcb detects an ocl and forces an ocl and also forces maincont low and pwmout low via 2 diodes, this works perfectly well. i have even changed the ic socket as it was getting a bit worn with all the programming changes etc and to be honest when i changed the ic skt i did think i had cracked it as the onoff pin was rather suspect.
 

scorpy

New Member
I have found the problem
testmodea: low delaystandby
high maincont
if thermal = 0 then ttripa
if onoff=1 or ilock=1 then psuoff
if sstart=0 then softstartchecka
if ilock = 0 and onoff = 0 then testmodea
if on off changes state between line 4 and 6 above the programme locks, i have split the or and and statements and then looped it back on itself at the end and all is working well aprt from the porta pin2, this just does not work at all, does anyone know how to use port a as an input pin? i could just use the w0 command, as the pin moves from 0v to almost 5v when i have an internal relay closing, just using this pin to say yes this relay has closed.
I have also changed all thermal, ilock and on off to go to psuoff then use that point to go back to the place of failure
 
Top