PDA

View Full Version : AD conversion problem for pic16F684



loekbeijer
- 10th May 2015, 21:22
Hello, I am starting with a first programm to test a AD-conversion.After the compiling to a HEX-file I do test the programm in REAL PIC SIMULATOR.
But nothing works, I do not see a AD value for the 2 ports !! I think even the hex file is not correct ! please help me, what is wrong ?? Here is my program:


'* Name : ADtest16F684.BAS *
'* Date : 10-5-2015 *
'************************************************* ***************
#config
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
Define OSC 4 ' Match the crystal on the board
OSCCON = %01100101 'select intern clock 4 Mhz
TRISA = %00111111 'all inputs
TRISC = %00000000 'all outputs
Define ADC_bits 8
define ADC_sampleus 100
ADCON1 = %00110000 'interne ad-clock is ook define ad_clock 3
ADCON0 = %11001001 'normal left justified channel AN2= enabled
define ADC_CLOCK 3 'werkt misschien niet

CMCON0 = 7 'comparators off CxIN pins are dig I/O
PORTC.0 = 0 : PORTC.1 = 0:PORTC.2 = 0
PORTC.3 = 0 : PORTC.4 = 0:PORTC.5 = 0
shortad var WORD 'is de ingang AN0
longad var word 'is de ingang AN1
ANSEL = %00000100 'kies RA2 als analoog ingang
pause 10
ADCIN 2,shortAD 'short is 0 - 255 van AD shortAD ingang AN0
pause 100
ADCON0 = %11010001 'normal left justified channel AN4= enabled
ANSEL = %00010000 'kies RA4 als analoog ingang
pause 10
adcin 4,longAD 'long is 0 - 255 van AD longAD ingang AN1
pause 100

'shortAD = 138
PORTC.5 = 1
if shortAD < 45 then PORTC.0 = 1 : goto x7
if shortAD < 90 then PORTC.1 = 1 : goto x7
if shortAD < 135 then PORTC.2 = 1 : goto x7
if shortAD < 180 then PORTC.3 = 1 : goto x7
if shortAD < 215 then PORTC.4 = 1 : goto x7
PORTC.5 = 1
x7:
end

rsocor01
- 10th May 2015, 22:54
It is always a good idea to check that the PIC settings are correct by implementing a blinking LED before you do anything else. Also, in your code I don't see any WHILE....WEND loop to check if the ADCON0.1 has changed it's status. I haven't checked the datasheet for your PIC, so you might want to double check if the ADCON0.1 is the correct bit.

loekbeijer
- 11th May 2015, 13:16
It is always a good idea to check that the PIC settings are correct by implementing a blinking LED before you do anything else. Also, in your code I don't see any WHILE....WEND loop to check if the ADCON0.1 has changed it's status. I haven't checked the datasheet for your PIC, so you might want to double check if the ADCON0.1 is the correct bit.

i am glad i did find the answer !!After very long time of searching!!
The problem is : when i want to convert 8 bits: ADC_bits = 8 then I must declare the var in ADCin as a byte (8 bits) otherwise it do not work
i did find out to use the ADRESH and ADRESL registers
I thank you for for qiuck answer for my problem !!
It is solved and I can go on with my work after several days of searching
have a nice day