|
| 1 | +/* |
| 2 | + Copyright 2017 Russell Jackson |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#include <iostream> |
| 18 | +#include <string> |
| 19 | +#include <vector> |
| 20 | +#include <gtest/gtest.h> |
| 21 | +#include "hardware/digital_analog_conversions.h" |
| 22 | + |
| 23 | + |
| 24 | +TEST(ard_hardware_conv, ADC_DAC) |
| 25 | +{ |
| 26 | + // for each potential value of current, validate that the ADC then back to DAC is valid. |
| 27 | + for (uint16_t index(0); index < 4096; index++) |
| 28 | + { |
| 29 | + double amperageVal(adc2MilliAmp(index)); |
| 30 | + uint16_t index_(milliAmp2Dac(amperageVal)); |
| 31 | + ASSERT_EQ(index, index_); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +TEST(ard_hardware_conv, DAC_ADC) |
| 36 | +{ |
| 37 | + // for each potential value of current, validate that the ADC then back to DAC is valid. |
| 38 | + double di(0.000001); |
| 39 | + for (double i(0.0); i < 300.0; i+=di) |
| 40 | + { |
| 41 | + uint16_t dacVal(milliAmp2Dac(i)); |
| 42 | + double i_(adc2MilliAmp(dacVal)); |
| 43 | + double e_(abs(i-i_)); |
| 44 | + ASSERT_LT(e_, 1/12.8); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +int main(int argc, char** argv) |
| 51 | +{ |
| 52 | + testing::InitGoogleTest(&argc, argv); |
| 53 | + return RUN_ALL_TESTS(); |
| 54 | +} |
0 commit comments