PDA

View Full Version : ADC_IN statement



Russ Kincaid
- 14th April 2007, 15:22
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

Acetronics2
- 14th April 2007, 15:38
Hi Russ

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

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



Regards
Alain

skimask
- 14th April 2007, 17:22
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.

mister_e
- 14th April 2007, 17:26
IF VOLT < OLDVOLT THEN
STOPCHG
ENDIF

should be


IF VOLT < OLDVOLT THEN STOPCHG

Russ Kincaid
- 14th April 2007, 17:53
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

mister_e
- 14th April 2007, 18:17
<table><tr><td>http://www.mister-e.org/Pics/animation38.gif</td><td>
IF volt "<" oldvolt THEN
well unless we don't use the same compiler, it must return a syntax error as well
</td></tr></table>

If something=something_else then Label
is the same thing as

If something=something_else then
goto Label
endif

At least here... so that's weird.


DEFINE ADC_SAMPLESUS 50
the only valid syntax i know is

DEFINE ADC_SAMPLEUS 50

Yeah, it doesn't return any syntax error... it's just ignored. Fortunately there's some default value ;)
pbppic14.lib


;************************************************* ***************
;* 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

Acetronics2
- 14th April 2007, 18:39
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

skimask
- 14th April 2007, 18:58
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...

Acetronics2
- 15th April 2007, 10:15
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