static void meca_crimp_task(void * arg) { (void)arg; while(1) { crimp_current = platform_adc_get_mV(PLATFORM_ADC_CH0); if(crimp_disable) { platform_gpio_clear(PLATFORM_GPIO1); cocobot_asserv_pid_reset(&pid); } else { platform_gpio_set(PLATFORM_GPIO1); cocobot_asserv_pid_set_input(&pid, crimp_target); cocobot_asserv_pid_set_feedback(&pid, crimp_current); cocobot_asserv_pid_compute(&pid); int32_t output = cocobot_asserv_pid_get_output(&pid); last_output = output; cocobot_asserv_pid_compute(&pid); if(output > 0) { if(output > 0xFFFF) { output = 0xFFFF; } platform_gpio_clear(PLATFORM_GPIO6); mcual_timer_set_duty_cycle(MCUAL_TIMER1, MCUAL_TIMER_CHANNEL4, output); } else { output = -output; if(output > 0xFFFF) { output = 0xFFFF; } platform_gpio_set(PLATFORM_GPIO6); mcual_timer_set_duty_cycle(MCUAL_TIMER1, MCUAL_TIMER_CHANNEL4, 0xFFFF - output); } } vTaskDelay(50 / portTICK_PERIOD_MS); } }
// Count one second void TIM2_IRQHandler(void) { if(TIM_GetITStatus(TIM2,TIM_IT_Update) == SET) { elapsed_time++; if (elapsed_time>=88) { //disable_power_relay(); platform_gpio_set(GPIO_RELAIS); platform_led_toggle(PLATFORM_LED5); } TIM_ClearFlag(TIM2, TIM_FLAG_Update); } }