Hi, I'm new to the program sense and I like for a lot of help with my what I think is become a very complex circuit and program for the Picaxe chip. I selected the 40X2 as it has the amount of Input and output had I could select for the circuit I required. Now I included pictures one of the circuit (not yet finished) and the flow diagram of what the program will need to look like when finished I think. I've started it and am as far a I can go with my limited knowledge and looking for help to try and finish it. I will add more info if people are interest in it as I said it get quite complex and the info file is quite long. I have try to do this in modules and put it together.
Any help that can be offered would be greatly welcomed.
The Code so far.
#picaxe 40x2 ;IC Chipset
let dirsC = %11110000 ;Selected Input Output Port C
let dirsB = %11100000 ;Selected Input Output Port B
let dirsD = %11111000 ;Selected Input Output Port D
let adcsetup = %0111111000000 ;Selected Anolog Input Port A & B
;Initialising
init: ;Program Initiation Label
; Input Pin Names Symbol Definitions
Symbol MOR = PinA.0 ;Manual operation of wings height control
Symbol MOT = PinA.1 ;Manual operation of wings tilt control
Symbol RUP = PinA.2 ;Manual operation raise wing UP
Symbol RDOWN = PinA.3 ;Manual operation raise wing DOWN
Symbol TUP = PinA.5 ;Manual operation tilt wing UP
Symbol TDOWN = PinA.6 ;Manual operation tilt wing DOWN
Symbol TP1 = PinC.0 ;Selectable wings tilt Position 1
Symbol TP2 = PinC.1 ;Selectable wings tilt Position 2
Symbol TP3 = PinC.2 ;Selectable wings tilt Position 3
Symbol TP4 = PinC.3 ;Selectable wings tilt Position 4
Symbol BRK = PinD.0 ;Brake active signal input
Symbol BTO = PinD.1 ;Bootlid open signal input
Symbol ACC = PinD.2 ;Accessory ON active signal input
; ADC Input Pin Names Symbol Definitions
Symbol SPD = PinA.7 ;Speedo input signal (4 pulse per sec)
Symbol STR = PinB.0 ;Steering input potentiometer signal
Symbol M1P = PinB.1 ;Motor 1 potentiomter (height position sensor)
Symbol M2P = PinB.2 ;Motor 2 potentiomter (height position sensor)
Symbol M3P = PinB.3 ;Motor 3 potentiomter (tilt position sensor)
Symbol M4P = PinB.4 ;Motor 4 potentiomter (tilt position sensor)
; Output Pin Names Symbol Definitions
Symbol MHU = D.3 ;Motor 1-2 height UP
Symbol MHD = C.4 ;Motor 1-2 height DOWN
Symbol MTU = C.5 ;Motor 3-4 tilt UP
Symbol MTD = C.6 ;Motor 3-4 tilt DOWN
Symbol MHL = C.7 ;LED manual height operation
Symbol MHLU = D.4 ;LED manual height UP
Symbol MHLD = D.5 ;LED manual height DOWN
Symbol MTL = B.5 ;LED manual tilt operation
Symbol MTLU = B.6 ;LED manual tilt UP
Symbol MTLD = B.7 ;LED manual tilt DOWN
; Variables Symbol Definitions
Symbol Delay = 15 ;Delay start of program
Symbol Pausetime = 1 ;Pause the program
Symbol Offset = 5 ;Offset value for Potentiometer
Symbol P1 = 65 ;Poistion 1 tilt value
Symbol P2 = 130 ;Poistion 2 tilt value
Symbol P3 = 190 ;Poistion 3 tilt value
Symbol P4 = 250 ;Poistion 4 tilt value
Do
Gosub Startup
Gosub Main
If MOR = 1 Then ;Manual Operation Height Wing Active
If MOT = 1 Then ;Manual Operation Tilt Wing Active
Gosub program1 ;Go to Program 1
Gosub program2 ;Go to Program 2
Loop
;Start Programs
Startup:
If ACC = 1 Then ;Accessory is active
Pause Delay ;Pause before running main programs
;Elseif ACC = 0 Then
;Wait 3
Endif
Main:
Return
Program1: ;Height Program Label
ReadADC B.1,b0 ;Motor 1 Pot Anolag Input Pin to ADC Channel b0
ReadADC B.2,b1 ;Motor 2 Pot Anolag Input Pin to ADC Channel b1
If BTO = 1 Then ;Bootlid Open signal is ON
Goto MotorsH_DOWN ;Go to Sub,turn motors 1 - 2 OFF
Else
If ACC = 1 and BTO = 0 Then ;Accessory is ON, Boot lid is OFF
Goto MotorsH_UP ;Go to Sub,turn motors 1 - 2 ON
Elseif ACC = 0 then ;Accessory is OFF
Goto MotorsH_DOWN ;Go to Sub,turn motors 1 - 2 OFF
Endif
Endif
Return
End
Program2: `;Tilt Program Label
;Pulsin A.7,1,b2 ;Speedo SignalInput Pin to ADC Channel b3
ReadADC A.7,b2 ;Speedo SignalInput Pin to ADC Channel b3
ReadADC B.0,b3 ;Steering Potetiometer Input Pin to ADC Channel b4
ReadADC B.3,b4 ;Motor 1 Pot Anolag Input Pin to ADC Channel b0
ReadADC B.4,b5 ;Motor 2 Pot Anolag Input Pin to ADC Channel b1
Let b8=b4+b5/2 ;Motor 3 - 4 pot values into one figure into b7
If BTO = 1 Then ;Bootlid Open signal is ON
Goto MotorsT_DOWN: ;Go to Sub,turn motors 1 - 2 OFF
Else
If BRK = 1 Then
High MTU
Goto Brake
Else
If ACC = 1 and BTO = 0 Then ;Accessory is ON, Boot lid is OFF
Goto MotorsT_UP ;Go to Sub,turn motors 1 - 2 ON
Else
If ACC = 0 then ;Accessory is OFF
Goto MotorsT_DOWN ;Go to Sub,turn motors 1 - 2 OFF
Endif
Endif
Endif
Return
End
;Sub Procedures Programs
MotorsH_UP:
Let b7=b0+b1/2 ;Motor 1 - 2 pot values into one figure into b2
High MHU ;Turn motor output high (ON)
If b7 >= 250 Then ;b2 value is equal 0
Low MHU ;Turn motor output low (OFF)
Endif
Return
MotorsH_DOWN:
Let b7=b0+b1/2 ;Motor 1 - 2 pot values into one figure into b2
High MHD ;Turn motor output high (ON)
If b7 = 0 Then ;b2 value is equal 0
Low MHD ;Turn motor output low (OFF)
Endif
Return
MotorsT_UP:
;Let b8=b4+b5/2 ;Motor 3 - 4 pot values into one figure into b7
If b2< 2 or b3 < 20 Then ;Speedo = 2v and Steering at 1/4 turn
Goto MotorsT_DOWN
Else
If b2> 2 and b3 > 20 Then ;Speedo = 2v and Steering at 1/4 turn
Goto Position
Endif
Endif
Return
MotorsT_DOWN:
;Let b8=b4+b5/2 ;motor 1 - 2 pot values into one figure into b7
High MTD ;Turn motor output high (ON)
If b8 = 0 Then ;b2 value is equal 0
Low MTD ;Turn motor output low (OFF)
Endif
Return
Position:
High MTU ;Turn motor tilt Up output high (ON)
If TP1 = 1 Then ;If position 1 input High
Goto Position1 ;Go top position 1 sub
Else
If TP2 = 1 Then ;If position 2 input High
Goto Position2 ;Go top position 2 sub
Else
If TP3 = 1 Then ;If position 3 input High
Goto Position3 ;Go top position 3 sub
Else
If TP4 = 1 Then ;If position 4 input High
Goto Position4 ;Go top position 4 sub
Endif
Endif
Endif
Endif
Return
Position1:
If b8 = P1 then ;Test if b8 equals P1 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Position2:
If b8 = P2 then ;Test if b8 equals P2 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Position3:
If b8 = P3 then ;Test if b8 equals P3 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Position4:
If b8 = P4 then ;Test if b8 equals P4 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Brake:
If b8 = P4 then ;Test if b8 equals P4 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
View attachment 13899View attachment 13900
Any help that can be offered would be greatly welcomed.
The Code so far.
#picaxe 40x2 ;IC Chipset
let dirsC = %11110000 ;Selected Input Output Port C
let dirsB = %11100000 ;Selected Input Output Port B
let dirsD = %11111000 ;Selected Input Output Port D
let adcsetup = %0111111000000 ;Selected Anolog Input Port A & B
;Initialising
init: ;Program Initiation Label
; Input Pin Names Symbol Definitions
Symbol MOR = PinA.0 ;Manual operation of wings height control
Symbol MOT = PinA.1 ;Manual operation of wings tilt control
Symbol RUP = PinA.2 ;Manual operation raise wing UP
Symbol RDOWN = PinA.3 ;Manual operation raise wing DOWN
Symbol TUP = PinA.5 ;Manual operation tilt wing UP
Symbol TDOWN = PinA.6 ;Manual operation tilt wing DOWN
Symbol TP1 = PinC.0 ;Selectable wings tilt Position 1
Symbol TP2 = PinC.1 ;Selectable wings tilt Position 2
Symbol TP3 = PinC.2 ;Selectable wings tilt Position 3
Symbol TP4 = PinC.3 ;Selectable wings tilt Position 4
Symbol BRK = PinD.0 ;Brake active signal input
Symbol BTO = PinD.1 ;Bootlid open signal input
Symbol ACC = PinD.2 ;Accessory ON active signal input
; ADC Input Pin Names Symbol Definitions
Symbol SPD = PinA.7 ;Speedo input signal (4 pulse per sec)
Symbol STR = PinB.0 ;Steering input potentiometer signal
Symbol M1P = PinB.1 ;Motor 1 potentiomter (height position sensor)
Symbol M2P = PinB.2 ;Motor 2 potentiomter (height position sensor)
Symbol M3P = PinB.3 ;Motor 3 potentiomter (tilt position sensor)
Symbol M4P = PinB.4 ;Motor 4 potentiomter (tilt position sensor)
; Output Pin Names Symbol Definitions
Symbol MHU = D.3 ;Motor 1-2 height UP
Symbol MHD = C.4 ;Motor 1-2 height DOWN
Symbol MTU = C.5 ;Motor 3-4 tilt UP
Symbol MTD = C.6 ;Motor 3-4 tilt DOWN
Symbol MHL = C.7 ;LED manual height operation
Symbol MHLU = D.4 ;LED manual height UP
Symbol MHLD = D.5 ;LED manual height DOWN
Symbol MTL = B.5 ;LED manual tilt operation
Symbol MTLU = B.6 ;LED manual tilt UP
Symbol MTLD = B.7 ;LED manual tilt DOWN
; Variables Symbol Definitions
Symbol Delay = 15 ;Delay start of program
Symbol Pausetime = 1 ;Pause the program
Symbol Offset = 5 ;Offset value for Potentiometer
Symbol P1 = 65 ;Poistion 1 tilt value
Symbol P2 = 130 ;Poistion 2 tilt value
Symbol P3 = 190 ;Poistion 3 tilt value
Symbol P4 = 250 ;Poistion 4 tilt value
Do
Gosub Startup
Gosub Main
If MOR = 1 Then ;Manual Operation Height Wing Active
If MOT = 1 Then ;Manual Operation Tilt Wing Active
Gosub program1 ;Go to Program 1
Gosub program2 ;Go to Program 2
Loop
;Start Programs
Startup:
If ACC = 1 Then ;Accessory is active
Pause Delay ;Pause before running main programs
;Elseif ACC = 0 Then
;Wait 3
Endif
Main:
Return
Program1: ;Height Program Label
ReadADC B.1,b0 ;Motor 1 Pot Anolag Input Pin to ADC Channel b0
ReadADC B.2,b1 ;Motor 2 Pot Anolag Input Pin to ADC Channel b1
If BTO = 1 Then ;Bootlid Open signal is ON
Goto MotorsH_DOWN ;Go to Sub,turn motors 1 - 2 OFF
Else
If ACC = 1 and BTO = 0 Then ;Accessory is ON, Boot lid is OFF
Goto MotorsH_UP ;Go to Sub,turn motors 1 - 2 ON
Elseif ACC = 0 then ;Accessory is OFF
Goto MotorsH_DOWN ;Go to Sub,turn motors 1 - 2 OFF
Endif
Endif
Return
End
Program2: `;Tilt Program Label
;Pulsin A.7,1,b2 ;Speedo SignalInput Pin to ADC Channel b3
ReadADC A.7,b2 ;Speedo SignalInput Pin to ADC Channel b3
ReadADC B.0,b3 ;Steering Potetiometer Input Pin to ADC Channel b4
ReadADC B.3,b4 ;Motor 1 Pot Anolag Input Pin to ADC Channel b0
ReadADC B.4,b5 ;Motor 2 Pot Anolag Input Pin to ADC Channel b1
Let b8=b4+b5/2 ;Motor 3 - 4 pot values into one figure into b7
If BTO = 1 Then ;Bootlid Open signal is ON
Goto MotorsT_DOWN: ;Go to Sub,turn motors 1 - 2 OFF
Else
If BRK = 1 Then
High MTU
Goto Brake
Else
If ACC = 1 and BTO = 0 Then ;Accessory is ON, Boot lid is OFF
Goto MotorsT_UP ;Go to Sub,turn motors 1 - 2 ON
Else
If ACC = 0 then ;Accessory is OFF
Goto MotorsT_DOWN ;Go to Sub,turn motors 1 - 2 OFF
Endif
Endif
Endif
Return
End
;Sub Procedures Programs
MotorsH_UP:
Let b7=b0+b1/2 ;Motor 1 - 2 pot values into one figure into b2
High MHU ;Turn motor output high (ON)
If b7 >= 250 Then ;b2 value is equal 0
Low MHU ;Turn motor output low (OFF)
Endif
Return
MotorsH_DOWN:
Let b7=b0+b1/2 ;Motor 1 - 2 pot values into one figure into b2
High MHD ;Turn motor output high (ON)
If b7 = 0 Then ;b2 value is equal 0
Low MHD ;Turn motor output low (OFF)
Endif
Return
MotorsT_UP:
;Let b8=b4+b5/2 ;Motor 3 - 4 pot values into one figure into b7
If b2< 2 or b3 < 20 Then ;Speedo = 2v and Steering at 1/4 turn
Goto MotorsT_DOWN
Else
If b2> 2 and b3 > 20 Then ;Speedo = 2v and Steering at 1/4 turn
Goto Position
Endif
Endif
Return
MotorsT_DOWN:
;Let b8=b4+b5/2 ;motor 1 - 2 pot values into one figure into b7
High MTD ;Turn motor output high (ON)
If b8 = 0 Then ;b2 value is equal 0
Low MTD ;Turn motor output low (OFF)
Endif
Return
Position:
High MTU ;Turn motor tilt Up output high (ON)
If TP1 = 1 Then ;If position 1 input High
Goto Position1 ;Go top position 1 sub
Else
If TP2 = 1 Then ;If position 2 input High
Goto Position2 ;Go top position 2 sub
Else
If TP3 = 1 Then ;If position 3 input High
Goto Position3 ;Go top position 3 sub
Else
If TP4 = 1 Then ;If position 4 input High
Goto Position4 ;Go top position 4 sub
Endif
Endif
Endif
Endif
Return
Position1:
If b8 = P1 then ;Test if b8 equals P1 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Position2:
If b8 = P2 then ;Test if b8 equals P2 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Position3:
If b8 = P3 then ;Test if b8 equals P3 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Position4:
If b8 = P4 then ;Test if b8 equals P4 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
Brake:
If b8 = P4 then ;Test if b8 equals P4 set value if so then
Low MTU ;Turns motor tilt Up output Low
High MTD ;Turns motor tilt Down output high
Endif
Return
View attachment 13899View attachment 13900