I have made the suggested changes to the program. depending on the position of the potentiometers when the power is applied to the circuit, one of the direction LEDs lights up. If both of the Potentiometers have equal resistances, both of the direction LEDs light up. The power LED never seems to light. I have checked the LEDs to ensure they are working as expected. I have also checked that the resistance of the potentiometers functions as expected.

The reading of the ADC appears to work, though the current position does not seem to update. I believe that either the If statements do not work properly or the main loop is not cycling, or the program is stopping as it is turning the LEDs on.

Is there anything that I am missing?

I have copied the latest form of the code bellow:

DEFINE OSC 8

'GP2 (AN2) IS FOR TARGET POSITION (INPUT)
'GP4 DIRECTION SIGNAL CW (OUTPUT)
'GP5 DIRECTION SIGNAL CCW (OUTPUT)
'GP0 POWER (OUTPUT)
'GP1 (AN1) CURRENT POSITION (INPUT)

'REGISTERS
OPTION_REG = %11000000
INTCON = %11000000
PIE1 = %01000000
PIR1 = %00000000
OSCCON = %01110001
TRISIO = %00000111
ANSEL = %01010110
CCP1CON = %00000000

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

;---------------------------------------------------------------------------
wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
;wsave VAR BYTE $70 SYSTEM ' alternate save location for W
' if using $70, comment wsave1-3

' --- IF any of these three lines cause an error ?? ------------------------
' Comment them out to fix the problem ----
' -- Which variables are needed, depends on the Chip you are using --
wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
'wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
'wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
' --------------------------------------------------------------------------

'OUTPUT PINS
DIRCW VAR GPIO.4
DIRCCW VAR GPIO.5
PWMOUT VAR GPIO.0

'VARIABLES
TARGET VAR WORD bank0
TARGET_L VAR Target.BYTE0
TARGET_H VAR TARGET.byte1
CURRENT VAR WORD bank0
CURRENT_L VAR current.byte0
CURRENT_H VAR current.byte1

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler AD_INT, _CurrentPos, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

'READ TARGET POSITION FROM POT
ADCON0 = %00001011 'TARGET POSITION READ
REPEAT
PAUSE 100
UNTIL ADCON0.1 = 0

TARGET.lowbyte = ADRESL
Target.HighByte = ADRESH

ADCON0 = %00000111 'CURRENT POSITION ADC SETUP

'MAIN PROG
MAIN:
IF CURRENT=TARGET THEN
gosub motorbreak
else
if current > target then
gosub motorcw
else
gosub motorccw
endif
endif
GOTO MAIN

'SUB PROGRAM
MotorBreak:
GPIO = %00110001
return

MotorCW:
GPIO = %00010001
Return

MotorCCW:
GPIO = %00100001
Return

CurrentPos:
current.lowbyte = ADRESL
Current.HighByte = ADRESH
@ INT_RETURN ;RETURN

END


Many thanks