Independent 1 sec delays for 4x NiMH charger

microcontroller

I want to make a 4x single cell NiMH charger. using the pic 18F4550 DIP family using the MPLAB and C18

Q1. I need 4 independent 1 second timers.

Here I ran into my lack of knowledge on the way the 18F guts are shared for parallel tasks.
I of course could use 4 x series 1Meg resistor with 10 uF on any port pin.

When a cell is inserted for charging a port pin will go high applying 5 V as a driving voltage.

Using an analogue input pin , maybe AN0, the 63% point can be detected and flip that driving port pin back to zero.
As there are four cells, they will require four analogue input pins, sounds a bit wasteful of analogue pins .

I also thought about using four digital input pins to change from low to high as this is a cmos chip and they flip at 2/2 Vdd.

The toggle will take place when 1 second has elapsed at the 63% charge voltage.

But I really want to use the onboard digital timers, taking me back to my initial question Q1

Help please

Fred

Best Answer

Unless the particular part you have in mind has four suitable hardware timers you will not be able to do it 'in parallel', however all is almost surely not lost. Chance are that for a battery charger almost 1 second and almost in parallel is just fine.

For example, set up a 5ms periodic interrupt and decrement four 8-bit registers inside the ISR (interrupt service routine) until they become zero.

Now you can write a routine that sets each of the registers to 200 and waits until they test as zero for the 1 second +/- 5ms delays.

In you are using C be sure to use the volatile keyword for things that are changed in the ISR and used elsewhere .. and more complexity rears its head when the registers are wider than the 8-bit PIC word (say you wanted 1ms resolution), but it's all very do-able.