# PIC16F819 - Problem with the A/D module

Status
Not open for further replies.

#### nickagian

##### Member
Hi to all!

I have recently started to experiment a little bit with a PIC16F819 and I have problems with the operation of the A/D module.

I have attached the .asm file that I use.

It seems that after the A/D finishes with the conversion, the ADRESH and ADRESL registers are not updated with the result of the conversion and I dont understand what I am doing wrong.

Actually, as you can see in the code, before the result is ready, I set the contents of both ADRESH and ADRESL to the value of 0x0F. The most logical behavior would be that after the A/D conversion -at least- one of these registers has a different content (I choose to display to PORTB -some LEDs- the ADRESH with the DISPLAY subroutine).

However, the final result is that PORTB has 0x0F!! So it seems that whatever the result of the A/D is, the ADRESH has not changed at all.

P.S. : Note that this test with the registers and the value 0x0F is just to investigate what the problem is. My initial code didn't include this part, but still didn't work properly

Nick

#### Attachments

• 8.2 KB Views: 92

#### Pommie

##### Well-Known Member
I suggest that you tidy up your code. Remove all the parts not needed for the ADC and see if you can get it working. One thing you definitely shouldn't do is write to the ADC result registers after starting a conversion.

Mike.

#### be80be

##### Well-Known Member
All you really need after set your chip up to use ADC is this to out put to led say on PORTB
Code:
MainLoop:
call	adcdelay		  ;delay to charge cap
btfss     ADCON0,GO      ; this bit will change to zero when the conversion is complete
goto      \$-1

movf     ADRESH,w       ; Copy the display to the LEDs
movlw  PORTB             ; send it out to portB`

#### nickagian

##### Member
I guess you both have right. I was trying to implement my final application, but moved away from my short-term goal which is simply to get the A/D working!

And Pommie, I think that what you said about not writing the ADC result register after starting the conversion must be the real reason for this behavior I observe. However, I thought that this wouldn't matter, because the data sheet says that these registers are not updated until the conversion has finished.

Anyway, thanks a lot both of you for your help and for your quick reply. I'll try to simplify things and come back if I still face a problem.

Status
Not open for further replies.