Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me fix a code for using pic18f452 as ADC

Status
Not open for further replies.

suwaii

Member level 4
Joined
Jan 21, 2006
Messages
68
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,830
i try to to use PIC18f452 as ADC so when i programme it i get error

verify failed at address 0004h and some times at address 0007h

the problem from code and this is the code to convert analog signal to digital

signal...... can any one help me where is the mistake in the code here:


List p=18f452,f=inhx32
#include <p18f452.inc>



;Start at the reset vector
org 0x000
goto Start
org 0x004
Interrupt
retfie
Start

movlw H'00'
movwf TRISC ;portc [7-0] outputs

movlw B'01000000'
movwf ADCON1

movlw B'11000000' ;Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0]
movwf ADCON0
Main
call ad_portc
goto Main


ad_portc
;wait for acquision time (20uS)
;(non-critical for this test)

bsf ADCON0,GO ;Start A/D conversion
Wait
btfsc ADCON0,GO ;Wait for conversion to complete
goto Wait

movf ADRESH,W ;Write A/D result to PORTC
movwf PORTC ;LEDs
return

end
 

pic18f452 adc code

To me this seems like a programmer issue. You never get errors like that because your code is faulty (you find that out later).
Check the power to the programmer, cabling, etc.
 

c code for adc in pic18f

hi..

You cant have a programming error with faulty coding. After all, it did compile, didnt it?:D

What type of programmer are you using?
Your error message looks like you have a faulty controller. try changing the chip. If it doesnt work, its definitely with the progammer. Try running the programmer in "slow mode" to check for timing issues.(If your programmer supports that)

Added after 1 minutes:

hi..

You cant have a programming error with faulty coding. After all, it did compile, didnt it?:D

What type of programmer are you using?
Your error message looks like you have a faulty controller. try changing the chip. If it doesnt work, its definitely with the progammer. Try running the programmer in "slow mode" to check for timing issues.(If your programmer supports that)
 

pic18f adc slow

the programmer is IC_PROG and the problem come from code not from circuit and not from programmer becasue at the same time i get error verify failed at address 0004h i try another simple code which make portc value=CF. i get secussful in that code but when i use the ADC code i get message verify faield at address 0004h....help me plzzzz
 

pic18f452 adc circuit code

I will repeat, the problem is with the programmer, unless your device is defective.

The fact that you do not get the verify error with the simpler code is perhaps because you write different data at address 0x0004 and it may just get "correct" data back. I mean, if the data written to 0x0004 is say 0xFFF, because the code does not use it, then you may read back 0xFFF and you think it's correct.
But when you write anything else and you still get 0xFFF back because the location did not actually get programmed properly, then it becomes clear you have an error and you get the error message.
To test, keep the same interrupt routine in place, even if you do not use it with the simple program. If you get the error, you will see what I mean.
 

program verify error at adress 0x0004

I suggest u change the controller and used a new controller instead.
 

pic18f analog to digital

the programmer is IC_PROG and the problem come from code not from circuit and not from programmer becasue at the same time i get error verify failed at address 0004h i try another simple code which make portc value=CF. i get secussful in that code but when i use the ADC code i get message verify faield at address 0004h....help me plzzzz
 

adc pic18f452

Did you try what I suggested?
Keep the interrupt routine in place, but replace the rest of the code with your simple program that only writes CF to port C.
I am almost certain you will get the same verify error. That should prove that the problem is with the programmer, unless you have a bad PIC, that just won't program location 0x0004.
 

verify failed at address 0004h

suwaii said:
the problem come from code not from circuit and not from programmer


Incorrect. You have made a bad conclusion that just because it checks ok with your old code, that you are programming your old code again. You likely aren't programming anything now, but when you TRY to program the old code again, it simply matches what's already in the chip.

Listen to people when they say the right answers.. Verify errors are with programming the chip, they have nothing to do with your code, just because you aren't getting the errors sometimes does NOT mean that your programmer is ok.


Use another chip, and try and program your 'good' code into it, so you see your GOOD code not work too. You just happen to already have it in that chip, so it verifies ok even though it didn't program..

And use your foot to step on your other foot really hard next time if you say you know what the problem is when you don't really. Nothing like some pain and fear of more pain to stop bad habits, you remember more if it hurts.
 

analog to digital converter pic18f452 program

i change the code and i get successful programming by IC- prog but when i t try

to convert analog to digital i do not get any thing in the PORTC i use RC oscillator

and pin#2(AN0) is analog input and Vref+,Vref- are the same Vdd&Vss...
this is the code:

List p=18f452,f=inhx32
#include <p18f452.inc>
org 0x0000
clrf PORTC
movlw 0x00
movwf TRISC

movlw B'11000000'
movwf ADCON1

movlw B'11000001'
movwf ADCON0

again:

bsf ADCON0, GO

Wait:
btfsc ADCON0,GO ;Wait for conversion to complete
goto Wait

movf ADRESH,W ;Write A/D result to PORTC
movwf PORTC ;LEDs

goto again

end

why i do not get the result of converting analog to digital in the portC
and how we can get it
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top