Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A/D with pic 18f4620

Status
Not open for further replies.

LEEN HIKARU

New Member
good need help with the ADC of this pic I'm starting to, I just want a basic conversion without interruption for now, seriously any help would be welcome, thanks for your help
 
Data Sheet
Section 19 tells you about the ADC

Tips and Tricks
has a few things you can do with the ADC

beyond that, can't provide much more help as you haven't described where you might be stuck, what compiler you're using or even what language you're looking to write your code in.
 
Norlin thanks opr answer, I think you forget to place some details ...

work with MPLAB and the programming language is in asm.

XTAL =48MHZ

and I read the datasheet and had already made a code but it is not correct, have you help me a bit ..... thanks in advance.



LIST P=18F4620
#include <P18F4620.INC>

;*****************************
;header goes here
;****************************

cblock 0x80
d1

endc
org 0x00

;delete some ports and placed as an input analog signal RA0

CLRF PORTA
CLRF LATA
CLRF W
movlw 0x01
movwf TRISA
CLRF PORTB
CLRF LATB
CLRF TRISB
CLRF PORTE
CLRF LATE
CLRF TRISE

;in ADCON1 choose as reference voltage VDD and VSS
; and PCFG3 :: PCFG0 <<<<.... 1110 AN0 =RA0 SIGNAL ANALOG
;

ini:
; 0x0E= 0000 1110 .......>>> ADCON1

movlw 0x0E
movwf ADCON1
play: movlw 0x01
movwf ADCON0

; then enable a module A / D ADON = 1

movlw 0xBE
movwf ADCON2
;0XBE=1011 1110 ..... >> ADCON2

bsf ADCON0,2
; right justified ADFM = 1


main:
btfsc ADCON0,2
goto main
; is one call delay_2Tad
; is zero goto play
delay_2Tad:
movlw 0x15
movwf d1
loop1
decfsz d1,1
goto loop1
return
end


this is the program compiles fine on me but it's badly MPLAB,
I hope you help me ..... I have some time with this, perhaps I'm wrong ...

thanks from now

LEEN H.
 
Last edited:
Hi,

Try this code, its taken from my working program.
Have only built it, but it should run ok on hardware or Sims - use a 10k pot / trimmer as your adc input for your basic tests. so you can check the voltage with a dvm and then see if your adc result agrees with the voltage measured.
 

Attachments

  • adc_test.asm
    3.1 KB · Views: 143
WP100've tested and reviewed your code and I have produced nothing, not that I'm making the mistake your code is similar to mine, I think qeu use similar settings ADCON records ...

well I'm using a 10K potentiometer, with its ends connected to 5V and ground and pin an0 average, I've also seen you use the 4MHz internal oscillator so the pic is only made with LEDs and the cable connecting the an0 pin to pin of potentiometer means ......

or did I miss something? please tell me
and also wanted to ask if you've tried? normal work for you? seriously help me a favor ...

Thanks for taking your time ..

lenn.
 
Hi,

Just got your message, will give it a try on the actual hardware - give me a hour ...
 
Hi,

Well have just run the code I sent on the hardware via the Pickit2 Debugger and it works fine.

You can see it working on the screenshot.

In the 'watch' window you can see the adc result from the first adc reading has been transfered to the two user registers, I allowed it to do another reading but after a moved the 10k pot to a new posisition.
ADRESL and H now show the new value.
( with debugger you can stop and start the program as you like so you can see whats happening)



I have added onto the original code so that when it has done the adc routine it flashes a led on and off for 1 second on RB0, then it loops around to the adc again.
If your hardware is set up correctly it should seem to act as a simple led flasher.

I have run this code directly on the chip, not via the debugger, so you should get the same results if your hardware is ok.

Does it do that for you ? - if not send your actual assembler code back with a diagram of how your hardware is connected.
On the 4620 pins 32 and 11 should be VDD + and pins 31 and 12 VSS -.
 

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    88.7 KB · Views: 163
  • adcled.asm
    3.2 KB · Views: 136
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top