Hey All,
In my project, i need to acquire 4 voltages and they are connected to AN0-3, they convert fine, and I am requesting the conversion by sending the PIC a command from VISUAL BASIC - OVER A WIRELESS LINK which works. So i command the pic to take the reading... when im ready i then command the pic to return the two bytes of data back to the application for processing. This all works EXCEPT the conversion bits is INCORRECT.
I have RIGHT justified the ADC, so the LOW byte should contain 8 bits, and the HIGH byte should contain the last 2 bits.
The problem lies with the LOW BYTE, my value ONLY traverses from 0-127, not 256 as if it was TRUE 8 BIT. The HIGH byte is 0. Look below, it may come clearer.
Analog V / HIGH BYTE / LOW BYTE
0-0.6V / 0 / 0-127
0.6-1.2V / 0 / 63 (For some odd reason it is always 63)
1.2-1.8V / 1 / 0-127
etc etc
5V / 3 / xxxxx cant remember
So the HIGH byte traverses 0/1/2/3 as you'd expect from a 2 bit number, but i am missing the MSB of the LOW BYTE. What is happening? I dont think the VISUAL BASIC is dropping this bit off, but could it be the ADC?
Im missing a chunk of my voltage range
HELPPPPP
Code is BELOW:
In my project, i need to acquire 4 voltages and they are connected to AN0-3, they convert fine, and I am requesting the conversion by sending the PIC a command from VISUAL BASIC - OVER A WIRELESS LINK which works. So i command the pic to take the reading... when im ready i then command the pic to return the two bytes of data back to the application for processing. This all works EXCEPT the conversion bits is INCORRECT.
I have RIGHT justified the ADC, so the LOW byte should contain 8 bits, and the HIGH byte should contain the last 2 bits.
The problem lies with the LOW BYTE, my value ONLY traverses from 0-127, not 256 as if it was TRUE 8 BIT. The HIGH byte is 0. Look below, it may come clearer.
Analog V / HIGH BYTE / LOW BYTE
0-0.6V / 0 / 0-127
0.6-1.2V / 0 / 63 (For some odd reason it is always 63)
1.2-1.8V / 1 / 0-127
etc etc
5V / 3 / xxxxx cant remember
So the HIGH byte traverses 0/1/2/3 as you'd expect from a 2 bit number, but i am missing the MSB of the LOW BYTE. What is happening? I dont think the VISUAL BASIC is dropping this bit off, but could it be the ADC?
Im missing a chunk of my voltage range
HELPPPPP
Code is BELOW:
Code:
ACQ_CH1
CLRF CH1_STAT
;Set ADCON0 to turn on ch1 AND turn on GO/DONE
MOVLW b'10000101'
MOVWF ADCON0
BSF ADCON0, GO_DONE ;initiate conversion - Make Sure
BTFSC ADCON0, GO_DONE
GOTO $-1 ;wait for ADC to finish
BSF STATUS,5 ;;CHANGING STATUS TO BANK 1
MOVF ADRESL, W
BCF STATUS,5 ;;CHANGING STATUS TO BANK 0
MOVWF CH1_STAT
MOVF ADRESH, W
MOVWF CH1_STAT_H
;RESET BYTES TO 5 AND DEFAULT EVERYTHING
MOVLW h'05'
MOVWF BYTE
MOVLW h'01' ;Loads default value for MAGIC to 01
MOVWF MAGIC ;Loads dfault value to MAGIC
GOTO LAST_CHANNEL
ACQ_RESULT_CH1
MOVFW CH1_STAT
MOVWF TXREG
BSF TXSTA, TXEN
MOVFW CH1_STAT
MOVWF TXREG
BSF TXSTA, TXEN
MOVLW h'05'
MOVWF BYTE
MOVLW h'01' ;Loads default value for MAGIC to 01
MOVWF MAGIC ;Loads dfault value to MAGIC
GOTO LAST_CHANNEL
ACQ_RESULT_CH1_2
MOVFW CH1_STAT_H
MOVWF TXREG
BSF TXSTA, TXEN
MOVFW CH1_STAT_H
MOVWF TXREG
BSF TXSTA, TXEN
MOVLW h'05'
MOVWF BYTE
MOVLW h'01' ;Loads default value for MAGIC to 01
MOVWF MAGIC ;Loads dfault value to MAGIC
GOTO LAST_CHANNEL
Last edited: