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.

[SOLVED] ADC problem with pic16f819

Status
Not open for further replies.

farrukhtalib

Junior Member level 3
Joined
Jul 16, 2010
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,487
Hi All
I wrote a code in proton BASIC for ADC but it is not working if some one may help am pasting my code here, and also I am pasting here the Image of proteus design which i made to check the code
https://obrazki.elektroda.pl/2646788600_1442644726.jpg

Code:
Device 16F819
XTAL 4

PORTB_PULLUPS true

LCD_INTERFACE 4
LCD_DTPIN PORTB.4
LCD_RSPIN PORTB.0
LCD_ENPIN PORTB.1
ADIN_RES 10 ' Set the resolution to 10
ADIN_TAD FRC ' Choose the RC osc for ADC samples
ADIN_STIME 100
   ADCON0.3 = 0
   ADCON0.4 = 0
   ADCON0.5 = 0
Output LED
Dim x As Byte
Dim A As Word
Dim V As Word

x= 255
loop:
GoSub GET_VOLT
DelayMS 250
GoSub GET_VOLT1 
GoTo loop

  GET_VOLT:
  A = ADIn 0
        V = (5/1023)*V
        Cls
        Print At 1,1, Dec 4 A 
        Return
        GET_VOLT1:
  A = ADIn 1
        V = (5/1023)*A
        Print At 2,1, DEC3 V
        Return
 
Last edited by a moderator:

Replace

Code:
V = (5/1023)*V

with

Code:
V = (5 * A /1023)

because if A is 30 then 5 / 1023 = 0 as you are not using floating point variable. So 0 * 30 = 0.
 

Zip and post the Proton project files and Proteus file. I will fix it.

- - - Updated - - -

Try this code. I have tested it and it works fine. I think the problem was with LCD Print function usage. Use RA0 for ADC. You forgot to set TRISA to 1.

Code:
'****************************************************************
'*  Name    : adc + lcd.BAS                                      *
'*  Author  : [select VIEW...EDITOR OPTIONS]                    *
'*  Notice  : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
'*          : All Rights Reserved                               *
'*  Date    : 9/19/2015                                         *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
    Device 16F819
Declare Xtal 4

Declare LCD_Interface 4

Declare LCD_DTPin PORTB.4
Declare LCD_RSPin PORTB.0
Declare LCD_ENPin PORTB.1

Declare Adin_Res 10     'Set the resolution to 10
Declare Adin_Tad FRC    'Choose the RC osc for ADC samples
Declare Adin_Stime 100

   ADCON0.3 = 0
   ADCON0.4 = 0
   ADCON0.5 = 0
   ADCON1 = $8E
   TRISA = $C1
   TRISB = $00
   PORTA = $00
   PORTB = $00

Dim A As Float

Main:
    
        A = ADIn 0
        'A = (A * 5.0 / 1024.0)                
        Print At 2,1, Dec2 A, " RAW ADC Value"        
  
GoTo Main
 

Attachments

  • adc + lcd.png
    adc + lcd.png
    25.9 KB · Views: 62

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top