Hi all,
I'm trying to multiplex 3 switches onto a single pin using an ADC on a PIC16F684.
I have the switches arranged on a resistor divider network, providing a unique voltage to the analogue input, for each switch.
As far as I can tell the ADC is configured correctly, and since I have a useful timebase already configured, everything runs inside the ISR.
There are 4 outputs, green LED, amber LED, red LED and white LED (the white LED flashes at 1Hz.)
The scenario I'm trying to achieve is this:-
The coloured LEDs are off, until a switch is made, at which point the corresponding LED is turned on (but not latched) upon release the LED is extinguished, and the white LED continues flashing the whole time, at 1Hz.
The scenario I am realising is this:-
As soon as the programme runs, the green LED is lit, and making button 3 (the corresponding button) does nothing. However making either of the other buttons, extinguishes the green LED and illuminates the correct LED (amber or red.) The white LED continues to flash at 1 HZ.
Since I don't require 10 bit accuracy, and it simplifies the code, I am only using the 8 MSB. Then 0-5V equates to 0-255, full-scale, in the conversion.
This is where I think the error lies:-
I have included a flow-chart depicting my rationale, a schematic for the circuit and the complete code.
Point me in the right direction please!!!!
The .txt file is code. the pdf is a flow-chart of rationale.
I'm trying to multiplex 3 switches onto a single pin using an ADC on a PIC16F684.
I have the switches arranged on a resistor divider network, providing a unique voltage to the analogue input, for each switch.
As far as I can tell the ADC is configured correctly, and since I have a useful timebase already configured, everything runs inside the ISR.
There are 4 outputs, green LED, amber LED, red LED and white LED (the white LED flashes at 1Hz.)
The scenario I'm trying to achieve is this:-
The coloured LEDs are off, until a switch is made, at which point the corresponding LED is turned on (but not latched) upon release the LED is extinguished, and the white LED continues flashing the whole time, at 1Hz.
The scenario I am realising is this:-
As soon as the programme runs, the green LED is lit, and making button 3 (the corresponding button) does nothing. However making either of the other buttons, extinguishes the green LED and illuminates the correct LED (amber or red.) The white LED continues to flash at 1 HZ.
Since I don't require 10 bit accuracy, and it simplifies the code, I am only using the 8 MSB. Then 0-5V equates to 0-255, full-scale, in the conversion.
This is where I think the error lies:-
Rich (BB code):
banksel ADRESH
; movlw .0
; xorwf ADRESH
movlw .1
subwf ADRESH,w
btfss STATUS,C ; see if adresh contains anything
goto INTX ; if not exit,otherwise...
movlw .100
subwf ADRESH,w ; is result >100? (switch3)
btfss STATUS,C
goto GRN
movlw .150
subwf ADRESH,w ; is result >150? (switch1)
btfss STATUS,C
goto RED
bsf PORTC,4 ; else (switch2) turn on amber LED
clrf ADRESH
goto INTX
Point me in the right direction please!!!!
The .txt file is code. the pdf is a flow-chart of rationale.
Attachments
-
7.7 KB Views: 17
-
27.9 KB Views: 38
-
81.7 KB Views: 30