|
|
@@ -26,6 +26,10 @@
|
|
|
#define TEST_SYNC_GPIO (21)
|
|
|
#define TEST_CAP_GPIO (21)
|
|
|
|
|
|
+#define MCPWM_TEST_GROUP_CLK_HZ (SOC_MCPWM_BASE_CLK_HZ / 16)
|
|
|
+#define MCPWM_TEST_TIMER_CLK_HZ (MCPWM_TEST_GROUP_CLK_HZ / 10)
|
|
|
+
|
|
|
+
|
|
|
static mcpwm_dev_t *MCPWM[2] = {&MCPWM0, &MCPWM1}; // interrupt handling still lacks API to get/clear pending event, currently we have to read/write interrupt register
|
|
|
const static mcpwm_io_signals_t pwma[] = {MCPWM0A, MCPWM1A, MCPWM2A};
|
|
|
const static mcpwm_io_signals_t pwmb[] = {MCPWM0B, MCPWM1B, MCPWM2B};
|
|
|
@@ -67,7 +71,8 @@ static esp_err_t test_mcpwm_gpio_init(mcpwm_unit_t mcpwm_num, mcpwm_io_signals_t
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
-static void mcpwm_setup_testbench(mcpwm_unit_t group, mcpwm_timer_t timer, uint32_t pwm_freq, float pwm_duty)
|
|
|
+static void mcpwm_setup_testbench(mcpwm_unit_t group, mcpwm_timer_t timer, uint32_t pwm_freq, float pwm_duty,
|
|
|
+ unsigned long int group_resolution, unsigned long int timer_resolution)
|
|
|
{
|
|
|
// PWMA <--> PCNT UNIT0
|
|
|
pcnt_config_t pcnt_config = {
|
|
|
@@ -100,6 +105,8 @@ static void mcpwm_setup_testbench(mcpwm_unit_t group, mcpwm_timer_t timer, uint3
|
|
|
.counter_mode = MCPWM_UP_COUNTER,
|
|
|
.duty_mode = MCPWM_DUTY_MODE_0,
|
|
|
};
|
|
|
+ mcpwm_group_set_resolution(group, group_resolution);
|
|
|
+ mcpwm_timer_set_resolution(group, timer, timer_resolution);
|
|
|
TEST_ESP_OK(mcpwm_init(group, timer, &pwm_config));
|
|
|
}
|
|
|
|
|
|
@@ -115,24 +122,24 @@ static uint32_t mcpwm_pcnt_get_pulse_number(pcnt_unit_t pwm_pcnt_unit, int captu
|
|
|
return (uint32_t)count_value;
|
|
|
}
|
|
|
|
|
|
-static void mcpwm_timer_duty_test(mcpwm_unit_t unit, mcpwm_timer_t timer)
|
|
|
+static void mcpwm_timer_duty_test(mcpwm_unit_t unit, mcpwm_timer_t timer, unsigned long int group_resolution, unsigned long int timer_resolution)
|
|
|
{
|
|
|
- mcpwm_setup_testbench(unit, timer, 1000, 50.0);
|
|
|
+ mcpwm_setup_testbench(unit, timer, 1000, 50.0, group_resolution, timer_resolution);
|
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
|
|
|
|
TEST_ESP_OK(mcpwm_set_duty(unit, timer, MCPWM_OPR_A, 10.0));
|
|
|
TEST_ESP_OK(mcpwm_set_duty(unit, timer, MCPWM_OPR_B, 20.0));
|
|
|
- TEST_ASSERT_EQUAL_FLOAT(10.0, mcpwm_get_duty(unit, timer, MCPWM_OPR_A));
|
|
|
- TEST_ASSERT_EQUAL_FLOAT(20.0, mcpwm_get_duty(unit, timer, MCPWM_OPR_B));
|
|
|
+ TEST_ASSERT_FLOAT_WITHIN(0.1, 10.0, mcpwm_get_duty(unit, timer, MCPWM_OPR_A));
|
|
|
+ TEST_ASSERT_FLOAT_WITHIN(0.1, 20.0, mcpwm_get_duty(unit, timer, MCPWM_OPR_B));
|
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
|
|
|
|
TEST_ESP_OK(mcpwm_set_duty(unit, timer, MCPWM_OPR_A, 55.5f));
|
|
|
TEST_ESP_OK(mcpwm_set_duty_type(unit, timer, MCPWM_OPR_A, MCPWM_DUTY_MODE_0));
|
|
|
- TEST_ASSERT_EQUAL_FLOAT(55.5, mcpwm_get_duty(unit, timer, MCPWM_OPR_A));
|
|
|
+ TEST_ASSERT_FLOAT_WITHIN(0.1, 55.5, mcpwm_get_duty(unit, timer, MCPWM_OPR_A));
|
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
|
|
|
|
TEST_ESP_OK(mcpwm_set_duty_in_us(unit, timer, MCPWM_OPR_B, 500));
|
|
|
- TEST_ASSERT_EQUAL_FLOAT(50.0, mcpwm_get_duty(unit, timer, MCPWM_OPR_B));
|
|
|
+ TEST_ASSERT_INT_WITHIN(5, 500, mcpwm_get_duty_in_us(unit, timer, MCPWM_OPR_B));
|
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
|
|
|
|
TEST_ESP_OK(mcpwm_stop(unit, timer));
|
|
|
@@ -143,7 +150,8 @@ TEST_CASE("MCPWM duty test", "[mcpwm]")
|
|
|
{
|
|
|
for (int i = 0; i < SOC_MCPWM_GROUPS; i++) {
|
|
|
for (int j = 0; j < SOC_MCPWM_TIMERS_PER_GROUP; j++) {
|
|
|
- mcpwm_timer_duty_test(i, j);
|
|
|
+ mcpwm_timer_duty_test(i, j, MCPWM_TEST_GROUP_CLK_HZ, MCPWM_TEST_TIMER_CLK_HZ);
|
|
|
+ mcpwm_timer_duty_test(i, j, MCPWM_TEST_GROUP_CLK_HZ / 2, MCPWM_TEST_TIMER_CLK_HZ * 2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -154,7 +162,7 @@ static void mcpwm_start_stop_test(mcpwm_unit_t unit, mcpwm_timer_t timer)
|
|
|
{
|
|
|
uint32_t pulse_number = 0;
|
|
|
|
|
|
- mcpwm_setup_testbench(unit, timer, 1000, 50.0); // Period: 1000us, 1ms
|
|
|
+ mcpwm_setup_testbench(unit, timer, 1000, 50.0, MCPWM_TEST_GROUP_CLK_HZ, MCPWM_TEST_TIMER_CLK_HZ); // Period: 1000us, 1ms
|
|
|
// count the pulse number within 100ms
|
|
|
pulse_number = mcpwm_pcnt_get_pulse_number(TEST_PWMA_PCNT_UNIT, 100);
|
|
|
TEST_ASSERT_INT_WITHIN(2, 100, pulse_number);
|
|
|
@@ -187,7 +195,7 @@ TEST_CASE("MCPWM start and stop test", "[mcpwm]")
|
|
|
|
|
|
static void mcpwm_deadtime_test(mcpwm_unit_t unit, mcpwm_timer_t timer)
|
|
|
{
|
|
|
- mcpwm_setup_testbench(unit, timer, 1000, 50.0); // Period: 1000us, 1ms
|
|
|
+ mcpwm_setup_testbench(unit, timer, 1000, 50.0, MCPWM_TEST_GROUP_CLK_HZ, MCPWM_TEST_TIMER_CLK_HZ); // Period: 1000us, 1ms
|
|
|
mcpwm_deadtime_type_t deadtime_type[] = {MCPWM_BYPASS_RED, MCPWM_BYPASS_FED, MCPWM_ACTIVE_HIGH_MODE,
|
|
|
MCPWM_ACTIVE_LOW_MODE, MCPWM_ACTIVE_HIGH_COMPLIMENT_MODE, MCPWM_ACTIVE_LOW_COMPLIMENT_MODE,
|
|
|
MCPWM_ACTIVE_RED_FED_FROM_PWMXA, MCPWM_ACTIVE_RED_FED_FROM_PWMXB
|
|
|
@@ -220,7 +228,7 @@ static void mcpwm_carrier_test(mcpwm_unit_t unit, mcpwm_timer_t timer, mcpwm_car
|
|
|
{
|
|
|
uint32_t pulse_number = 0;
|
|
|
|
|
|
- mcpwm_setup_testbench(unit, timer, 1000, 50.0);
|
|
|
+ mcpwm_setup_testbench(unit, timer, 1000, 50.0, MCPWM_TEST_GROUP_CLK_HZ, MCPWM_TEST_TIMER_CLK_HZ);
|
|
|
mcpwm_set_signal_high(unit, timer, MCPWM_GEN_A);
|
|
|
mcpwm_set_signal_high(unit, timer, MCPWM_GEN_B);
|
|
|
TEST_ESP_OK(mcpwm_carrier_enable(unit, timer));
|
|
|
@@ -276,7 +284,7 @@ static void mcpwm_fault_cbc_test(mcpwm_unit_t unit, mcpwm_timer_t timer)
|
|
|
mcpwm_fault_signal_t fault_sig = fault_sig_array[timer];
|
|
|
mcpwm_io_signals_t fault_io_sig = fault_io_sig_array[timer];
|
|
|
|
|
|
- mcpwm_setup_testbench(unit, timer, 1000, 50.0);
|
|
|
+ mcpwm_setup_testbench(unit, timer, 1000, 50.0, MCPWM_TEST_GROUP_CLK_HZ, MCPWM_TEST_TIMER_CLK_HZ);
|
|
|
TEST_ESP_OK(test_mcpwm_gpio_init(unit, fault_io_sig, TEST_FAULT_GPIO));
|
|
|
gpio_set_level(TEST_FAULT_GPIO, 0);
|
|
|
TEST_ESP_OK(mcpwm_fault_init(unit, MCPWM_HIGH_LEVEL_TGR, fault_sig));
|
|
|
@@ -312,7 +320,7 @@ static void mcpwm_fault_ost_test(mcpwm_unit_t unit, mcpwm_timer_t timer)
|
|
|
mcpwm_fault_signal_t fault_sig = fault_sig_array[timer];
|
|
|
mcpwm_io_signals_t fault_io_sig = fault_io_sig_array[timer];
|
|
|
|
|
|
- mcpwm_setup_testbench(unit, timer, 1000, 50.0);
|
|
|
+ mcpwm_setup_testbench(unit, timer, 1000, 50.0, MCPWM_TEST_GROUP_CLK_HZ, MCPWM_TEST_TIMER_CLK_HZ);
|
|
|
TEST_ESP_OK(test_mcpwm_gpio_init(unit, fault_io_sig, TEST_FAULT_GPIO));
|
|
|
gpio_set_level(TEST_FAULT_GPIO, 0);
|
|
|
TEST_ESP_OK(mcpwm_fault_init(unit, MCPWM_HIGH_LEVEL_TGR, fault_sig));
|
|
|
@@ -345,7 +353,7 @@ static void mcpwm_sync_test(mcpwm_unit_t unit, mcpwm_timer_t timer)
|
|
|
mcpwm_sync_signal_t sync_sig = sync_sig_array[timer];
|
|
|
mcpwm_io_signals_t sync_io_sig = sync_io_sig_array[timer];
|
|
|
|
|
|
- mcpwm_setup_testbench(unit, timer, 1000, 50.0);
|
|
|
+ mcpwm_setup_testbench(unit, timer, 1000, 50.0, MCPWM_TEST_GROUP_CLK_HZ, MCPWM_TEST_TIMER_CLK_HZ);
|
|
|
TEST_ESP_OK(test_mcpwm_gpio_init(unit, sync_io_sig, TEST_SYNC_GPIO));
|
|
|
gpio_set_level(TEST_SYNC_GPIO, 0);
|
|
|
|