Not go to subsection in programing

lamxe

Senior Member
Dear all
I try this code on simulate , the code ruining but not reach to main1
So please help me to know why and how fix it
many thank you
I use 2 moment switch at pin 3 and 4 ( picaxe08) and pin1 ,pin2 to H-bridge motor


#Picaxe 08M
do
Symbol PIN_IN = pin3
Symbol counter = b0
main:

if pin3 = 1 then mar
if pin4=1 then low 1 endif

goto main

mar:
if pin3 = 1 then mar
inc b0
if b0= 2 then high 1 low 2 endif; for change direction of motor
if pin4= 1 then low 1
b0=0
endif

goto main

For counter = 1 To 10; It's really over 1000 but i put 10 for quick check on ;simulate
Gosub WaitForPulse
Next
;//////////

;;;;;;;;;;;;;;;;;;; not reach to the code below
main1:

if pin3 = 1 then mar1
if pin4=1 then low 2
endif
goto main

mar1:
if pin3 = 1 then mar1
inc b0
if b0= 2 then high 2 low 1 ; for change direction of motor
endif
if pin4=1 then low 2
endif
b0=0;

goto main1

For counter = 10 to 1 step-1; It's really over 1000 but i put 10 for quick check ; on simulate
Gosub WaitForPulse
Next
let b0=0
loop
'/////////
WaitForPulse:
Do : Loop While PIN_IN = 1
Do : Loop Until PIN_IN = 1
Return
 

lbenson

Senior Member
Since you are running in the simulator, try single-stepping through your code. Then you can see exactly what it is doing.

Hint re
Code:
goto main
   
For counter = 1 To 10;  It's really over 1000 but i put 10 for quick check on                                                  ;simulate
  Gosub WaitForPulse
Next
How can it ever get to the "For" loop?
 

lamxe

Senior Member
Since you are running in the simulator, try single-stepping through your code. Then you can see exactly what it is doing.

Hint re
Code:
goto main
  
For counter = 1 To 10;  It's really over 1000 but i put 10 for quick check on                                                  ;simulate
  Gosub WaitForPulse
Next
How can it ever get to the "For" loop?
Dear Sir lbenson and all
First of all I apologize that I didn't double check before posting the code and my English is poor
My code is bad
I want to have a new code: please see my code posted
, Eg:
Pins 1 and 2 are on off every 3rd of b0
, Eg:
B0 = 1 to 12 and 12 to 1
Pin1 turns on off at 3.6..9..12 comes back
Pin 2 is always low
Pin 2 on off at 12...9 ...3 ..1 and do the same(loop)
Pin 1 is always low
I hope you understand what I mean and help me to have good code Many thank you
HAPPY NEW YEAR
 

lbenson

Senior Member
I'm afraid I don't understand, and don't see how what you are saying relates to the code you posted. Perhaps try again with the code.

Also, in addition to saying what you want the pins to do, can you explain what in the real world you are trying to accomplish with the code?
 

johnlong

Senior Member
Hi Not totally sure but I think you want to flip between the 2 pins high and low have look at this in the simulator and see if you can work around it

Code:
do
for b0= 0 to 12 
    if b0 =3 or b0=6 or b0=9 or b0= 12 then
        gosub mar
else high C.1
    endif
    next b0
loop    
mar:    low C.1
    high C.2
    for b1=0 to 2
        pause 50
next b1
low C.2

    return
you can add your code using
Code:
and a sesonal greetings and a happy new year to yourself
regards john
 

lamxe

Senior Member
I'm afraid I don't understand, and don't see how what you are saying relates to the code you posted. Perhaps try again with the code.

