# Pretty good weekend effort

#### joeyd999

Joined Jun 6, 2011
4,474
If the theoretical is a straight line, it may be tough to justify the significance of any additional terms. They might help fit existing data but not really have much predictive value.
The coefficients for the 6th order polynomial were generated based upon the measured discharge characteristics of a set of Energizer alkaline batteries. I had no expectation that the Duracells would track exactly -- simply because of what I am sure are differences in the manufacturing process (even the chemistry might be subtly different).

I am not surprised by the overall result. The only surprise was those few hours where the terminal voltage did not change at all. It's possible that the the electrolyte in the Duracells is more mobile than that in the Energizers, at least at that point in the discharge curve.

I am interested enough to repeat the experiment to see if it holds for another set of Duracells. But I cannot do that till I again have some free time -- perhaps in the next few weeks.

This is not an important problem. More of an intellectual curiosity.

#### Tesla23

Joined May 10, 2009
511
The coefficients for the 6th order polynomial were generated based upon the measured discharge characteristics of a set of Energizer alkaline batteries. I had no expectation that the Duracells would track exactly -- simply because of what I am sure are differences in the manufacturing process (even the chemistry might be subtly different).

I am not surprised by the overall result. The only surprise was those few hours where the terminal voltage did not change at all. It's possible that the the electrolyte in the Duracells is more mobile than that in the Energizers, at least at that point in the discharge curve.

I am interested enough to repeat the experiment to see if it holds for another set of Duracells. But I cannot do that till I again have some free time -- perhaps in the next few weeks.

This is not an important problem. More of an intellectual curiosity.
How are you accounting for temperature - this has an enormous effect on battery performance. In your discharge test, did you hold the temperature constant? It's possible you are fitting higher order terms to your room temperature profile.

From Energizer website for an alkaline : http://data.energizer.com/pdfs/temperat.pdf

#### wayneh

Joined Sep 9, 2010
17,167
The coefficients for the 6th order polynomial were generated based upon the measured discharge characteristics of a set of Energizer alkaline batteries. I had no expectation that the Duracells would track exactly -- simply because of what I am sure are differences in the manufacturing process (even the chemistry might be subtly different).

I am not surprised by the overall result. The only surprise was those few hours where the terminal voltage did not change at all. It's possible that the the electrolyte in the Duracells is more mobile than that in the Energizers, at least at that point in the discharge curve.

I am interested enough to repeat the experiment to see if it holds for another set of Duracells. But I cannot do that till I again have some free time -- perhaps in the next few weeks.

This is not an important problem. More of an intellectual curiosity.
Make sure you control for temperature as much as you can. Changing ambient temperature could cause some anomalies.

I suspect that a method called ARIMA might give a better result. It’s basically a moving average but with a random walk. It’s a common way to model stock prices, for instance. I think for a battery you would always predict a linear decay from wherever you are at the moment.

#### joeyd999

Joined Jun 6, 2011
4,474
How are you accounting for temperature?
Make sure you control for temperature as much as you can.
I'm way ahead of you guys:

It doesn't compensate for temperature, but it doesn't have to.
All I want is a 0% battery life at ~1.8V (regardless of temp) and a very rough estimate of remaining battery life elsewhere. Again, this is an academic exercise. I was curious how close I could get to an accurate estimate without accounting for temperature.

#### cmartinez

Joined Jan 17, 2007
7,744
a very rough estimate
and that's why you used a 6th order polynomial? ... hell, I would've just calculated a least-squares straight line and be done with it! ... on the other hand, this tells me something about your perfectionist streak ...

#### joeyd999

Joined Jun 6, 2011
4,474
hell, I would've just calculated a least-squares straight line and be done with it!
Yebbut...constant power does complex things to the basic discharge curve. The load increases as the battery ability to support loads decreases.

#### nsaspook

Joined Aug 27, 2009
9,983
Yebbut...constant power does complex things to the basic discharge curve. The load increases as the battery ability to support loads decreases.
Exactly, for my solar battery monitor I dynamically compute discharge and load run-time parameters using a sizable number of real-time and historically derived data points. Chemical batteries are like living creatures under load.

#### cmartinez

