Picaxe 40X2 Programing Very Lost, Very Complex

Thread Starter

Foose

Joined Mar 17, 2013
4
Hi there, I’m have a few issues with the programming code for a circuit that I required to build to control 4 Actuator motors. The microcontroller chip is the PICAXE 40X2. Have trouble understanding the ADCsetup and readADC among other things as I very new to this. I have the manual but the info contained with is very hit and miss. The Program I I've started to work on is at the bottom of this it long way from being first and slow going.
Any help persons can offer would be a help.
There are a number of inputs from varies sources and a few are analog from Potentiometers and a Pulse Signal from the car Speedo sensor.

The Program will have to run on 2 or 3 process at once I think to work.

The first is the Power
Depend what Can be done here will give option with what happens with the circuit. What is need is when the Accessory input (D.3) go High the program will start. When the Accessory input (D.3) go Low a delay will activate say 3 minutes and shutdown the program. Also a later option for car show is to allow the car security system output to control the actuator motors though inputs (A.7, D.5) the only 2 pins not being used.

The Second Part (Height – raise the wing)
Turn On Accessory
1. Once the Accessory input (D.3) go High after a 10 sec delaythe Height Motor Up Output(B.0) go High andtheHeight Up Led Output(D.7)go high and run to the set position obtain from theactuator motors (1 & 2) potentiometer inputs (D.4 [ADC25], C.7 [ADC19]) say 250.
2. Once this is reached the Height Motor Up Output(B.0) go Low andtheHeight Up Led Output(D.7) go Low until theAccessory input (D.3) go Low then the Height Motor Down Output(B.1) go High and theHeight Down Led Output(D.6)go high and run to the set position obtain from theactuator motors (1 & 2) potentiometer inputs (D.4 [ADC25], C.7 [ADC19]) = 0.
3. Once this is reached the Height Motor Down Output(B.1) go Low and theHeight Down Led Output(D.6) go Low.
If the Boot is opened
4. As you see in the program flow I’ve put the Boot Open input (D.2) ahead of the accessory input this is just to show that it overrider the input from the accessory input.
5. So if the Boot Open input (D.2) go High then it checks the position of the Actuator Height motors (1 & 2) potentiometer inputs (D.4 [ADC25], C.7 [ADC19]) and if >0 turns the Height Motor Down Output(B.1) go High and theHeight Down Led Output(D.6)go high and run to the set position obtain from theActuator Height motors (1 & 2) potentiometer inputs (D.4 [ADC25], C.7 [ADC19]) = 0.
The Actuator Height motors (1 & 2) potentiometer inputs (D.4 [ADC25], C.7 [ADC19]) must also be used to monitor the position of the both motors and if one stops or the distance between either is more than say 5 then it shut down the motor outputs (B.0, B.1) to low and flash both Height led output (D.6, D.7).
6. Once this is reached the Height Motor Down Output(B.1) go Low and theHeight Down Led Output(D.6) go Low. Manual Operation
1. I have also included a manual operation so when the Manual Height Switch Input (A.0) go Highit turn Manual Height LED Input (B.5) High and if possible lock out the Accessory input (D.3) and activates Height up input (A.2) and Height Down input (A.3) (of course when the Manual Height Switch Input (A.0) is low then Height up input (A.2) and Height Down input (A.3) is locked out.
Up Switch
2. When the Height up input (A.2) go high and the Height Up Led Output(D.7)go high and theHeight Motor Up Output(B.0) go High until Height up input (A.2) go Low and the Height Up Led Output(D.7) go Low andthe Height Motor Up Output(B.0) go Low
Down Switch
3. When the Height Down input (A.3)go high and the Height Up Led Output(D.7)go high and theHeight Motor Up Output(B.0) go High until Height Down input (A.3) go Low and the Height Down Led Output(D.6) go Low andthe Height Motor Down Output(B.1) go Low
If in manual operation when the Accessory input (D.3) go Low will go back into auto operation and follow the shutdown.
 

Attachments

Thread Starter

Foose

Joined Mar 17, 2013
4
Sorry had to put this in 3 posts
The Third Part (Tilt)
Turn On Accessory
The part works much the same the second part
1. The Accessory input (D.3) must be High then when Steering Potentiometer Input (D.0 [ADC20]) reads > 10 (for say) and the Speedo Input (C.4 [ADC16]) read 2v (For Say) then the Tilt Motor Up Output(B.2) go High and the Tilt Up Led output (B.7) go High and will run to the set position of the Tilt Position Input (C.0, C.1, C.2, C.3)which will be High obtain from theActuator Tilt motors (1 & 2) potentiometer inputs (D.5 [ADC17], D.6 [ADC18]) say 191 Tilt Position Input 3 (C.2).
2. Once this reading is reached the Tilt Motor Up Output(B.2) go Low and theTilt Up Led output (B.7) go Low stopping the tilt motors until the Steering Potentiometer Input (D.0 [ADC20]) reads <2( for say) or the Speedo Input (C.4 [ADC16]) read 0v (For Say) then the Tilt Motor Down Output(B.3) go High and the Tilt Down Led output (B.6) go High running to the set position obtain from theActuator Tilt motors (1 & 2) potentiometer inputs (D.5 [ADC25], D.5 [ADC19]) = 0. .
3. Once this is reached the Tilt Motor Down Output(B.3) go Low and theTilt Down Led output (B.6) go Low.
Pin
Position
Pot Required Reading
Input C.0
Position 1
63
Input C.1
Position 2
72
Input C.2
Position 3
191
Input C.3
Position 4
250
Input D.1
Brake
255


Accessory off
4. When the Accessory input (D.3) go Low then the Tilt Motor Down Output (B.3) go High and the Tilt Down Led output (B.6) go High and run to the set position obtain from the Actuator Tilt motors (1 & 2) potentiometer inputs (D.5 [ADC17], C.6 [ADC18]) = 0.
5. Once this is reached the Tilt Motor Down Output (B.1) go Low and the Tilt Down Led output (B.6) go Low.

Brake
6. If the Brake Input (D.1) go High then it overriders Steering Potentiometer Input (D.0 [ADC20]) and the Speedo Input (C.4 [ADC16]) and send the Tilt Motor Up Output (B.2) go High and the Tilt Up Led output (B.7) go High and will run to the set position obtain from the Actuator Tilt motors (1 & 2) potentiometer inputs (D.5 [ADC17], D.6 [ADC18]) = 255.
7. Once this reading is reached the Tilt Motor Up Output (B.2) go Low and the Tilt Up Led output (B.7) go Low stopping the tilt motors until Brake Input (D.1) go Low then Tilt Motor Down Output (B.3) go High and the Tilt Down Led output (B.6) go High running to the set position obtain from the Actuator Tilt motors (1 & 2) potentiometer inputs (D.5 [ADC25], D.5 [ADC19]) = 0
8. Once this is reached the Tilt Motor Down Output (B.3) go Low and the Tilt Down Led output (B.6) go Low.

Manual Operation
1. I have also included a manual operation so when the Manual Tilt Switch Input (A.1) go High it turn Manual Height LED Input (B.4) High and if possible lock out the Accessory input (D.3) and activates Tilt up input (A.5) and Tilt Down input (A.6) (of course when the Manual Height Switch Input (A.1) is low then Tilt up input (A.5) and Tilt Down input (A.6) is locked out.
Up Switch
2. When the Tilt up input (A.5) go high and the Tilt Up Led Output (B.7) go high and the Tilt Motor Up Output (B.2) go High until Height up input (A.5) go Low and the Height Up Led Output (B.7) go Low and the Height Motor Up Output (B.2) go Low
Down Switch
3. When the Tilt Down input (A.6) go high and the Tilt Up Led Output (B7) go high and the Tilt Motor Up Output (B.3) go High until Tilt Down input (A.6) go Low and the Tilt Down Led Output (B.6) go Low and the Tilt Motor Down Output (B.3) go Low
If in manual operation when the Accessory input (D.3) go Low will go back into auto operation and follow the shutdown.

 

Thread Starter

Foose

Joined Mar 17, 2013
4
The Code
The Starting blocks of what I hope will one day work......try to learn....
#picaxe 40x2
let dirsA = %00010000
let dirsB = %11111111
let dirsC = %00000000
let dirsD = %11000000
let adcsetup = %0000000000001100
;***************
;****Symbol*****
;***************
;Symbol definitions
; Pin Inputs
Symbol ManualRaise = PinA.0 ; Run Wing manual raise switch
Symbol MauualTilt = PinA.1 ; Run wing manual tilt switch
Symbol MauualRaise_Up = PinA.2 ; Wing manual raise up switch
Symbol MauualRaise_Down = PinA.3 ; Wing manual raise down switch
Symbol MauualTilt_Up = PinA.5 ; Wing manual tilt up switch
Symbol MauualTilt_Down = PinA.6 ; Wing manual tilt down switch
Symbol TiltPoistion_1 = PinC.0 ; Wing tilt angle position input
Symbol TiltPoistion_2 = PinC.1 ; Wing tilt angle position input
Symbol TiltPoistion_3 = PinC.2 ; Wing tilt angle position input
Symbol TiltPoistion_4 = PinC.3 ; Wing tilt angle position input
Symbol SteeringAngle = PinD.0 ; Potentiometer wiper is connected to steering column
Symbol Brake = PinD.1 ; Contection to the Brake petal switch
Symbol BootOpen = PinD.2 ; Contection to the Boot open switch
Symbol Accessorys = pinD.3 ; Contection to the Accessory on ignation
Symbol Speedo = PinC.4 ; Contection to the speedo sensor wire
Symbol RightRaise_Pot = PinD.4 ; Actuator motor's potentiometer wiper is connected
Symbol LeftRaise_Pot = PinC.7 ; Actuator motor's potentiometer wiper is connected
Symbol RightTilt_Pot = PinC.5 ; Actuator motor's potentiometer wiper is connected
Symbol LeftTilt_Pot= PinC.6 ; Actuator motor's potentiometer wiper is connected
Symbol Raise_Sec= PinD.5 ; Contection to outside seciterity system output activation
Symbol Tilt_Sec= PinD.6 ; Contection to outside seciterity system output activation
; Pin Outputs
Symbol RightRaise = B.0 ;output signal to motor 1
Symbol LefttRaise = B.1 ;output signal to motor 2
Symbol RightTilt = B.2 ;output signal to motor 3
Symbol LeftTilt = B.3 ;output signal to motor 4
; Variables
Symbol Pot_RightRaise = b0 ; Potentiomter variable value
Symbol Pot_LeftRaise = b1 ; Potentiomter variable value
Symbol Pot_RightLeft = b2 ; Potentiomter variable value
Symbol Pot_LeftLest = b3 ; Potentiomter variable value
Symbol Pot_Steering = b4 ; Potentiomter variable value
;Symbol Pot_Steering = b5 ; speedo variable value

Symbol PAUSE_TIME = 1
Do
Gosub RaiseWing
Gosub TiltWing
Pause PAUSE_TIME
Loop

RaiseWing: ;label
If BootOpen = 1 then ;Boot open signal input (ON)
goto HeightMotorsDown ;send motor dowm
Else
If BootOpen = 0 and Accessorys = 1 then ;Boot open signal (OFF) input and Accessory signal input (ON)
goto HeightMotorsUp ;send motor up
Elseif Accessorys = 0 then ;Accessory signal (OFF)
goto HeightMotorsDown ;send motor dowm
end if
end if
Return ;Return Home


TiltWing: ;label
If PinD.1 = 1 then ;Brake signal input (ON)
goto TiltMotorsup ;send motor up
Else
If PinC.4 = 1 and PinD.0 = 1 then ;Speedo signal input (ON) and Steering signal input (ON)
goto TiltPoistionMotorsUp ;send motor up
Elseif PinC.4 = 0 or PinD.0 = 0 then ;Accessory signal (OFF)
goto TiltMotorsDown ;send motor dowm
end if
end if
Return ;Return Home









;ain1: readadc C.5, b0 ; Read the potentiometer value
;debug ; Display the value
;pause 1000 ; Wait a while
;goto main ; Repeat
;****************************************************************
;************************* Raise Wing****************************
;****************************************************************
HeightMotorsUp: ;label
High RightRaise ;Raise motor 1 up poistion
High LefttRaise ;Raise motor 2 up poistion
Return ;Return to RaiseWing
HeightMotorsDown: ;label
Low RightRaise ;Raise motor 1 Down poistion
Low LefttRaise ;Raise motor 2 Down poistion
Return ;Return to RaiseWing
;****************************************************************
;************************* Tilt Wing****************************
;****************************************************************
TiltMotorsUp: ;label
High B.2 ;Raise motor 1 up poistion
High B.3 ;Raise motor 2 up poistion
Return ;Return to RaiseWing

TiltPoistionMotorsUp: ;label
High B.2 ;Raise motor 1 up poistion
High B.3 ;Raise motor 2 up poistion
Return ;Return to RaiseWing

TiltMotorsDown: ;label
Low B.2 ;Raise motor 1 Down poistion
Low B.3 ;Raise motor 2 Down poistion
Return ;Return to RaiseWing
 

Thread Starter

Foose

Joined Mar 17, 2013
4
Sorry about the text is underlined and / or in bold type Just try to mage the Main points and important info stand out.

Anyway I any getting so where:

Some code that is working well so far.

Rich (BB code):
#picaxe 40x2
let dirsC = %11100000
let dirsB = %11100000
let dirsD = %11111000
let adcsetup = %0111111000000
; Variables
Symbol Height_MotorRight_Pot = b0     ; Potentiomter variable value
Symbol Height_MotorLeft_Pot = b1      ; Potentiomter variable value
Symbol Tilt_MotorRight_Pot = b2    ; Potentiomter variable value
Symbol Tilt_MotorLeft_Pot = b3     ; Potentiomter variable value
Symbol Steering_Pot = b4          ; Potentiomter variable value
Symbol SpeedSignal = b5      ; speedo variable value
Symbol PAUSE_TIME = 1
Main:
   
   Gosub RaiseWing
   Gosub TiltWing
    readADC B.1,b0
    readADC B.2,b1
    readADC B.3,b2
    readADC B.4,b3
    readADC B.0,b4
    readADC A.7,b5
    
   Pause PAUSE_TIME
   
   goto main
RaiseWing: ;label
   If PinD.1 = 1 then ;Boot open signal input (ON)
   goto HeightMotorsDown ;send motor dowm
   Else
   If PinD.1 = 0 and PinD.2 = 1 then ;Boot open signal (OFF) input and Accessory signal input (ON)
   goto HeightMotorsUp ;send motor up
   Elseif PinD.2 = 0 then ;Accessory signal (OFF)
   goto HeightMotorsDown ;send motor dowm
   end if
   end if
   Return ;Return Home

TiltWing: ;label
   If PinD.0 = 1 then ;Brake signal input (ON)
   goto TiltMotorsUp ;send motor up
   Else
   if PinD.2 = 0 or PinD.1 = 1 then ;Accessory signal (OFF)
   goto TiltMotorsDown ;send motor dowm
   ElseIf b5 >10 and b4 >20 then ;Speedo signal input (ON) and Steering signal input
   goto TiltPoistionMotorsUp ;send motor up
   end if
   end if
   Return ;Return Home 
   
HeightMotorsDown:
 low D.4
    Low D.3
    High C.4
    High D.5
   Return
   
HeightMotorsUp:
 Low C.4
    Low D.5
 High D.3
    High D.4
   Return
TiltMotorsUp:
 low C.6
      Low B.6
 High C.5
    High B.7
   Return
   
TiltPoistionMotorsUp:
      High C.7
      High B.7
      pause 2
      Low C.7
      Low B.7
      pause 2
      low C.6
      Low B.6
 High C.5
    High B.7
   Return
   
TiltMotorsDown:
 Low C.5
    Low B.7
 High C.6
 High B.6
   Return
 
Last edited by a moderator:
Top