Picaxe 40X2 Programing Very Lost, Very Complex

Discussion in 'Embedded Systems and Microcontrollers' started by Foose, Apr 1, 2013.

  1. Foose

    Thread Starter New Member

    Mar 17, 2013
    4
    0
    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.
     
  2. Foose

    Thread Starter New Member

    Mar 17, 2013
    4
    0
    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.

     
  3. Foose

    Thread Starter New Member

    Mar 17, 2013
    4
    0
    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
     
  4. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,648
    764
    Is that the way you speak? Most of your text is underlined and / or in bold type. Nothing I would bother to read.
     
  5. Foose

    Thread Starter New Member

    Mar 17, 2013
    4
    0
    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.

    Code ( (Unknown Language)):
    1.  
    2. #picaxe 40x2
    3. let dirsC = %11100000
    4. let dirsB = %11100000
    5. let dirsD = %11111000
    6. let adcsetup = %0111111000000
    7. ; Variables
    8. Symbol Height_MotorRight_Pot = b0     ; Potentiomter variable value
    9. Symbol Height_MotorLeft_Pot = b1      ; Potentiomter variable value
    10. Symbol Tilt_MotorRight_Pot = b2    ; Potentiomter variable value
    11. Symbol Tilt_MotorLeft_Pot = b3     ; Potentiomter variable value
    12. Symbol Steering_Pot = b4          ; Potentiomter variable value
    13. Symbol SpeedSignal = b5      ; speedo variable value
    14. Symbol PAUSE_TIME = 1
    15. Main:
    16.    
    17.    Gosub RaiseWing
    18.    Gosub TiltWing
    19.     readADC B.1,b0
    20.     readADC B.2,b1
    21.     readADC B.3,b2
    22.     readADC B.4,b3
    23.     readADC B.0,b4
    24.     readADC A.7,b5
    25.    
    26.    Pause PAUSE_TIME
    27.    
    28.    goto main
    29. RaiseWing: ;label
    30.    If PinD.1 = 1 then ;Boot open signal input (ON)
    31.    goto HeightMotorsDown ;send motor dowm
    32.    Else
    33.    If PinD.1 = 0 and PinD.2 = 1 then ;Boot open signal (OFF) input and Accessory signal input (ON)
    34.    goto HeightMotorsUp ;send motor up
    35.    Elseif PinD.2 = 0 then ;Accessory signal (OFF)
    36.    goto HeightMotorsDown ;send motor dowm
    37.    end if
    38.    end if
    39.    Return ;Return Home
    40.  
    41. TiltWing: ;label
    42.    If PinD.0 = 1 then ;Brake signal input (ON)
    43.    goto TiltMotorsUp ;send motor up
    44.    Else
    45.    if PinD.2 = 0 or PinD.1 = 1 then ;Accessory signal (OFF)
    46.    goto TiltMotorsDown ;send motor dowm
    47.    ElseIf b5 >10 and b4 >20 then ;Speedo signal input (ON) and Steering signal input
    48.    goto TiltPoistionMotorsUp ;send motor up
    49.    end if
    50.    end if
    51.    Return ;Return Home
    52.    
    53. HeightMotorsDown:
    54.  low D.4
    55.     Low D.3
    56.     High C.4
    57.     High D.5
    58.    Return
    59.    
    60. HeightMotorsUp:
    61.  Low C.4
    62.     Low D.5
    63.  High D.3
    64.     High D.4
    65.    Return
    66. TiltMotorsUp:
    67.  low C.6
    68.       Low B.6
    69.  High C.5
    70.     High B.7
    71.    Return
    72.    
    73. TiltPoistionMotorsUp:
    74.       High C.7
    75.       High B.7
    76.       pause 2
    77.       Low C.7
    78.       Low B.7
    79.       pause 2
    80.       low C.6
    81.       Low B.6
    82.  High C.5
    83.     High B.7
    84.    Return
    85.    
    86. TiltMotorsDown:
    87.  Low C.5
    88.     Low B.7
    89.  High C.6
    90.  High B.6
    91.    Return
    92.  
    93.  
     
    Last edited by a moderator: Apr 1, 2013
Loading...