Skip to content

Commit 80aac69

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

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/corelibs/analogio/test_analogio_pwm.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,36 @@ static TEST_TEAR_DOWN(analogio_pwm) {
120120

121121
}
122122

123+
/**
124+
* @brief Verify SetAnalog frequency.
125+
*/
126+
127+
TEST_IFX(analogio_pwm, test_analog_set_fz)
128+
{
129+
//Set the frequency followed by a analogWrite
130+
analogWriteResolution(16);
131+
setAnalogWriteFrequency(PWM_PIN_OUTPUT, 100);
132+
delay(1000);
133+
analogWrite(PWM_PIN_OUTPUT, 32767);
134+
delay(1000);
135+
feedback_measurement_handler();
136+
TEST_ASSERT_FLOAT_WITHIN(TOLERANCE_FREQUENCY, 100, measured_frequency_hz);
137+
138+
const float frequency[] = {1, 50, 5000, 50000};
139+
140+
for(size_t i=0; i< sizeof(frequency)/sizeof(frequency[i]); i++)
141+
{
142+
// Set different frequencies and verify the output
143+
setAnalogWriteFrequency(PWM_PIN_OUTPUT, frequency[i]);
144+
delay(1000); // Wait for the signal to stabilize
145+
feedback_measurement_handler();
146+
TEST_ASSERT_FLOAT_WITHIN(TOLERANCE_FREQUENCY, frequency[i], measured_frequency_hz);
147+
}
148+
149+
setAnalogWriteFrequency(PWM_PIN_OUTPUT, 1000); //set back to default fz
150+
delay(1000);
151+
}
152+
123153
/**
124154
* @brief Verify PWM duty cycle for various percentages (25%, 50%, 75%) with default 8-bit resolution.
125155
*/
@@ -247,6 +277,7 @@ TEST_GROUP_RUNNER(analogio_pwm)
247277
{
248278
analogio_pwm_suite_setup();
249279

280+
RUN_TEST_CASE(analogio_pwm, test_analog_set_fz);
250281
RUN_TEST_CASE(analogio_pwm, test_analog_write_pwm_8_bit_resolution);
251282
RUN_TEST_CASE(analogio_pwm, test_analog_write_pwm_10_bit_resolution);
252283
RUN_TEST_CASE(analogio_pwm, test_analog_write_pwm_12_bit_resolution);

0 commit comments

Comments
 (0)