# program get stuck.

#### Satchid

##### Member
Here is my full program, it stops in simulation

' Program to convert analog inputs A1 to A8 to digital values and control a stepper motor
' Written in PICAXE Basic

Hallo, I am looking for a solution, from this line the simulator from the picaxe editor is going stuch on this line: readadc10 5, b4 ' Read analog input A5 and store the digital value in variable b4
What can i do to correct this?
Thanks,
Willy

' Set the PICAXE chip type
#picaxe 28x2

' Define pins for stepper motor control
symbol DIR_pin = 0 ' Pin for direction control
symbol ENABLE_pin = 1 ' Pin for enabling the stepper motor driver

' Main program loop
main:
' Read analog input A1 and convert to digital value
readadc10 1, b0 ' Read analog input A1 and store the digital value in variable b0
' Read analog input A2 and convert to digital value
readadc10 2, b1 ' Read analog input A2 and store the digital value in variable b1
' Read analog input A3 and convert to digital value
readadc10 3, b2 ' Read analog input A3 and store the digital value in variable b2
' Read analog input A4 and convert to digital value
readadc10 4, b3 ' Read analog input A4 and store the digital value in variable b3
' Read analog input A5 and convert to digital value
readadc10 5, b4 ' Read analog input A5 and store the digital value in variable b4
' Read analog input A6 and convert to digital value
readadc10 6, b5 ' Read analog input A6 and store the digital value in variable b5
' Read analog input A7 and convert to digital value
readadc10 7, b6 ' Read analog input A7 and store the digital value in variable b6
' Read analog input A8 and convert to digital value
readadc10 8, b7 ' Read analog input A8 and store the digital value in variable b7

' Set direction based on inputs
if b3 = 1 and b4 = 1 then
' If B3 and B4 are both equal to 1, go straight
' Set direction for straight movement
gosub goStraight
elseif b0 = 1 or b1 = 1 or b2 = 1 or b3 = 1 and b4 = 0 then
' If any of B0 to B3 is 1 and B4 is 0, turn left
' Set direction for left movement
gosub goLeft
elseif b4 = 1 or b5 = 1 or b6 = 1 or b7 = 1 and b3 = 0 then
' If any of B4 to B7 is 1, turn right
' Set direction for right movement
gosub goRight
endif

' Pause for a short time before repeating the loop
pause 100
' Loop back to the beginning of the main program loop
goto main

' Subroutine for going straight
goStraight:
' Disable stepper motor driver (assuming ENABLE_pin low disables the driver)
low ENABLE_pin
' Return from subroutine
return

' Subroutine for turning left
goLeft:
' Set direction for left movement
low DIR_pin
' Enable stepper motor driver
high ENABLE_pin
' Pause to allow stepper motor movement
pause 1000 ' Adjust the pause duration as needed for your motor
' Disable stepper motor driver
low ENABLE_pin
' Return from subroutine
return

' Subroutine for turning right
goRight:
' Set direction for right movement
high DIR_pin
' Enable stepper motor driver
high ENABLE_pin
' Pause to allow stepper motor movement
pause 1000 ' Adjust the pause duration as needed for your motor
' Disable stepper motor driver
low ENABLE_pin
' Return from subroutine
return

#### Attachments

• 3.1 KB Views: 1

#### Technical

##### Technical Support
Staff member
There is no analogue channel 5 on the 28X2.

#### neiltechspec

##### Senior Member
From what I can see, ADC 5, 6 & 7 don't exist.
Also, if using readadc10, values should go into word variables not byte.