Joined Jan 17, 2007
7,744
very interesting ... I don't know much about batteries actually (in case you haven't noticed) ... so, what you're saying is that the battery's internal resistance changes as it's discharged?

#### joeyd999

Joined Jun 6, 2011
4,474
very interesting ... I don't know much about batteries actually (in case you haven't noticed) ... so, what you're saying is that the battery's internal resistance changes as it's discharged?
I'm saying the terminal voltage is a function of temperature, state of charge, and load.

Batteries are extremely non-linear devices. I think my first shot was a pretty good estimate -- well within expectations. It's just the strange response over a few hours that surprised -- and interests -- me.

#### cmartinez

Joined Jan 17, 2007
7,744
I'm saying the terminal voltage is a function of temperature, state of charge, and load.

Batteries are extremely non-linear devices. I think my first shot was a pretty good estimate -- well within expectations. It's just the strange response over a few hours that surprised -- and interests -- me.
And I'm interested too ... especially about that strange plateau at between 30-35 hrs ... So this is what I'm beginning to grasp: batteries change their behavior depending on (among other things) rate of discharge, and that would mean that their performance changes from device to device. So that means that the curve you've calculated applies to your device only, is that it?

#### joeyd999

Joined Jun 6, 2011
4,474
And I'm interested too ... especially about that strange plateau at between 30-35 hrs ... So this is what I'm beginning to grasp: batteries change their behavior depending on (among other things) rate of discharge, and that would mean that their performance changes from device to device. So that means that the curve you've calculated applies to your device only, is that it?
Yes, but I'm trying to generalize it a bit. The power required by my device does change depending on certain things.

#### joeyd999

Joined Jun 6, 2011
4,474
I simplified my encoder code a few weeks ago, and I forgot to post an update. It works highly reliably now. Here is the interrupt routine:

Code:
;*****************************************
;** ENCINT -- Encoder Interrupt routine **
;*****************************************

encint    swapf    portb,w        ;capture new encoder value (bits 4:5 -> 0:1)
bcf    intcon,rbif    ;clear interrupt

rlncf    _enclst,f    ;shift old values
rlncf    _enclst,f
iorwf    _enclst,w    ;merge in new
andlw    b'1111'        ;modulo 16
movwf    _enclst        ;save as new last

call    _cjump

bra    eina        ;no action
bra    eidec        ;decrement
bra    eiinc        ;increment
bra     eina        ;no action

bra    eiinc        ;increment
bra     eina        ;no action
bra     eina        ;no action
bra    eidec        ;decrement

bra    eidec        ;decrement
bra     eina        ;no action
bra     eina        ;no action
bra    eiinc        ;increment

bra    eina        ;no action
bra    eiinc        ;increment
bra    eidec        ;decrement
bra     eina        ;no action

eidec    decf    _enccnt,f    ;decrement minor encoder counts
bra    eiupd        ;and process hysteresis

eiinc    incf    _enccnt,f    ;increment minor encoder counts

;process hysteretic state machine

eiupd    cjump    _enccnt

bra    eist0
bra    eina
bra    eist2
bra    eina
bra    eina        ;midpoint of current count
bra    eina
bra    eist6
bra    eina

eist0    bcf    _encbup        ;reset back to mid-position
bcf    _encbdn
movlf    _enccnt,4
bra    eina

eist2    bbs    _encbdn,eina    ;decrement one major count
bsf    _encbdn
bcf    _encbup
bra    eidn

eist6    bbs    _encbup,eina    ;Increment one major count
bsf    _encbup
bcf    _encbdn
bra    eiup

;increment major count and set up flag

eiup    incf    _encinc,f
bsf    _encup
bra    eiex

;decrement major count and set down flag

eidn    decf    _encinc,f
bsf    _encdn

eiex    bsf    _encrdy        ;indicate new encoder data ready

eina    goto    intdone        ;and get out
And this is the "user space" polling code:

Code:
;*****************************
;** POLLENC -- Poll Encoder **
;*****************************

pollenc    movlw    b'00001111'    ;preclear static flags
andwf    encflag,f

bbs    psenc,peeact    ;encoder active and initialized?
retbc    pcenc        ;inactive and off, do nothing
bra    encinit        ;otherwise, initialize

