Motor switching program gets lost

stevecoulson

New Member
Hi, I have been struggling with this for some days now so, with tears of frustration rolling down my cheeks I turn to the Picaxe forum.
I am trying to control a device that displays model figures one at a time in sequence. It is a motor switching program. A large table rotates and pause 8 times allowing one, and then another and another, of the 8 tables positioned around it's periphery to be displayed. These smaller tables also rotate, clockwise and anticlockwise. The large table is called a Tumbrel (made up name) and rotates clockwise only. It is controlled by a Picaxe 28X2. The smaller ones are simply called Tables and each is controlled by a 14M2.
One of the Tables operates only when the Tumbrel is inactive and it rotates back and forth switched by a PIR sensor. This is called the ComeOn table. As soon as the Go button is pressed the ComeOn goes into ParkAnd Wait mode.
I have written a program to control all this and it works fine but only once. After the Tumbrel has gone through it's sequence (indexing round 8 times and coming to a halt with the ComeOn back at the front) everything goes dead. The Go button does nothing and the ComeOn no longer responds to the PIR sensor. If I switch off the power and then on again all is well but only for one more cycle. It seems that the program has got stuck. It does not go to PreMain as I tell it to in:-
If eCount = 8 then Goto PreMain
Can anyone tell me what I have done wrong?

Here is the program:-
Code:
    #picaxe 28X2
    #no_data
    #no_table
    #terminal off
    
    '======Variables======
    
       symbol  ButPush =  pinA.1  ' leg 3
       symbol  SenA = pinA.0     'leg 2
       symbol  TableSig = pinA.2  ' leg 4
       symbol  eCount = b0 ' variable
       symbol  Carousel = b1' variable
      
       
  '=============Initialisation==============
  
          let dirsb = %11111111 ' set port B as outputs
   
  '============= Program=================
  
                PreMain:
                       eCount = 0
                       Carousel = %00000010
                       High C.5  'this tells the ComeOn to go into action
                       Pause 300 
                       Low C.5    
                       Goto  WaitForPush
                                        
                Main:
                    High C.1
                    Gosub TableStart
                    Pause 1500 ' allows the magnetic sensor to escape the magnet
                    Gosub WaitForSensorA 'wait for magnetic sensor on Tumbrel
                    Low C.1
                    Gosub WaitForTable 'wait for the active Table to signal.	
                    eCount=eCount+1
                    If eCount=8 then goto PreMain
                    Carousel = Carousel*2
                    Goto  Main
                    
'=============Sub-Routines=============

       WaitForPush:
             If ButPush = 0 then WaitForPush'active High
             High C.4       'tells the ComeOn to go into park mode
             Pause 200
             Low C.4
             Goto Main
        
             
       WaitForSensorA:
             If SenA = 1 then WaitForSensorA 'active Low
             Return
   
             
       WaitForTable:
             If TableSig = 0 then WaitForTable 'this line is active High.
             Return
             
             
       TableStart:
             Let OutpinsB = Carousel
             Pause 300
             Let OutpinsB = $00
             Return
 
Last edited by a moderator:

hippy

Technical Support
Staff member
I haven't studied what you program does but one thing you can do is use DEBUG or SERTXD commands to give reports on where program execution is and what values variables contain.

You should also be able to simulate the program and see where flow goes and how variables change.

By analysing how it eventually fails to behave as intended, you should be able to determine what the cause of its not working is, then work back to determine why that is.
 

PhilHornby

Senior Member
You definitely need some debugging aids, to figure out whereabouts in the code the Picaxe is 'stuck' - you could consider adding some LEDs, in addition to the DEBUG/SERTXDs.

My guess would be that the program is in one of the loops at the beginning of "WaitForSensorA" or "WaitForTable".

Perhaps the signal's been and gone before the Picaxe spotted it?. Perhaps it never happens at all?

You could alter the loops so that there is an escape route after a certain period of time ... but you'd probably need to find the root cause, in order for the system as a whole to function the way you want.
 

AllyCat

Senior Member
Hi,

As previously said, take out the #TERMINAL OFF and put in some SERTXD("Waiting for...") and SERTXD("..Done") commands at the start and end of the subroutines.

But, your main loop ends with a GOTO Main, which I suspect should be GOTO PreMain (or somewhere within it).

Cheers, Alan.
 

Buzby

Senior Member
I just ran it in the simulator.

Pressed a.0, a.1, a.2 enough times, and the program returned to 'WaitForPush', so it's not locking up, it must be being held by something external.

How does the 'moving bit' on portB work the table ?. It resets to zero on count 7, but your code seems to be looking for 8.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
How does the 'moving bit' on portB work the table ?. It resets to zero on count 7, but your code seems to be looking for 8.
Good point. I had a gut feeling it might be setting 'carousel' to zero but then saw the 'If ... Goto PreMain' and thought that had been catered for, but hadn't spotted the eCount of 8 may be wrong.

If it is just 'carousel' going to zero, then more button pushes may eventually kick it back to 'PreMain' and it might start working again. Or the code might jam somewhere else, waiting for something to move which won't be moving..
 

stevecoulson

New Member
Reply to suggestions

Thanks for these ideas. I posted a reply this morning but nothing is now showing on the thread so I had better do it again.
I tried Sertxd a couple of days ago but all I got in the terminal window was gobbledegook so I gave up.
I have leds on all the relevent pins which was helpful in telling me that the program was not getting as far as PreMain.
Thanks Buzby and Hippy for the idea that I have over-called the number on eCount. I have replaced the "if eCount = 8 then PreMain" with 7 and it works!!!
The Tumbrel is one eighth of a turn out of sync but I have put a few extra lines in the PreMain program and it all works as intended.
I still don't see quite where the program got hung up and it would have been nice to get the SerTxd to work but a great result never the less.
Thanks again, Steve C ( Hoping my reply gets sent this time)
 

Buzby

Senior Member
Hi Steve,

Glad to know it's working now.

it sounds like an interesting project, would you care to share a video ?.

Cheers,

Buzby
 

stevecoulson

New Member
Wrong baud rate Hippy? I will try that later. As to putting a video on the Forum Buzby, I didn't know you could do that. I will look into it.
The project isn't finished yet. All that can be seen are rotating tables on a larger rotating table. On completion each of the smaller tables will carry a depiction of the Seven Deadly Sins. These stand about 7 inches high and some of them move. Originally they were all going to move but trying to get a vicar's hands to move (say) on a moving table that is itself being rotated on a larger table proved to be a bit difficult but I managed it a couple of times using battery packs. Slip rings would be the proper way to do it but maybe later.
Doing the models / depictions / tableau / figures; whatever they are called is what I consider my strength. I had lots of ideas for Lust but not so many for Pride. These models are now nearly done and ready to be mounted on the tables. Doing the electronics and the software I find fascinating but you need a really sharp brain to be good at it. A retentive brain too. Mine ain't retentive. What was I saying....? Oh yes...!
I promise to look into doing a video when the machine is nearer completion. Thanks again, Steve C
 
Top