Also, in addition to saying what you want the pins to do, can you explain what in the real world you are trying to accomplish with the code?
Dear Sir Ibenson
This code is for use in solenoid winding machines with 2 motor drivers.
/////////////////////////////////////////////
Motor windings (W) alway run in one direction and the other motor for guide windings (G) must run back and forth,
Each motor have moment swich for make a short high pulse at end revolution each turn
The G motor makes 1 rapid revolution at the end of the 3rd revolution (6 .. 9., 12 ...1 00) of the W motor. (by 1 pulse from motor W for start run and 1 pulse from motor G for stop)
When motor W reaches 100th rotation (1rd layer), motor G reverses and does the same (ratio 3:1) until the desired winding layer ( <> 100 turnsx 10 layers =1500 turns with _30 gauge magnet wire) is reached and auto stops (if have program) or by manually.
//////////////////////////////////////////////////
* Short pulse (at end of 3rd turn) from motor W to pin3( 08x picaxe) for start motor G
*Short pulse from motor G to pin 4 (08x picaxe) for stop motor G
High or low at pin 2 and pin 1 for control forward backwar motor G thourgh H-bridge
If my Explanation is still not clear, please let me know
Thank you a lot
 

lamxe

Senior Member
Hi Not totally sure but I think you want to flip between the 2 pins high and low have look at this in the simulator and see if you can work around it

Code:
do
for b0= 0 to 12
    if b0 =3 or b0=6 or b0=9 or b0= 12 then
        gosub mar
else high C.1
    endif
    next b0
loop  
mar:    low C.1
    high C.2
    for b1=0 to 2
        pause 50
next b1
low C.2

    return
you can add your code using
Code:
and a sesonal greetings and a happy new year to yourself
regards john
Wishing you a merry Christmas and a happy new year
 

lamxe

Senior Member
Hi Not totally sure but I think you want to flip between the 2 pins high and low have look at this in the simulator and see if you can work around it

Code:
do
for b0= 0 to 12
    if b0 =3 or b0=6 or b0=9 or b0= 12 then
        gosub mar
else high C.1
    endif
    next b0
loop   
mar:    low C.1
    high C.2
    for b1=0 to 2
        pause 50
next b1
low C.2

    return
you can add your code using
Code:
and a sesonal greetings and a happy new year to yourself
regards john
Dear Sir johnlon
First of all, thank you for your attention and help,
Sorry, because my English is not well so my question not clear so you misunderstood, please see my answer to Sir Ibenson for understand why and what I need this code.
Wishing you and your family a Merry Christmas and a Happy New Year
 

The bear

Senior Member
@lamxe,
I see you are from Canada, What is your native language, is it French or First Nation?
You are coping well with the English language.
You could use your own language, then we could try a Google translate.
Good luck............ Bear
 

lamxe

Senior Member
@lamxe,
I see you are from Canada, What is your native language, is it French or First Nation?
You are coping well with the English language.
You could use your own language, then we could try a Google translate.
Good luck............ Bear
Dear Sir
Thank you for your interest and suggestions. I will try to try it in the future. I wish you and your family Merry Christmas and Happy New Year.
 

hippy

Technical Support
Staff member
Motor windings (W) alway run in one direction and the other motor for guide windings (G) must run back and forth,
I can understand what you have. It is what we would probably call it a "reel winding machine"; the reel turns and a guide makes sure whatever is wound on the reel is layered left to right, then right to left.

After some number of turns of the reel the guide is moved so it winds in the opposite direction. After a total number of reel turns the reel is full and the reel turning motor is stopped.

The G motor makes 1 rapid revolution at the end of the 3rd revolution (6 .. 9., 12 ...1 00) of the W motor. (by 1 pulse from motor W for start run and 1 pulse from motor G for stop)
When motor W reaches 100th rotation (1rd layer), motor G reverses and does the same (ratio 3:1) until the desired winding layer ( <> 100 turnsx 10 layers =1500 turns with _30 gauge magnet wire) is reached and auto stops (if have program) or by manually.
The key here seems to be counting the winding motor revolutions but I am having a hard time figuring out how the machine actually works, what outputs from the PICAXE need to be and when they would occur.

But the main issue is that the code you have never reaches 'main1'.

That would be correct; because there is no path from 'main' or 'mar' which leads to 'main1'. Which is what I believe lbenson was hinting at in Post #2.

There also appears to be a redundant or erroneous DO-LOOP wrapping the 'main' and other code.

The best way forward would probably be to forget about the existing code, and create a specification which describes exactly how the PICAXE should respond as W or G pulses come in, something like -

