# Thread: Basic C help. charging battery DC RC circuit in series

1. ## Basic C help. charging battery DC RC circuit in series

given circuit containing a capacitor, switch, resistor and power supply. have to create a c program that allows the person using it to calculate time it takes for capacitor to charge up to 50% 70% and 90% of supply voltage Vs.
User must input values for the resistor R, capacitor C and power supply dc voltage with the final time answer given in seconds.

Vc = Vs(1-e^-1/RC)) formula for calculating voltage across capacitor ( as a function of time) t=0 when switch is closed

any ideas? new to c!

2. Nope.

3. okay thanks anyways!

4. The electrical charge on a capacitor is a function of time and available current... the current is limited by series resistence in the circuit...
Given R and C one can calculate the rate of change using the simple forumla tc = 1 / (2pi R C)... A time constant (tc) is defined as the time it takes the capacitor to charge to 63% of the remaining voltage... a capacitor is considered fully charged after 5 time constants.

Once you know C and R, simply apply the forumla to get the value of 1 time constant... the rest should be simple.

What you need to do is sit down and figure out what is needed...
Obviously you need the forumla...
You also need some means of acquiring the values of R and C...
and so on.

With that in hand, you can write a step by step plan for solving the problem.

With plan in hand, you can begin working on your source code.

When the source is completed you need to test to make sure it's behaving correctly.

5. Many Thanks Tater. This has helped my understanding of the problem loads! cheers.

6. That's a fine post Tater.

7. ## C newbie!

after some great help from Tater ive spent some time looking at it i now understand how it works on paper but i am still struggling to put that into a c program. As a C newbie wondering if anyone can help. The user must input the values of resistance R, capacitor C and Supply Voltage Vs. here is as far as ive got before hitting the wall. ( sorry if these basic c questions seem silly, only just started out! The aim of the program is to find how long it takes for capacitor to charge up 50%, 70% and 90%

Code:
```#include <stdio.h>

main()
{
float r;
float c;
float vs;
float vc;
printf("please input the value of the resistance\n");
scanf("%f",&r);
printf("please input the value of the current\n");
scanf("%f",&c);
printf("please input the value of the source voltage\n");
scanf("%f",&vs);

}```

8. Great start! ...

Every solution begins with understanding the problem.

The next step would be to apply your formula to the user's data and determine your time constant.

I noticed you had a somewhat different formula in your original message... I don't recognize it (i.e. Its not one I've used in general electronics) but you should probably try both... When R is in Megohms and C is in Microfarads mine gives an answer in seconds... not sure about the other one.

Then, once you've got the forumla to compile, you need to display the answers... so you'll have to add some printf() with the results.

Then guess what... That's it.