2020-03-01 14:44:45 +01:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2003-2020 Andy Little.
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see http://www.gnu.org/licenses./
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
capacitor discharge curve using compile_time
|
|
|
|
|
physical_quantities
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-16 09:32:28 +01:00
|
|
|
#include <units/physical/si/capacitance.h>
|
|
|
|
|
#include <units/physical/si/resistance.h>
|
|
|
|
|
#include <units/physical/si/time.h>
|
2020-09-08 11:02:16 +02:00
|
|
|
#include <units/math.h>
|
2020-12-28 15:18:02 +01:00
|
|
|
#include <units/quantity_io.h>
|
2020-03-19 11:43:12 +00:00
|
|
|
#include "./voltage.h"
|
2020-03-01 14:44:45 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2020-03-19 11:43:12 +00:00
|
|
|
using namespace units::experimental;
|
2020-05-08 22:39:24 +02:00
|
|
|
using namespace units::physical::si::literals;
|
2020-03-01 14:44:45 +01:00
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
std::cout << "mpusz/units capacitor time curve example...\n";
|
|
|
|
|
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
|
|
|
|
|
std::cout.precision(3);
|
|
|
|
|
|
2020-09-09 19:20:35 +02:00
|
|
|
constexpr auto C = 0.47_q_uF;
|
|
|
|
|
constexpr auto V0 = 5.0_q_V;
|
|
|
|
|
constexpr auto R = 4.7_q_kR;
|
2020-03-01 14:44:45 +01:00
|
|
|
|
2020-09-09 19:20:35 +02:00
|
|
|
for (auto t = 0_q_ms; t <= 50_q_ms; ++t) {
|
2020-09-08 11:02:16 +02:00
|
|
|
const auto Vt = V0 * units::exp(-t / (R * C));
|
2020-03-01 14:44:45 +01:00
|
|
|
|
|
|
|
|
std::cout << "at " << t << " voltage is ";
|
|
|
|
|
|
2020-09-09 19:20:35 +02:00
|
|
|
if (Vt >= 1_q_V)
|
2020-03-01 14:44:45 +01:00
|
|
|
std::cout << Vt;
|
2020-09-09 19:20:35 +02:00
|
|
|
else if (Vt >= 1_q_mV)
|
2020-03-01 14:44:45 +01:00
|
|
|
std::cout << voltage::mV<>{Vt};
|
2020-09-09 19:20:35 +02:00
|
|
|
else if (Vt >= 1_q_uV)
|
2020-03-01 14:44:45 +01:00
|
|
|
std::cout << voltage::uV<>{Vt};
|
2020-09-09 19:20:35 +02:00
|
|
|
else if (Vt >= 1_q_nV)
|
2020-03-01 14:44:45 +01:00
|
|
|
std::cout << voltage::nV<>{Vt};
|
|
|
|
|
else
|
|
|
|
|
std::cout << voltage::pV<>{Vt};
|
|
|
|
|
std::cout << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|