"W Motor starts
After every 3 revolutions of W; the G Motor is switched between left and right
After 1500 revolutions of W; W Motor is stopped".

Or whatever it may be. How the G Motor is switched can be separately defined.

From that specification it should be much easier to create code which will do what is required.
 

lamxe

Senior Member
I can understand what you have. It is what we would probably call it a "reel winding machine"; the reel turns and a guide makes sure whatever is wound on the reel is layered left to right, then right to left.

After some number of turns of the reel the guide is moved so it winds in the opposite direction. After a total number of reel turns the reel is full and the reel turning motor is stopped.


The key here seems to be counting the winding motor revolutions but I am having a hard time figuring out how the machine actually works, what outputs from the PICAXE need to be and when they would occur.

But the main issue is that the code you have never reaches 'main1'.

That would be correct; because there is no path from 'main' or 'mar' which leads to 'main1'. Which is what I believe lbenson was hinting at in Post #2.

There also appears to be a redundant or erroneous DO-LOOP wrapping the 'main' and other code.

The best way forward would probably be to forget about the existing code, and create a specification which describes exactly how the PICAXE should respond as W or G pulses come in, something like -

"W Motor starts
After every 3 revolutions of W; the G Motor is switched between left and right
After 1500 revolutions of W; W Motor is stopped".

Or whatever it may be. How the G Motor is switched can be separately defined.

From that specification it should be much easier to create code which will do what is required.
Dear Sir HIPPY
I am very happy and excited because you understood what I wanted. And sorry to everyone member because I write the question not clear so other people who saw my question didn't understand so they couldn't help me. I looked at the manual picaxe many time but because of my low level of education and intelligence, so I don't understand much for set w and B and value 1 to 150 and 151 to 300 and loop (please see my code). I not yet try this code (not complete W and B .if you thing my code is will running can you help me to set B or W and the value to make good code But if is bad please give me other code.Many thank you and HAPPY NEW YEAR
, ####
,,, Dear Sir ...In reel solenoid there are 10 layers of wire and each layer has 150 turns of wire, the first layer wraps from right to left and the second layer wraps from left to right do the same for the next layer until it reaches the l0th layer. when finish 1.500 turns machine stop by manual
Each layer, motor guide wire (G)must be turned on and off once at the end of the 3rd turn of motor wingding(W) and at the end 150 turns of motor W motor (G)must change direction for wrap new layer wrire.
////////////////////////////////////////
*Short hi pulse from moment switch N.O of motor W to pin 3 picaxe for start motor G
*Short hi pulse from moment swith N.O of motor G to pin 4 for turn off motor G
pin 1 and 2 to motor G.
Many thank you
; ///////////////////////////
Code:
#Picaxe 08M or other  picaxe
do
Symbol PIN_IN  = pin3
Symbol counter =   (W.. or B.. ) 
   ####       please help  this section by your  #### 
    #######               code Thank you                                    ####                                                                                                                       if .(   *wb = 1 to 150.*)............ then gosub  forwa                                                                                                                                                                                            if *.( *if Wb = 151 to 300*............. then gosub rev : 151 to  300 ( or 151  to 1) gosub  rev and loop  
;////////////////////////////////////////////////////////////
forwa: 
         ; for 1  to 150 count for windding   each layer ( each                                              ;                                     layer has 150 turns wrap  left to right
Gosub WaitForPulse
inc bx     
 if b x= 3 then high 1  low  2  ; motor run forward  endif
     if pin 4 =1 then low 1 low 2  endif
            let wb x =0
 goto main
rev:
           ; for 151  to 300   (or 151 to 0)count .   wire wrap right
                                           to lelf 
          Gosub WaitForPulse
i             inc w... or  b..
if   wbx = 3 then high 2  low 1  ;   motor G motor run  
          endif                                                                      backward
if pin 4= 1 then low 2  low 1     ;motor G stop
endif
let x = 0  
 goto main
WaitForPulse:
  Do : Loop While PIN_IN = 1
  Do : Loop Until PIN_IN = 1
  Return
 
Top