ADC problem


Closed Thread
Results 1 to 4 of 4

Thread: ADC problem

  1. #1
    NacNud's Avatar
    NacNud Guest

    Arrow ADC problem

    Hello,

    First I want to say that this is a nice forum finding solutions for PBP.

    Here is my queston about an Analog to digital conversion.
    I want to put an conversion in the variable word_temp_int, but this ain't seem to work. Every result of the AD conversion is 0.
    Using a PIC16F870.

    This code is in my interrupt routine, the routine is 500 ms. The varaiable word_wachttijd_aantal is decreased with every interrupt.

    Code:
    if (word_wachttijd_aantal == 12) and (byte_status == 1) then
       adcon0.0 = 1                            ' AD converter on
    endif
    if (word_wachttijd_aantal == 11) and (byte_status == 1) then
       word_pot_adc = 0                     ' reset value potmeter
       adcon0.2 = 1                         ' start AD conversion
    endif                
    if (word_wachttijd_aantal < 11) and (byte_status == 1) then
       if adcon0.2 == 0 then                   ' test AD conversion ready
          word_temp_int.highbyte = ADRESH      ' store AD value
          word_temp_int.lowbyte = ADRESL       ' store AD value
          word_pot_adc = word_pot_adc * 9      ' some calculations
          word_pot_adc = word_pot_adc + word_temp_int
          word_pot_adc = word_pot_adc / 10
       endif
       adcon0.2 = 1                            ' start new AD conversion
    endif
    The AD converter is put on when word_wachttijd_aantal is equal to 12.
    500 ms later the AD converter is started when word_wachttijd_aantal is equal to 11.
    500 ms later the AD converter is stored in word_pot_adc because word_wachttijd_aantal is less than 11 and adscon0.2 is equal to 0 a long time ago.
    After the AD value is stored in word_pot_adc a new AD conversion is started.

    If I put de code untherneath here at the same place it works fine.
    Code:
    test:
       adcon0.0 = 1                            ' AD converter on
       pause 500                               ' wait 500ms is
       adcon0.2 = 1                            ' start AD conversion
    ADC:	
       pause 5                                 ' wait 5ms aquisition time
       if adcon0.2 = 1 Then ADC                ' test if AD conversie is ready             
       word_pot_adc.highbyte = ADRESH          ' store AD value
       word_pot_adc.lowbyte = ADRESL
       adcon0.0 = 0                            ' AD converter off
    goto test
    Last edited by NacNud; - 14th December 2004 at 20:18.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what about if you put an PAUSE 50 after starting the analog to digital conversion. This will give the PIC enough time to convert and store it to your var.

    BTW wich PIC are you using ?

    if nothing work, can you post/attach your whole code?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    NacNud's Avatar
    NacNud Guest


    Did you find this post helpful? Yes | No

    Default

    I have found the answer myself. The if statements where more than 4 levels deep. Thx mister_e for your reply.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    I have found the answer myself. The if statements where more than 4 levels deep
    kinda, but look a this part of your code really closer

    Code:
    if (word_wachttijd_aantal < 11) and (byte_status == 1) then
       if adcon0.2 == 0 then                   ' test AD conversion ready
          word_temp_int.highbyte = ADRESH      ' store AD value
          word_temp_int.lowbyte = ADRESL       ' store AD value
          word_pot_adc = word_pot_adc * 9      ' some calculations
          word_pot_adc = word_pot_adc + word_temp_int
          word_pot_adc = word_pot_adc / 10
       endif
       adcon0.2 = 1                            ' start new AD conversion
    endif
    in clear if you A/D conversion is not ready you begin a new one...
    Simple to modify...

    Code:
    if (word_wachttijd_aantal < 11) and (byte_status == 1) then
       while ADCON0.2    'wait until AD conversion is ready
              pause 5
       Wend
          word_temp_int.highbyte = ADRESH      ' store AD value
          word_temp_int.lowbyte = ADRESL       ' store AD value
          word_pot_adc = word_pot_adc * 9      ' some calculations
          word_pot_adc = word_pot_adc + word_temp_int
          word_pot_adc = word_pot_adc / 10
       adcon0.2 = 1                            ' start new AD conversion
    endif
    IF THEN statement don't use stacks... SO you can use as many level you want... SUBs use stacks
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. pic12f675 ADC problem
    By radu022003 in forum mel PIC BASIC
    Replies: 3
    Last Post: - 1st September 2009, 10:13
  2. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  3. Mutliple ADC problem with PIC16F877
    By andyto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2007, 17:47
  4. ADC problem with PIC16F917
    By eetech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th March 2007, 21:22
  5. Problem reading multiple ADC ports
    By jswayze in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2004, 16:46

Members who have read this thread : 0

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

Posting Permissions

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