2 #include "libpropeller/pwm2/pwm2.h"
3 #include "libpropeller/pulsewidthreader/pulse_width_reader.h"
4 #include "libpropeller/board/board_unit_tester.h"
11 const int kFrequency = 1000;
13 const int outputPin = libpropeller::Board::kPinTie1a;
14 const int inputPinMask = 1 << libpropeller::Board::kPinTie1b;
19 static int MicrosecondsToClockCycles(
const int microseconds) {
20 return (
CLKFREQ * microseconds) / 1000000;
23 static int ClockCyclesToMicroseconds(
const int clockCycles) {
24 return clockCycles / (
CLKFREQ / 1000000);
27 static void setUp(
void) {
30 sut->SetPinX(outputPin);
31 sut->SetFrequency(kFrequency);
34 pwr->
Start(inputPinMask);
40 static void tearDown(
void) {
51 static void helper_CheckWidths(
const int highMicroseconds,
const int lowMicroseconds) {
52 TEST_ASSERT_INT_WITHIN(3, highMicroseconds,
55 TEST_ASSERT_INT_WITHIN(3, lowMicroseconds,
56 ClockCyclesToMicroseconds(pwr->
getLowTime(0)));
59 static void helper_TestDuty(
const int percent) {
63 const int periodUs = 1000000 / kFrequency;
64 sut->SetDutyX(percent);
69 helper_CheckWidths((periodUs * percent) / 100, (periodUs * (100 - percent)) / 100);
72 static void test_80PercentDuty(
void) {
76 static void test_20PercentDuty(
void) {
81 static void test_50PercentDuty(
void) {