AD conversion problem for pic16F684


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2015
    Posts
    2

    Default AD conversion problem for pic16F684

    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:
    Code:
    '*  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
    Last edited by Archangel; - 10th May 2015 at 21:33.

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: AD conversion problem for pic16F684

    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.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    May 2015
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: AD conversion problem for pic16F684

    Quote Originally Posted by rsocor01 View Post
    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

Similar Threads

  1. A/D conversion problem on 18F4431
    By ttease in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2007, 23:03
  2. Conversion Problem
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th March 2007, 12:09
  3. Conversion problem
    By eva in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th March 2007, 18:21
  4. A/D conversion problem with pic16F88
    By Tapio Linkosalo in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 18th August 2006, 11:42
  5. Conversion problem
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd March 2004, 18:11

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts