I am doing my homework, and I am trying to figure out this part: Using if statements, detect & print the rise time of the signal. The rise time of a signal is computed as the time it takes the signal to transition from 10% to 90%
of the final voltage (i.e. Vs). Compute this value by checking the capacitor voltage at each time step that you compute it. Record the first time step at which the voltage reaches at least 10% of Vs and then record the first time step at which the voltage reaches at least 90% of Vs and compute the rise time as the difference. If Vc never reaches one or both of these thresholds, simply output "No rise-time available".
I do not need any code. I just need a good explanation how to write these if statements. I will appreciate your help.
I usually find it easiest to start by thinking of the data that you'll need. In this case:
- You're given Vs from somewhere.
- Compute Vlow and Vhigh, the 10% and 90% thresholds
- You'll need variables to store the time step numbers for when the voltage reaches Vlow and Vhigh. Let's call these lowStep and highStep
Note that you want to set lowStep only once. So your code there will have to say if (current voltage > Vlow and I haven't set lowStep) lowStep = currentStep;