|
|
|
|
@ -96,7 +96,7 @@ volatile uint8_t uart_buf[10];
|
|
|
|
|
|
|
|
|
|
void DMA1_Channel1_IRQHandler() {
|
|
|
|
|
DMA1->IFCR = DMA_IFCR_CTCIF1;
|
|
|
|
|
|
|
|
|
|
HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
|
|
|
|
|
/*
|
|
|
|
|
uart_buf[0] = 0xff;
|
|
|
|
|
uart_buf[1] = adc_buffer.r_dc1 - 1850 + 127;
|
|
|
|
|
@ -119,10 +119,8 @@ void DMA1_Channel1_IRQHandler(){
|
|
|
|
|
|
|
|
|
|
if(adc_buffer.l_dc2 > 1950) {
|
|
|
|
|
LEFT_TIM->BDTR &= ~TIM_BDTR_MOE;
|
|
|
|
|
HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
|
|
|
|
|
} else {
|
|
|
|
|
LEFT_TIM->BDTR |= TIM_BDTR_MOE;
|
|
|
|
|
HAL_GPIO_WritePin(LED_PORT, LED_PIN, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(adc_buffer.r_dc1 > 1950) {
|
|
|
|
|
@ -139,13 +137,13 @@ void DMA1_Channel1_IRQHandler(){
|
|
|
|
|
int vr = 0;
|
|
|
|
|
int wr = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t hall_ul = HAL_GPIO_ReadPin(LEFT_HALL_U_PORT, LEFT_HALL_U_PIN);
|
|
|
|
|
uint8_t hall_vl = HAL_GPIO_ReadPin(LEFT_HALL_V_PORT, LEFT_HALL_V_PIN);
|
|
|
|
|
uint8_t hall_wl = HAL_GPIO_ReadPin(LEFT_HALL_W_PORT, LEFT_HALL_W_PIN);
|
|
|
|
|
uint8_t hall_ul = !(LEFT_HALL_U_PORT->IDR & LEFT_HALL_U_PIN);
|
|
|
|
|
uint8_t hall_vl = !(LEFT_HALL_V_PORT->IDR & LEFT_HALL_V_PIN);
|
|
|
|
|
uint8_t hall_wl = !(LEFT_HALL_W_PORT->IDR & LEFT_HALL_W_PIN);
|
|
|
|
|
|
|
|
|
|
uint8_t hall_ur = HAL_GPIO_ReadPin(RIGHT_HALL_U_PORT, RIGHT_HALL_U_PIN);
|
|
|
|
|
uint8_t hall_vr = HAL_GPIO_ReadPin(RIGHT_HALL_V_PORT, RIGHT_HALL_V_PIN);
|
|
|
|
|
uint8_t hall_wr = HAL_GPIO_ReadPin(RIGHT_HALL_W_PORT, RIGHT_HALL_W_PIN);
|
|
|
|
|
uint8_t hall_ur = !(RIGHT_HALL_U_PORT->IDR & RIGHT_HALL_U_PIN);
|
|
|
|
|
uint8_t hall_vr = !(RIGHT_HALL_V_PORT->IDR & RIGHT_HALL_V_PIN);
|
|
|
|
|
uint8_t hall_wr = !(RIGHT_HALL_W_PORT->IDR & RIGHT_HALL_W_PIN);
|
|
|
|
|
|
|
|
|
|
uint8_t halll = hall_ul * 1 + hall_vl * 2 + hall_wl * 4;
|
|
|
|
|
posl = hall_to_pos[halll];
|
|
|
|
|
@ -178,7 +176,6 @@ void DMA1_Channel1_IRQHandler(){
|
|
|
|
|
block(pwml, posl, &ul, &vl, &wl);
|
|
|
|
|
block(pwmr, posr, &ur, &vr, &wr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LEFT_TIM->LEFT_TIM_U = CLAMP(ul + pwm_res / 2, 0, pwm_res);
|
|
|
|
|
LEFT_TIM->LEFT_TIM_V = CLAMP(vl + pwm_res / 2, 0, pwm_res);
|
|
|
|
|
LEFT_TIM->LEFT_TIM_W = CLAMP(wl + pwm_res / 2, 0, pwm_res);
|
|
|
|
|
@ -186,13 +183,12 @@ void DMA1_Channel1_IRQHandler(){
|
|
|
|
|
RIGHT_TIM->RIGHT_TIM_U = CLAMP(ur + pwm_res / 2, 0, pwm_res);
|
|
|
|
|
RIGHT_TIM->RIGHT_TIM_V = CLAMP(vr + pwm_res / 2, 0, pwm_res);
|
|
|
|
|
RIGHT_TIM->RIGHT_TIM_W = CLAMP(wr + pwm_res / 2, 0, pwm_res);
|
|
|
|
|
HAL_GPIO_WritePin(LED_PORT, LED_PIN, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int milli_vel_error_sum = 0;
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
|
HAL_Init();
|
|
|
|
|
__HAL_RCC_AFIO_CLK_ENABLE();
|
|
|
|
|
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
|
|
|
|
|
@ -226,8 +222,7 @@ int main(void)
|
|
|
|
|
HAL_ADC_Start(&hadc1);
|
|
|
|
|
HAL_ADC_Start(&hadc2);
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
while(1) {
|
|
|
|
|
HAL_Delay(0);
|
|
|
|
|
// int milli_cur = 3000;
|
|
|
|
|
// int milli_volt = milli_cur * MILLI_R / 1000;// + vel * MILLI_PSI * 141;
|
|
|
|
|
@ -252,9 +247,7 @@ int main(void)
|
|
|
|
|
|
|
|
|
|
/** System Clock Configuration
|
|
|
|
|
*/
|
|
|
|
|
void SystemClock_Config(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
void SystemClock_Config(void) {
|
|
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
|
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
|
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
|
|
|
|
@ -271,8 +264,7 @@ void SystemClock_Config(void)
|
|
|
|
|
|
|
|
|
|
/**Initializes the CPU, AHB and APB busses clocks
|
|
|
|
|
*/
|
|
|
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
|
|
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
|
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
|
|
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
|
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
|
|
|
|