ADC_IN statement


Closed Thread
Results 1 to 9 of 9
  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 " !!!
    *****************************************

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    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
    Maybe I should've qualified that statement just a bit instead of throwing it out there....
    In my experience (which I know isn't as much as some, more than other, but it's enough for me ), whether I'm using a constant voltage source or a constant current source (or even a plain 'ol wall wart power supply), when you shut off the charger, immediately afterwards, the battery voltage is quite high, then starts to drop off a bit as the battery 'self equalizes'. And it seems to me that the rate at which it does this 'self equalization' business is always changing a bit different because of temp, age, how far discharged the battery was in the first place, etc.etc. I could never get decent, repeatable numbers on the graph (I whipped up a voltmeter with an RS-232, imported data into a PC, put them into a spreadsheet and tried a few things out a few years ago on NiCads and NiMH when I was working on the P/S for my mp3 player).

    What did seem to work for me, and was fairly repeatable, was just to watch the battery volts while keeping the charger on. I kept an eye on the negative delta-V. I had options in the firmware to switch from NiCad to NiMH modes to vary the amount of negative delta-V before shutting off the charger. Then, I'd let the battery sit for an hour without a load, let it do it's 'self equalization' thing. Then I'd connect it to a load resistor while plotting the discharge voltage. This seemed to be repeatable and accurate enough for me. One thing I never did do was to hook up a thermistor to check for a large delta-Temp. As you may well know, temp is one thing that'll easily tell you if you're on the verge of an overcharge or not.

    When I first started the project, I tried it thinking that checking the battery voltage with the charger disconnected was the way to go. But, like I said, the voltage drop just wasn't repeatable and I'd end up with a 1/2 charged battery packs.

    So that's my thought process. As far as newer battery charging technologies and methodology...well, that's all fine and good and it just may be that much better...but...what I ended up with worked and the numbers (mAh on the load resistor, etc.) seemed to work for me...and...it was simple...which I think was the main key!


    I just did a quick search on 'reflex' charging. At first glance, it looks like the only people that are 'FOR' reflex charging are the people trying to sell chargers...and the people saying it's crap are the university's, researchers, etc. I'll keep looking, don't have enough information to base an opinion yet...
    Last edited by skimask; - 14th April 2007 at 19:03. Reason: added info on reflex charge

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


    Did you find this post helpful? Yes | No

    Post

    Hi, Skimask

    I understand it's not necessary for a Delta V or Delta T end-of-charge ... but, here, it was a Constant current or so, charge ... as the charger doesn't stop by itself ( M .de la Pallice dixit )

    For reflex charge, it deals with the internal resistance of the battery ...

    nowadays, people has understood that batteries ( Pb,NiCad and NiMh ... others, I don't know !!! ) need high current peaks to keep their electrodes "clean" ... their low internal resistance and their full capacity.

    Reading Batt. and batt. chargers circuits manufacturer's datas will show you all that ... despite info is really spread !!!

    Alain
    Last edited by Acetronics2; - 15th April 2007 at 10:17.
    ************************************************** ***********************
    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