LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Graphing Capacitor Charging and Discharging after Time Constant

Solved!
Go to solution

So I'm really new to LabView and I've been struggling to get this program to work. I'm supposed to plot the charging and discharging of a capacitor on a graph. The capacitor should charge until 10RC and then discharge. The program should use the following inputs: values of R and C, time between data points, number of data points, and the DC power supply voltage. I'm supposed to use case structure, for loop, and enum to switch the variable power supply voltage from 5V (charging) to 0V (discharging) after 10RC and then record the output voltage over the capacitor using the DAQ Assistant. While the program is running, I should have a chart showing comparing the theoretical value at that point in time to the experimental. The LabVIEW program should output a delimited spreadsheet file that contains the time, theoretical, and experimental values. So previously I made a program to plot the theoretical charging and discharging of the capacitor (hoping to use a sub VI to pull those experimental values?).

 

My problem: I can't get my program to switch to discharging. I get charging plots but even after waiting hours, no discharge occurs. Or I only get discharging plots. I've a strong suspicion that I'm using time variables incorrectly. I've attached my programs for the theoretical and experimental version. Thanks for any help you can offer!

Download All
Message 1 of 13
(5,554 Views)

I'm not at my laptop just now but I'm going to point out that this.

 

Looks like homework. 

 

That keys other posters to provide advice and feedback to help you EARN your own grade.  We like to see students try first and ask why they are not getting desired results.   Kudos 


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 13
(5,536 Views)

Yes, this is an in-lab assignment for my grad level lab course worth 1 point. I'm just curious as to how to solve this problem rather than give up on it. We are supposed to conceptually understand what is going on. I've been working on this program for two weeks trying different things to no avail. Both of our lab TAs were unable to get this program to work as well so they weren't helpful either. Just want some suggestions for understanding what it going on here 🙂

0 Kudos
Message 3 of 13
(5,533 Views)

Now I can help...

 

I will ask two very pointed questions then you are going to find out why I asked them. Fair enough?

 

1. Looking at "Theoretical" If you place an indicator on the output of the integer shift register what will its value be when the vi completes execution?  Trust me, it does not matter one bit what the value of "Data Points" is when the vi starts.  What is the only condition that this value depends on?  does changing that condition during the vi execution influence the outcome?

 

2. Looking at "Experimental"  What must happen to cause a change from executing the discharging case to executing the charging case within a single execution of the vi? What must happen to effect the opposite change within a single execution of the vi?  Hint: Google "IEEE-754"     

 

Can you fix it from those clues?

 

Post your solution and explain it for the other contributors here.


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 13
(5,528 Views)

1) Oh yes, data points is just an arbitrary number for running the loop. In our instructions, it says this number should depend of the # of time constants and the time between data points that is desired, but I did not see why to use it as an input at all.

Which integer shift register? I only have the enum shift register. The output of my capacitor voltage?

 

2) For example, when R = 1 kOhm, C = 500 uF, 10RC = 5 seconds. So in this case, after five iterations the loop (which should take 1 second each based on timer), it should switch from charging to discharging. Once it's on the discharging condition, I don't want it to switch back.

 

Within one execution, means one iteration and 1 sec time has passed which should mean the charging state is ongoing? Is it only doing that over and over again? So that I set an impossible condition?

 

I googled IEEE-754 (covering binary numbers later in the course, alas) and don't understand how that comes into play here. Do I have a floating point decimal? I guess I do in my input for C.

 

Sorry, still scratching my head here XD

0 Kudos
Message 5 of 13
(5,490 Views)

Oh, by placing indicators at different points, I can see iteration does not result in the same number inside and outside the case structure.

 

And referring to the IEEE-754, does that relate to the red dot on my equal sign? And to the loop count? Hmm.

 

EDIT: Ahhhhh, I got it to work! At least theoretically! Both discharging and charging curves 😄 I will try the actual portion in lab tomorrow. Thanks, those tips about thinking about it for each single run really helped!

 

image.png

Message 6 of 13
(5,487 Views)

Great. You have done some work and asked for clarity when uncertain 

 

Awesome!

 

Let's go back to your enum control.  Dataflow says it will be read exactly 1 time.  And that value will be placed on the for loops blue shift register.  In theoretical. Vi.  You wire that value to a case selector and in each case you wire that value to th cases output then back to the shift register.  Nothing can change that value after the run button has been pressed and the for loop starts.

 

The code never executes the other case.

 

Empirical.  Has that floating point number being compared with an integer value for equality and that nasty coersion dot has offered you a clue.    Floating point numbers are seldom exactly equal to integers.  A greater than or equal to would at least switch the comparison after a number of iterations.. as you have it... unless you hit the lottery and find a floating point value that is a whole number and equal to the iteration count... well, you should bother your teacher now rather than later....

 

You show promise.  Keep digging!

 

Ignorance is your teacher's fault and your responsibility to correct.  Stupidity is your fault and your teacher's responsibility to correct.   -JJB


"Should be" isn't "Is" -Jay
Message 7 of 13
(5,482 Views)

Ah, I understand what you're talking about for the Theoretical. That VI is actually working fine, we were just supposed to get an individual plot of charging and discharging.

 

So I tested the experimental today and it still doesn't work. I get the same sharp jump up to my voltage and a discharging curve. I think I interpreted my problem incorrectly. I think there's an issue with how I'm plotting the myDAQ output. It's giving me zeros for the charging voltage. I even split the two DAQ outputs and added them individually, but I still get the same plot.

image.png

0 Kudos
Message 8 of 13
(5,447 Views)

Please repost the empirical vi with recent changes... that looks like your task may be not quite right... I'll need to go into my home office and investigate.   And that laptop  needs to be packed for a business trip.  If I miss your window. ... hopefully another DAQmx overlord will have a chance to help too.


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 13
(5,440 Views)

I made some minor tweaks, but the first experimental VI I posted gives me the same results as the "updated" one. Thanks for all your help 🙂

 

EDIT: Do I need to use two different channels in myDAQ for the voltage recording? I have both using A0.

0 Kudos
Message 10 of 13
(5,436 Views)