PWM Not working
Signed-off-by: linuxes_mojoworld@aleeas.com <linuxes_mojoworld@aleeas.com>
This commit is contained in:
parent
7aa3ff6af3
commit
267f4bace5
|
@ -77,23 +77,23 @@ motor_init(car_struct_t *car_struct)
|
||||||
gpio_set_function(PWM_PIN_RIGHT, GPIO_FUNC_PWM);
|
gpio_set_function(PWM_PIN_RIGHT, GPIO_FUNC_PWM);
|
||||||
|
|
||||||
car_struct->p_left_motor->pwm.slice_num
|
car_struct->p_left_motor->pwm.slice_num
|
||||||
= pwm_gpio_to_slice_num(PWM_PIN_LEFT);
|
= pwm_gpio_to_slice_num(0);
|
||||||
car_struct->p_right_motor->pwm.slice_num
|
car_struct->p_right_motor->pwm.slice_num
|
||||||
= pwm_gpio_to_slice_num(PWM_PIN_RIGHT);
|
= pwm_gpio_to_slice_num(0);
|
||||||
|
|
||||||
// NOTE: PWM clock is 125MHz for raspberrypi pico w by default
|
// NOTE: PWM clock is 125MHz for raspberrypi pico w by default
|
||||||
|
|
||||||
// 125MHz / 50 = 2500kHz
|
// 125MHz / 50 = 2500kHz
|
||||||
pwm_set_clkdiv(car_struct->p_left_motor->pwm.slice_num, PWM_CLK_DIV);
|
pwm_set_clkdiv(car_struct->p_left_motor->pwm.slice_num, PWM_CLK_DIV);
|
||||||
pwm_set_clkdiv(car_struct->p_right_motor->pwm.slice_num, PWM_CLK_DIV);
|
// pwm_set_clkdiv(car_struct->p_right_motor->pwm.slice_num, PWM_CLK_DIV);
|
||||||
|
|
||||||
// L289N can accept up to 40kHz
|
// L289N can accept up to 40kHz
|
||||||
// 2500kHz / 100 = 25kHz
|
// 2500kHz / 100 = 25kHz
|
||||||
pwm_set_wrap(car_struct->p_left_motor->pwm.slice_num, (PWM_WRAP - 1U));
|
pwm_set_wrap(car_struct->p_left_motor->pwm.slice_num, (PWM_WRAP - 1U));
|
||||||
pwm_set_wrap(car_struct->p_right_motor->pwm.slice_num, (PWM_WRAP - 1U));
|
// pwm_set_wrap(car_struct->p_right_motor->pwm.slice_num, (PWM_WRAP - 1U));
|
||||||
|
|
||||||
pwm_set_enabled(car_struct->p_left_motor->pwm.slice_num, true);
|
pwm_set_enabled(car_struct->p_left_motor->pwm.slice_num, true);
|
||||||
pwm_set_enabled(car_struct->p_right_motor->pwm.slice_num, true);
|
// pwm_set_enabled(car_struct->p_right_motor->pwm.slice_num, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -8,14 +8,16 @@ motor_control_task(void *params)
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
set_wheel_direction(DIRECTION_FORWARD);
|
set_wheel_direction(DIRECTION_FORWARD);
|
||||||
set_wheel_speed_synced(90u, car_struct);
|
set_wheel_speed_synced(99u, car_struct);
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
set_wheel_speed_synced(50u, car_struct);
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(10000));
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
|
|
||||||
revert_wheel_direction();
|
revert_wheel_direction();
|
||||||
set_wheel_speed_synced(90u, car_struct);
|
set_wheel_speed_synced(90u, car_struct);
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(10000));
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,30 +33,37 @@ void
|
||||||
motor_control_task(void *params)
|
motor_control_task(void *params)
|
||||||
{
|
{
|
||||||
car_struct_t *car_struct = (car_struct_t *)params;
|
car_struct_t *car_struct = (car_struct_t *)params;
|
||||||
|
car_struct->p_pid->use_pid = false;
|
||||||
set_wheel_direction(DIRECTION_FORWARD);
|
set_wheel_direction(DIRECTION_FORWARD);
|
||||||
set_wheel_speed_synced(90u, car_struct);
|
// set_wheel_speed_synced(50u, car_struct);
|
||||||
|
pwm_set_chan_level(car_struct->p_left_motor->pwm.slice_num,
|
||||||
|
car_struct->p_left_motor->pwm.channel,
|
||||||
|
50u);
|
||||||
|
// pwm_set_chan_level(car_struct->p_right_motor->pwm.slice_num,
|
||||||
|
// car_struct->p_right_motor->pwm.channel,
|
||||||
|
// 50u);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
uint8_t temp = check_line_touch(car_struct);
|
// uint8_t temp = check_line_touch(car_struct);
|
||||||
switch (temp)
|
// switch (temp)
|
||||||
{
|
// {
|
||||||
default:
|
// default:
|
||||||
break;
|
// break;
|
||||||
case 0b01:
|
// case 0b01:
|
||||||
car_struct->p_right_motor->speed.distance_cm
|
// car_struct->p_right_motor->speed.distance_cm
|
||||||
-= SLOT_DISTANCE_CM;
|
// -= SLOT_DISTANCE_CM;
|
||||||
break;
|
// break;
|
||||||
case 0b10:
|
// case 0b10:
|
||||||
car_struct->p_right_motor->speed.distance_cm
|
// car_struct->p_right_motor->speed.distance_cm
|
||||||
+= SLOT_DISTANCE_CM;
|
// += SLOT_DISTANCE_CM;
|
||||||
break;
|
// break;
|
||||||
case 0b11:
|
// case 0b11:
|
||||||
turn(DIRECTION_LEFT, 90u, 90u, car_struct);
|
// turn(DIRECTION_LEFT, 90u, 90u, car_struct);
|
||||||
set_wheel_direction(DIRECTION_FORWARD);
|
// set_wheel_direction(DIRECTION_FORWARD);
|
||||||
set_wheel_speed_synced(90u, car_struct);
|
// set_wheel_speed_synced(90u, car_struct);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(25));
|
vTaskDelay(pdMS_TO_TICKS(25));
|
||||||
}
|
}
|
||||||
|
@ -172,13 +179,13 @@ main(void)
|
||||||
sleep_ms(1000u);
|
sleep_ms(1000u);
|
||||||
|
|
||||||
// control task
|
// control task
|
||||||
// TaskHandle_t h_motor_turning_task_handle = NULL;
|
TaskHandle_t h_motor_turning_task_handle = NULL;
|
||||||
// xTaskCreate(motor_control_task,
|
xTaskCreate(motor_control_task,
|
||||||
// "motor_turning_task",
|
"motor_turning_task",
|
||||||
// configMINIMAL_STACK_SIZE,
|
configMINIMAL_STACK_SIZE,
|
||||||
// (void *)&car_struct,
|
(void *)&car_struct,
|
||||||
// PRIO,
|
PRIO,
|
||||||
// &h_motor_turning_task_handle);
|
&h_motor_turning_task_handle);
|
||||||
|
|
||||||
// obs task
|
// obs task
|
||||||
// TaskHandle_t h_obs_task_handle = NULL;
|
// TaskHandle_t h_obs_task_handle = NULL;
|
||||||
|
@ -190,13 +197,13 @@ main(void)
|
||||||
// &h_obs_task_handle);
|
// &h_obs_task_handle);
|
||||||
|
|
||||||
// turn task
|
// turn task
|
||||||
TaskHandle_t h_turn_task_handle = NULL;
|
// TaskHandle_t h_turn_task_handle = NULL;
|
||||||
xTaskCreate(turn_task,
|
// xTaskCreate(turn_task,
|
||||||
"turn_task",
|
// "turn_task",
|
||||||
configMINIMAL_STACK_SIZE,
|
// configMINIMAL_STACK_SIZE,
|
||||||
(void *)&car_struct,
|
// (void *)&car_struct,
|
||||||
PRIO,
|
// PRIO,
|
||||||
&h_turn_task_handle);
|
// &h_turn_task_handle);
|
||||||
|
|
||||||
// PID timer
|
// PID timer
|
||||||
struct repeating_timer pid_timer;
|
struct repeating_timer pid_timer;
|
||||||
|
|
Loading…
Reference in New Issue