Skip to content

Commit bfd6e1e

Browse files
committed
src/corelibs/analogio: Test for SetAnalogfrequency function.
Signed-off-by: IFX-Anusha <[email protected]>
1 parent 4fc98b6 commit bfd6e1e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/corelibs/analogio/test_analogio_pwm.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,25 @@ TEST_IFX(analogio_pwm, test_analog_write_pwm_0_percentage_dutycycle)
240240
TEST_ASSERT_EQUAL_MESSAGE(LOW, digitalRead(PWM_PIN_FEEDBACK), "PWM output should be LOW when 0 percentage duty cycle is set");
241241
}
242242

243+
/**
244+
* @brief Verify SetAnalog frequency
245+
*/
246+
TEST_IFX(analogio_pwm, test_analog_set_fz)
247+
{
248+
analogWriteResolution(16); // Set resolution to 16 bits
249+
analogWrite(PWM_PIN_OUTPUT, 32767); // Set duty of 50 percent
250+
251+
const float frequency[] = {1, 50, 5000, 50000};
252+
for(size_t i=0; i< sizeof(frequency)/sizeof(frequency[i]); i++)
253+
{
254+
// Set different frequencies and verify the output
255+
setAnalogWriteFrequency(PWM_PIN_OUTPUT, frequency[i]);
256+
delay(1000); // Wait for the signal to stabilize
257+
feedback_measurement_handler();
258+
TEST_ASSERT_FLOAT_WITHIN(TOLERANCE_FREQUENCY, frequency[i], measured_frequency_hz);
259+
}
260+
}
261+
243262
/**
244263
* @brief Bundle all tests to be executed for this test group.
245264
*/
@@ -253,6 +272,7 @@ TEST_GROUP_RUNNER(analogio_pwm)
253272
RUN_TEST_CASE(analogio_pwm, test_analog_write_pwm_16_bit_resolution);
254273
RUN_TEST_CASE(analogio_pwm, test_analog_write_pwm_100_percentage_dutycycle);
255274
RUN_TEST_CASE(analogio_pwm, test_analog_write_pwm_0_percentage_dutycycle);
275+
RUN_TEST_CASE(analogio_pwm, test_analog_set_fz);
256276

257277
analogio_pwm_suite_teardown();
258278
}

0 commit comments

Comments
 (0)