ADC_IN statement


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Default ADC_IN statement

    I am elated that my IF - Then compiles OK, but I am trying to use the A/D converter and I get a "syntax error" on the ADC_IN statement. I looks just like the example in the manual to me. Here is my program:
    REM DEVICE = 12F675
    REM USE INTERNAL OSCILLATOR, OUTPUT IS ON GP4 (PIN3)
    REM CONFIGURATION: INTOSC CLOCKOUT, WDT DISABLED, PWR UP ENABLED,
    'MCLR = INPUT PIN,BROWN OUT DISABLED, NO PROTECTION
    REM CLOCK OUT ON PIN 3 (GP4)
    REM CHARGER SWITCH ON PIN 7 (GP0)
    REM A/D INPUT ON PIN 4 (GP3)
    REM GREEN LED ON PIN 2 (GP5)
    ADCON0 = %00001101 'LEFT JUSTIFIED, VDD REF, CHANNEL 3, A/D INITIALLY OFF
    ANSEL = %01001000 'CLOCK IS FOSC/4, INPUT TO GP3
    TRISIO = 0 'ALL OUTPUTS EXCEPT GP3
    GPIO = 0 'ALL OUTPUTS INITIALLY LOW
    DEFINE OSCCAL_1K 1 'SAVES OSCILLATOR CALIBRATION
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 5 'INTOSC_CLOCKOUT?
    DEFINE ADC_SAMPLESUS 50 '50 MICROSECONDS SAMPLE TIME
    VOLT VAR WORD
    OLDVOLT VAR WORD
    GREEN VAR GPIO.5
    SWITCH VAR GPIO.0
    START:
    LOW SWITCH 'TURNS ON CHARGER
    PAUSE 60000 'DELAY 1 MINUTE
    HIGH SWITCH 'TURN OFF CHARGER
    ADC_IN 3,VOLT 'SAMPLE CHANNEL 3, STORE BATTERY VOLTAGE
    IF VOLT < OLDVOLT THEN
    STOPCHG
    ENDIF
    OLDVOLT = VOLT
    GOTO START
    STOPCHG:
    HIGH GREEN
    STOP
    END

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking Clean your glasses ...

    Hi Russ

    Just write "ADCIN" ( no underscore ...)

    << loop: ADCIN 0, adval ' Read channel 0 to adval >>



    Regards
    Alain
    Last edited by Acetronics2; - 14th April 2007 at 15:41.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    If this is a NiMH charger controller type thing, there's no reason to shut off the charger to check your battery voltage. But, instead of taking a single reading and comparing that to your old reading, I'd take a load of readings over a minute, add them up, and then see if the new 'summed reading' is less than the old 'summed reading'. That way, any voltage drops due to mains power fluctuations, ripple in the power supply, etc. should be compensated for. Try this instead:

    adcon0=$d:ansel=$48:trisio=0:gpio=0
    DEFINE OSCCAL_1K 1 'SAVES OSCILLATOR CALIBRATION
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 5 'INTOSC_CLOCKOUT?
    DEFINE ADC_SAMPLESUS 50 '50 MICROSECONDS SAMPLE TIME
    volt var word : oldvolt var word:green var gpio.5:switch var gpio.0:summedvolts var word : oldsummedvolts var word:sumcounter var byte:fudgefactor var byte:fudgefactor=100:low switch
    START:
    pause 60000:for sumcounter=1 to 64:adcin 3,volt:summedvolts=summedvolts+volt:next sumcounter:if ( summedvolts - fudgefactor ) < oldsummedvolts then stopchg
    oldsummedvolts=summedvolts:summedvolts=0:goto start
    STOPCHG:
    high green:stop
    end
    Another problem the original is that there is no 'slop' built into it. One ADCIN count less, and the charger stops. That's why I added the 'fudgefactor' to it.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    IF VOLT < OLDVOLT THEN
    STOPCHG
    ENDIF
    should be
    Code:
    IF VOLT < OLDVOLT THEN STOPCHG
    Steve

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

  5. #5
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    Thanks, Alain, it is working now.
    Steve: you are right, my code didn't work, but yours doesn't either! What works is:
    IF volt "<" oldvolt THEN
    GOTO stopchg
    ENDIF

    Thanks, all.

    Russ

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


    Did you find this post helpful? Yes | No

    Default

    <table><tr><td></td><td>
    Code:
    IF volt "<" oldvolt THEN
    well unless we don't use the same compiler, it must return a syntax error as well
    </td></tr></table>
    Code:
    If something=something_else then Label
    is the same thing as
    Code:
    If something=something_else then 
        goto Label
        endif
    At least here... so that's weird.

    Code:
    DEFINE ADC_SAMPLESUS 50
    the only valid syntax i know is
    Code:
    DEFINE ADC_SAMPLEUS 50
    Yeah, it doesn't return any syntax error... it's just ignored. Fortunately there's some default value
    pbppic14.lib
    Code:
    ;****************************************************************
    ;* Default Adcin values                                         *
    ;****************************************************************
    
        ifndef ADC_BITS		; ADC number of bits
    ADC_BITS EQU 8
        endif
        ifndef ADC_CLOCK		; ADC clock source = rc
    ADC_CLOCK EQU 3
        endif
        ifndef ADC_SAMPLEUS		; ADC sample time in microseconds
    ADC_SAMPLEUS EQU 50
        endif
    Last edited by mister_e; - 14th April 2007 at 18:32.
    Steve

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

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Thumbs down

    Hi, Skimask

    " If this is a NiMH charger controller type thing, there's no reason to shut off the charger to check your battery voltage"

    You're TOTALLY WRONG !!!

    ...

    just look at ALL NiMh and NiCd "reflex" chargers ... why stop charging when sampling voltage then ... ???

    good question !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. newbe: IF..THEN statement
    By ShawnB in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th November 2009, 14:07
  2. 16F883 and Problems with HIGH statement
    By aaanekre in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th October 2009, 01:09
  3. END Statement
    By jderson in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th November 2008, 14:48
  4. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 18:05
  5. getting around the basic IF - THEN statement
    By dw_pic in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th February 2006, 14:10

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