peeact    bbc    pcenc,encoff    ;turn off encoder if necessary

retbc    _encrdy

;capture encoder increments since last check into temp0

bcf    intcon,rbie    ;disable further interrupts

movff    _encinc,temp0    ;capture increment
movff    encflag,temp1    ;capture volatile flags

clrw
movff    wreg,_encinc    ;and increments for next pass

clrf    encflag        ;clear volatile flags

bsf    intcon,rbie     ;reinable int

;add signed 8 bit increments into cntnew

movfw    temp0        ;get increment/decrement

;set static flags

swapf    temp1,w        ;duplicate low nibble to high
andlw    b'11110000'
iorwf    encflag        ;set static flags

return            ;and get out
The flag definitions are:

Code:
#define    _encrdy    encflag,0        ;1=Optical Encoder data ready
#define _encup     encflag,1        ;1=encoder up
#define _encdn    encflag,2        ;1=encoder down
;#define     encflag,3        ;
#define    encrdy    encflag,4        ;1=Optical Encoder data ready
#define encup     encflag,5        ;1=encoder up
#define encdn    encflag,6        ;1=encoder down
;#define     encflag,7        ;

#define _encbup    encflag1,0        ;hysteretic bits
#define _encbdn    encflag1,1

#### joeyd999

Joined Jun 6, 2011
4,474
And, dammit!, I am still waiting for the last part to arrive for my new transducer, the whole reason why I have embarked on this project.

Tracking shows that the part has visited all over the world the past few weeks: Philippines, China, Japan, Hawaii, and California so far. Just not Florida.

It should arrive in the next day or so -- tanned, rested, and ready.

#### cmartinez

Joined Jan 17, 2007
7,744
And, dammit!, I am still waiting for the last part to arrive for my new transducer, the whole reason why I have embarked on this project.

Tracking shows that the part has visited all over the world the past few weeks: Philippines, China, Japan, Hawaii, and California so far. Just not Florida.

It should arrive in the next day or so -- tanned, rested, and ready.
and you ordered only one unit?

#### joeyd999

Joined Jun 6, 2011
4,474
and you ordered only one unit?
No, silly. But I am only assembling one transducer for starters, therefore, I only need one part.

If the one does not perform as expected (assuming all else is correct), there is no point in building more: the project (a proof-of-principle of the new transducer) will have been a failure.

#### cmartinez

Joined Jan 17, 2007
7,744
No, silly. But I am only assembling one transducer for starters, therefore, I only need one part.

If the one does not perform as expected (assuming all else is correct), there is no point in building more: the project (a proof-of-principle of the new transducer) will have been a failure.
How long ago did you order that component?

And yes, I've been there, alright. I know the feeling of laying one's hope on a single component ... good luck!

#### joeyd999

Joined Jun 6, 2011
4,474
How long ago did you order that component?

And yes, I've been there, alright. I know the feeling of laying one's hope on a single component ... good luck!
The part in question is a stock part that I use in my daily course of business. I was unaware until two weeks ago that I did not have one in stock -- until I received all the other parts I required for the build.

The part I am waiting for is not the questionable part of the build. The finished transducer (as a whole) is.

Joined Jul 18, 2013
25,466
Have you ever looked into the P18F2331/4431 series?
They have a Motion feedback module in them, aimed at quadrature encoders etc.
There are 100p/rev quad encoders on ebay for ~\$2.00, includes the metallic slotted disk and slot detector.
Apart from the odd 12F series, I generally just use the P18F series now.
Max.

#### joeyd999

Joined Jun 6, 2011
4,474
Have you ever looked into the P18F2331/4431 series?
They have a Motion feedback module in them, aimed at quadrature encoders etc.
This might be attractive if I were developing a motion control project.

But I am just using the encoder for menu scrolling and quick and easy adjustments. The PIC was selected to support what I require to run the transducer.

#### joeyd999

Joined Jun 6, 2011
4,474
How long ago did you order that component?

And yes, I've been there, alright. I know the feeling of laying one's hope on a single component ... good luck!
The parts just arrived. Yay!

Building transducer as we speak. It'll be a few days till I have final results.

But at least I have some real work to do now.