CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PWM based battery charger

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pras
Guest







PWM based battery charger
PostPosted: Sun Nov 24, 2002 5:46 am     Reply with quote

First of all before beginning my question I thank "Sherpa Doug" for the earlier reply. I would welcome suggestions for pointing out the possible errors or improvements in the following code!

Following is my code for performing an A/D conversion during the low period of PWM output:

---------------------------------------------------------------

#use delay (clock=20000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#define RES 5/1024

float charge_volt;

#int_ccp2
void isr()
{
setup_adc(ADC_CLOCK_INTERNAL);
delay_us(10);
charge_volt = (float)read_adc()*RES;
setup_adc(ADC_OFF);
}

void main()
{
//setup A/D ports
set_adc_channel(0);
setup_adc_ports(RA0_ANALOG);

// Setup PWM
setup_timer_2(T2_DIV_BY_16, 200, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(75);

// setup CCP2 to capture the fall edge
setup_ccp2(CCP_CAPTURE_FE);
setup_timer_1(T1_INTERNAL); //start timer 1

// setup interrupt on falling edge
enable_interrupts(INT_CCP2);
enable_interrupts(GLOBAL);

output_low(pin_C0); //charge enable

while(TRUE)
{
printf("\r\n THE A/D value in Low PWM period is \%f \r\n", charge_volt);
delay_ms(300);
}
}

---------------------------------------------------------------

Here is a short description of how i have made the ckt connection:

I have connected the PWM output to the Vadj pin of LM317 and the connected the output of LM317 (shorted with Vadj thro' a lesser ohm resistor) to a diode (IN4001) and then to the battery that should be charged (Ni-Cd/Ni-MH). Well i have also connected a transistor to provide an enable signal before it the output of LM317 gets connected to the battery terminals for charging. I HAVE ALSO CONNECTED THE PWM OUTPUT (ccp1) to ccp2 pin to detect the falling edge of PWM waveform. I vary the duty cycle of PWM to provide different charge voltages. Is this idea right?

Suggestions are welcome and would be grateful for your comments!!

Sincerely
-pras
___________________________
This message was ported from CCS's old forum
Original Post ID: 9331
R.J.Hamlett
Guest







Re: PWM based battery charger
PostPosted: Sun Nov 24, 2002 6:14 am     Reply with quote

:=First of all before beginning my question I thank "Sherpa Doug" for the earlier reply. I would welcome suggestions for pointing out the possible errors or improvements in the following code!
:=
:=Following is my code for performing an A/D conversion during the low period of PWM output:
:=
:=---------------------------------------------------------------
:=
:=#use delay (clock=20000000)
:=#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
:=#define RES 5/1024
:=
:=float charge_volt;
:=
:=#int_ccp2
:=void isr()
:={
:= setup_adc(ADC_CLOCK_INTERNAL);
:= delay_us(10);
:= charge_volt = (float)read_adc()*RES;
:= setup_adc(ADC_OFF);
:=}
:=
:=void main()
:={
:= //setup A/D ports
:= set_adc_channel(0);
:= setup_adc_ports(RA0_ANALOG);
:=
:= // Setup PWM
:= setup_timer_2(T2_DIV_BY_16, 200, 1);
:= setup_ccp1(CCP_PWM);
:= set_pwm1_duty(75);
:=
:= // setup CCP2 to capture the fall edge
:= setup_ccp2(CCP_CAPTURE_FE);
:= setup_timer_1(T1_INTERNAL); //start timer 1
:=
:= // setup interrupt on falling edge
:= enable_interrupts(INT_CCP2);
:= enable_interrupts(GLOBAL);
:=
:= output_low(pin_C0); //charge enable
:=
:= while(TRUE)
:= {
:= printf("\r\n THE A/D value in Low PWM period is \%f \r\n", charge_volt);
:= delay_ms(300);
:= }
:=}
:=
:=---------------------------------------------------------------
:=
:=Here is a short description of how i have made the ckt connection:
:=
:=I have connected the PWM output to the Vadj pin of LM317 and the connected the output of LM317 (shorted with Vadj thro' a lesser ohm resistor) to a diode (IN4001) and then to the battery that should be charged (Ni-Cd/Ni-MH). Well i have also connected a transistor to provide an enable signal before it the output of LM317 gets connected to the battery terminals for charging. I HAVE ALSO CONNECTED THE PWM OUTPUT (ccp1) to ccp2 pin to detect the falling edge of PWM waveform. I vary the duty cycle of PWM to provide different charge voltages. Is this idea right?
:=
:=Suggestions are welcome and would be grateful for your comments!!
:=
:=Sincerely
I am slightly 'worried' by the output circuit. The LM317, is a linear regulator. Now if you are feeding the pulse train to it's reference pin, 'unsmoothed', you are asking it to behave instead as a PWM driver, which it is not designed to do. You circuit after the regulator presumably is just a conventional output capacitor. Conversely if you are smoothing the PWM voltage with a capacitor, then an output buffer will be needed to drive the reference pin.
Realistically, if you are adjusting the charge with a PWM output, it becomes your responsibility to actually monitor the output voltage, and the voltage regulator becomes redundant. Normally you'd use something like a power FET, to drive an inductor, trap diode, and output capacitor directly from the PWM source, allowing massively greater efficiencies.
On the code front, why use the second CCP, for the edge detection?. This should work, but the external interrupt could also do this, and leaves an extra resource if you need it for anything else. You need to absolutely minimise the time taken in the ISR, since otherwise there is a significant risk of the low time ending. You don't need to select the ADC channel, you can leave it permanently selected to this channel (add the set in the main code). You may still need to wait a little time to allow the ADC to 'track' the output changes resulting from the last PWM 'high' period, but the code in the interrupt handler will have allready introduced several uSec of delay in getting to this point.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9332
Sergio
Guest







Re: PWM based battery charger
PostPosted: Sun Nov 24, 2002 11:53 pm     Reply with quote

I'm designing a similar circuit except I'm using an FET to drive the pulse. After this it goes into a diode then onto the battery. For monitoring the voltage I feed it into the A/D and sense it between the charging pulses. I found no need to use the PWM since I'm applying power to charge them for about a second then waiting for a short rest period. Supposedly this "rest" period improves efficiency. These are NiCads so I'm not sure yet whether to sense a specific voltage or the point of inflection as it charges. Not sure whether to "burp" it on the rest cycle yet either.

Sergio




:=First of all before beginning my question I thank "Sherpa Doug" for the earlier reply. I would welcome suggestions for pointing out the possible errors or improvements in the following code!
:=
:=Following is my code for performing an A/D conversion during the low period of PWM output:
:=
:=---------------------------------------------------------------
:=
:=#use delay (clock=20000000)
:=#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
:=#define RES 5/1024
:=
:=float charge_volt;
:=
:=#int_ccp2
:=void isr()
:={
:= setup_adc(ADC_CLOCK_INTERNAL);
:= delay_us(10);
:= charge_volt = (float)read_adc()*RES;
:= setup_adc(ADC_OFF);
:=}
:=
:=void main()
:={
:= //setup A/D ports
:= set_adc_channel(0);
:= setup_adc_ports(RA0_ANALOG);
:=
:= // Setup PWM
:= setup_timer_2(T2_DIV_BY_16, 200, 1);
:= setup_ccp1(CCP_PWM);
:= set_pwm1_duty(75);
:=
:= // setup CCP2 to capture the fall edge
:= setup_ccp2(CCP_CAPTURE_FE);
:= setup_timer_1(T1_INTERNAL); //start timer 1
:=
:= // setup interrupt on falling edge
:= enable_interrupts(INT_CCP2);
:= enable_interrupts(GLOBAL);
:=
:= output_low(pin_C0); //charge enable
:=
:= while(TRUE)
:= {
:= printf("\r\n THE A/D value in Low PWM period is \%f \r\n", charge_volt);
:= delay_ms(300);
:= }
:=}
:=
:=---------------------------------------------------------------
:=
:=Here is a short description of how i have made the ckt connection:
:=
:=I have connected the PWM output to the Vadj pin of LM317 and the connected the output of LM317 (shorted with Vadj thro' a lesser ohm resistor) to a diode (IN4001) and then to the battery that should be charged (Ni-Cd/Ni-MH). Well i have also connected a transistor to provide an enable signal before it the output of LM317 gets connected to the battery terminals for charging. I HAVE ALSO CONNECTED THE PWM OUTPUT (ccp1) to ccp2 pin to detect the falling edge of PWM waveform. I vary the duty cycle of PWM to provide different charge voltages. Is this idea right?
:=
:=Suggestions are welcome and would be grateful for your comments!!
:=
:=Sincerely
:=-pras
___________________________
This message was ported from CCS's old forum
Original Post ID: 9359
R.J.Hamlett
Guest







Re: PWM based battery charger
PostPosted: Mon Nov 25, 2002 5:33 am     Reply with quote

:=I'm designing a similar circuit except I'm using an FET to drive the pulse. After this it goes into a diode then onto the battery. For monitoring the voltage I feed it into the A/D and sense it between the charging pulses. I found no need to use the PWM since I'm applying power to charge them for about a second then waiting for a short rest period. Supposedly this "rest" period improves efficiency. These are NiCads so I'm not sure yet whether to sense a specific voltage or the point of inflection as it charges. Not sure whether to "burp" it on the rest cycle yet either.
:=
:=Sergio
This is a much better way to do the drive. Obviously the need for PWM, would depend on the incoming supply level (and impedance), with shorter pulses being necessary with a higher differential voltage, but as described, you could do exactly the same if needed, by feeding a 'train' of PWM pulses for a second, then pausing and reading. For real sophistication, you could have a resistor, and capacitor, in the feed line, allowing the current to be sensed using the AD during the pulse train, and adjust the pulse width from this (to effectively give constant current feed in the 'on time'), and combine this with the voltage measurement in the off period, to see how the battery is actually charging. :-)

Best Wishes

:=
:=
:=:=First of all before beginning my question I thank "Sherpa Doug" for the earlier reply. I would welcome suggestions for pointing out the possible errors or improvements in the following code!
:=:=
:=:=Following is my code for performing an A/D conversion during the low period of PWM output:
:=:=
:=:=---------------------------------------------------------------
:=:=
:=:=#use delay (clock=20000000)
:=:=#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
:=:=#define RES 5/1024
:=:=
:=:=float charge_volt;
:=:=
:=:=#int_ccp2
:=:=void isr()
:=:={
:=:= setup_adc(ADC_CLOCK_INTERNAL);
:=:= delay_us(10);
:=:= charge_volt = (float)read_adc()*RES;
:=:= setup_adc(ADC_OFF);
:=:=}
:=:=
:=:=void main()
:=:={
:=:= //setup A/D ports
:=:= set_adc_channel(0);
:=:= setup_adc_ports(RA0_ANALOG);
:=:=
:=:= // Setup PWM
:=:= setup_timer_2(T2_DIV_BY_16, 200, 1);
:=:= setup_ccp1(CCP_PWM);
:=:= set_pwm1_duty(75);
:=:=
:=:= // setup CCP2 to capture the fall edge
:=:= setup_ccp2(CCP_CAPTURE_FE);
:=:= setup_timer_1(T1_INTERNAL); //start timer 1
:=:=
:=:= // setup interrupt on falling edge
:=:= enable_interrupts(INT_CCP2);
:=:= enable_interrupts(GLOBAL);
:=:=
:=:= output_low(pin_C0); //charge enable
:=:=
:=:= while(TRUE)
:=:= {
:=:= printf("\r\n THE A/D value in Low PWM period is \%f \r\n", charge_volt);
:=:= delay_ms(300);
:=:= }
:=:=}
:=:=
:=:=---------------------------------------------------------------
:=:=
:=:=Here is a short description of how i have made the ckt connection:
:=:=
:=:=I have connected the PWM output to the Vadj pin of LM317 and the connected the output of LM317 (shorted with Vadj thro' a lesser ohm resistor) to a diode (IN4001) and then to the battery that should be charged (Ni-Cd/Ni-MH). Well i have also connected a transistor to provide an enable signal before it the output of LM317 gets connected to the battery terminals for charging. I HAVE ALSO CONNECTED THE PWM OUTPUT (ccp1) to ccp2 pin to detect the falling edge of PWM waveform. I vary the duty cycle of PWM to provide different charge voltages. Is this idea right?
:=:=
:=:=Suggestions are welcome and would be grateful for your comments!!
:=:=
:=:=Sincerely
:=:=-pras
___________________________
This message was ported from CCS's old forum
Original Post ID: 9381
Sergio
Guest







Re: PWM based battery charger
PostPosted: Mon Nov 25, 2002 11:33 pm     Reply with quote

Well, as I look deeper into it I think that I will need to sense the current going into the batteries since I wish to toggle betweeen a 0.1C slow charge and a faster 0.5C rate.

Good idea on your circuit. I'm going to have to think exactly how I'm going to do it. This charger was an after thought by the client and I probably won't give it too much time till after Thanskgiving. I'll post it up here since I'm sure that others can use this circuit and c routines.

Cheers,
Sergio


:=:=I'm designing a similar circuit except I'm using an FET to drive the pulse. After this it goes into a diode then onto the battery. For monitoring the voltage I feed it into the A/D and sense it between the charging pulses. I found no need to use the PWM since I'm applying power to charge them for about a second then waiting for a short rest period. Supposedly this "rest" period improves efficiency. These are NiCads so I'm not sure yet whether to sense a specific voltage or the point of inflection as it charges. Not sure whether to "burp" it on the rest cycle yet either.
:=:=
:=:=Sergio
:=This is a much better way to do the drive. Obviously the need for PWM, would depend on the incoming supply level (and impedance), with shorter pulses being necessary with a higher differential voltage, but as described, you could do exactly the same if needed, by feeding a 'train' of PWM pulses for a second, then pausing and reading. For real sophistication, you could have a resistor, and capacitor, in the feed line, allowing the current to be sensed using the AD during the pulse train, and adjust the pulse width from this (to effectively give constant current feed in the 'on time'), and combine this with the voltage measurement in the off period, to see how the battery is actually charging. :-)
:=
:=Best Wishes
:=
:=:=
:=:=
:=:=:=First of all before beginning my question I thank "Sherpa Doug" for the earlier reply. I would welcome suggestions for pointing out the possible errors or improvements in the following code!
:=:=:=
:=:=:=Following is my code for performing an A/D conversion during the low period of PWM output:
:=:=:=
:=:=:=---------------------------------------------------------------
:=:=:=
:=:=:=#use delay (clock=20000000)
:=:=:=#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
:=:=:=#define RES 5/1024
:=:=:=
:=:=:=float charge_volt;
:=:=:=
:=:=:=#int_ccp2
:=:=:=void isr()
:=:=:={
:=:=:= setup_adc(ADC_CLOCK_INTERNAL);
:=:=:= delay_us(10);
:=:=:= charge_volt = (float)read_adc()*RES;
:=:=:= setup_adc(ADC_OFF);
:=:=:=}
:=:=:=
:=:=:=void main()
:=:=:={
:=:=:= //setup A/D ports
:=:=:= set_adc_channel(0);
:=:=:= setup_adc_ports(RA0_ANALOG);
:=:=:=
:=:=:= // Setup PWM
:=:=:= setup_timer_2(T2_DIV_BY_16, 200, 1);
:=:=:= setup_ccp1(CCP_PWM);
:=:=:= set_pwm1_duty(75);
:=:=:=
:=:=:= // setup CCP2 to capture the fall edge
:=:=:= setup_ccp2(CCP_CAPTURE_FE);
:=:=:= setup_timer_1(T1_INTERNAL); //start timer 1
:=:=:=
:=:=:= // setup interrupt on falling edge
:=:=:= enable_interrupts(INT_CCP2);
:=:=:= enable_interrupts(GLOBAL);
:=:=:=
:=:=:= output_low(pin_C0); //charge enable
:=:=:=
:=:=:= while(TRUE)
:=:=:= {
:=:=:= printf("\r\n THE A/D value in Low PWM period is \%f \r\n", charge_volt);
:=:=:= delay_ms(300);
:=:=:= }
:=:=:=}
:=:=:=
:=:=:=---------------------------------------------------------------
:=:=:=
:=:=:=Here is a short description of how i have made the ckt connection:
:=:=:=
:=:=:=I have connected the PWM output to the Vadj pin of LM317 and the connected the output of LM317 (shorted with Vadj thro' a lesser ohm resistor) to a diode (IN4001) and then to the battery that should be charged (Ni-Cd/Ni-MH). Well i have also connected a transistor to provide an enable signal before it the output of LM317 gets connected to the battery terminals for charging. I HAVE ALSO CONNECTED THE PWM OUTPUT (ccp1) to ccp2 pin to detect the falling edge of PWM waveform. I vary the duty cycle of PWM to provide different charge voltages. Is this idea right?
:=:=:=
:=:=:=Suggestions are welcome and would be grateful for your comments!!
:=:=:=
:=:=:=Sincerely
:=:=:=-pras
___________________________
This message was ported from CCS's old forum
Original Post ID: 9426
pras
Guest







PWM - Thanks for the kind reply
PostPosted: Tue Nov 26, 2002 3:02 am     Reply with quote

Thanks a lot for your kind reply. Well, I modified my circuit and i introduced a 100 microH inductance. The following is my ckt description:

I connected the PWM output to a signal conditioning unit comprising of a transistor, inductor, diodes (IN4001 - don't know whether it is good for switching speeds) and a N-FET.

That was basically a buck converter circuit and then i gave a charge enable transistor to the output of the buck converter circuit to enable/disable the charge voltage to the battery. With a PWM output of Ton = 50\% (2.5V and 10 mA) and using the FET ..i was able to get 185mA from the source of the FET..well,then it was fed to the rectifing circuit and then i was able to get only 60 mA..and eventually when i put up a 100 ohm resistor before connecting it to the charge enable/disable transistor..i get only 6 mA as the charge current with 2.72 V at the output for a PWM of 50\% ON-period..

I have the following question:
How do I increase the current without increasing the voltage further?? Is there a current amplifier circuit using LM317 or any other transistor combination?

I need a charge current anywhere inbetween "250mA - 300mA " and another question is how to sense the charge current?? In one of my earlier questions i was suggested to use MAX471 (current sense IC from Maxim)..

I am using LM324 in my circuit and feeding the charge current taken from the negative terminal of the battery and then grounding it with 0.05 ohm resistor as i connect it to one of the inputs of the quad op-amp (LM324)..and then doing a voltage comparator operation.. Is this method right?

I need your expert opinion!

Thanking you in advance
Regards

-pras

PS: If you would prefer to have a better idea of the ckt, my email id for contact is soundoctor@rediffmail.com (i can provide you with the circuit diagram). Thanks!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 9433
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group