@@ -104,8 +104,10 @@ TEST_GROUP(analogio_pwm);
104104/* *
105105 * @brief Setup method called by Unity before every test in this test group.
106106 */
107- static TEST_SETUP (analogio_pwm) {
107+ static TEST_SETUP (analogio_pwm) {
108108 interrupts ();
109+ setAnalogWriteFrequency (PWM_PIN_OUTPUT, PWM_FREQUENCY_HZ); // set back to default fz
110+ delay (1000 );
109111 // Reset the measurement variables
110112 start_time = 0 ;
111113 high_time = 0 ;
@@ -130,24 +132,21 @@ TEST_IFX(analogio_pwm, test_analog_set_fz)
130132 analogWriteResolution (16 );
131133 setAnalogWriteFrequency (PWM_PIN_OUTPUT, 100 );
132134 delay (1000 );
135+ // 32767 for 50% duty cycle
133136 analogWrite (PWM_PIN_OUTPUT, 32767 );
134137 delay (1000 );
135138 feedback_measurement_handler ();
136139 TEST_ASSERT_FLOAT_WITHIN (TOLERANCE_FREQUENCY, 100 , measured_frequency_hz);
137140
138- const float frequency[] = {1 , 50 , 5000 , 50000 };
139-
140- for (size_t i=0 ; i< sizeof (frequency)/sizeof (frequency[i]); i++)
141+ // Frequency array in test_config.h
142+ for (size_t i=0 ; i< sizeof (test_pwm_frequencies)/sizeof (test_pwm_frequencies[i]); i++)
141143 {
142144 // Set different frequencies and verify the output
143- setAnalogWriteFrequency (PWM_PIN_OUTPUT, frequency [i]);
145+ setAnalogWriteFrequency (PWM_PIN_OUTPUT, test_pwm_frequencies [i]);
144146 delay (1000 ); // Wait for the signal to stabilize
145147 feedback_measurement_handler ();
146- TEST_ASSERT_FLOAT_WITHIN (TOLERANCE_FREQUENCY, frequency [i], measured_frequency_hz);
148+ TEST_ASSERT_FLOAT_WITHIN (TOLERANCE_FREQUENCY, test_pwm_frequencies [i], measured_frequency_hz);
147149 }
148-
149- setAnalogWriteFrequency (PWM_PIN_OUTPUT, PWM_FREQUENCY_HZ); // set back to default fz
150- delay (1000 );
151150}
152151
153152/* *
0 commit comments