MIT Motor Controller Code Analyze
Clock Tree

NVIC Settings

PowerStage PWM Generation


Current Sampling

Encoder

The Commutation Loop
Last updated






Last updated
HAL_NVIC_SetPriority(PWM_ISR, 0x0,0x0); // commutation > communication
HAL_NVIC_SetPriority(CAN_ISR, 0x01, 0x01);HAL_GPIO_WritePin(ENC_CS, GPIO_PIN_RESET ); // CS low
HAL_SPI_TransmitReceive(&ENC_SPI, (uint8_t*)encoder->spi_tx_buff, (uint8_t *)encoder->spi_rx_buff, 1, 100);
while( ENC_SPI.State == HAL_SPI_STATE_BUSY ); // wait for transmission complete
HAL_GPIO_WritePin(ENC_CS, GPIO_PIN_SET ); // CS highvoid TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
//HAL_GPIO_WritePin(LED, GPIO_PIN_SET ); // Useful for timing
/* Sample ADCs */
analog_sample(&controller);
/* Sample position sensor */
ps_sample(&comm_encoder, DT);
/* Run Finite State Machine */
run_fsm(&state);
/* Check for CAN messages */
can_tx_rx();
/* increment loop count */
controller.loop_count++;
//HAL_GPIO_WritePin(LED, GPIO_PIN_RESET );
/* USER CODE END TIM1_UP_TIM10_IRQn 0 */
HAL_TIM_IRQHandler(&htim1);
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
/* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}