LoRaWAN payload decoder
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Программирование
- Просмотров: 161
STM32 not working without JTAG/ STLINK
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Программирование микроконтроллеров
- Просмотров: 165
Step motor wires/ шаговый мотор - провода, A+, A-, B+, B-, A1, A2, B1, B2
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Электроника / cхемотехника
- Просмотров: 200
STM32G031: TIM1 PWM LL: exact pulses to generate
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Программирование микроконтроллеров
- Просмотров: 176
void runCmdFromUart(void){ uint32_t frequency = 0; uint32_t ARR_reg_val = 0; uint32_t PSC_reg_val = 7; static uint32_t pulses = 1000; //im ms if(receiveBuffer[0] == 'f'){ //frequency frequency += (receiveBuffer[1] - 0x30) *100000; frequency += (receiveBuffer[2] - 0x30) *10000; frequency += (receiveBuffer[3] - 0x30) *1000; frequency += (receiveBuffer[4] - 0x30) *100; frequency += (receiveBuffer[5] - 0x30) *10; frequency += receiveBuffer[6] - 0x30; if(frequency > 10000) PSC_reg_val = 0; else if(frequency > 100) PSC_reg_val = 7; else PSC_reg_val = 4095; ARR_reg_val = (BASE_FREQ/(PSC_reg_val+1))/frequency; LL_TIM_WriteReg(TIM1, PSC, PSC_reg_val); LL_TIM_WriteReg(TIM1, ARR, ARR_reg_val); CountTim1P = pulses-1; LL_TIM_WriteReg(TIM1, CCR1, 0); LL_TIM_OC_SetCompareCH4(TIM1, (ARR_reg_val/2)); //50% PWM, 100 kHz } if(receiveBuffer[0] == 'd'){ if(receiveBuffer[1] == '1') LL_GPIO_ResetOutputPin(DIR_GPIO_Port,DIR_Pin); else if(receiveBuffer[1] == '0') LL_GPIO_SetOutputPin(DIR_GPIO_Port,DIR_Pin); } if(receiveBuffer[0] == 'e'){ if(receiveBuffer[1] == '1') LL_GPIO_ResetOutputPin(ENABLE_GPIO_Port,ENABLE_Pin); else if(receiveBuffer[1] == '0') LL_GPIO_SetOutputPin(ENABLE_GPIO_Port,ENABLE_Pin); } if(receiveBuffer[0] == 'p'){ //pulses pulses = 0; pulses += (receiveBuffer[1] - 0x30) *100000000; pulses += (receiveBuffer[2] - 0x30) *10000000; pulses += (receiveBuffer[3] - 0x30) *1000000; pulses += (receiveBuffer[4] - 0x30) *100000; pulses += (receiveBuffer[5] - 0x30) *10000; pulses += (receiveBuffer[6] - 0x30) *1000; pulses += (receiveBuffer[7] - 0x30) *100; pulses += (receiveBuffer[8] - 0x30) *10; pulses += receiveBuffer[9] - 0x30; } }
void TIM1_CC_IRQHandler(void) { /* USER CODE BEGIN TIM1_CC_IRQn 0 */ /* USER CODE END TIM1_CC_IRQn 0 */ /* USER CODE BEGIN TIM1_CC_IRQn 1 */ LL_TIM_ClearFlag_CC1(TIM1); if(CountTim1P) CountTim1P--; else LL_TIM_OC_SetCompareCH4(TIM1, 0xFFFF); /* USER CODE END TIM1_CC_IRQn 1 */ }
STM32G031 LL library: freq. for control step motor appx. fast setup
- Информация о материале
- Автор: Super User
- Родительская категория: Заметки
- Категория: Программирование микроконтроллеров
- Просмотров: 185
/* USER CODE BEGIN 0 */ uint8_t receiveBuffer[BUFFER_UART_LEN]; #define BASE_FREQ 16000000 void runCmdFromUart(void){ uint32_t frequency = 0; uint32_t ARR_reg_val = 0; uint32_t PSC_reg_val = 7; if(receiveBuffer[0] == 'f'){ //frequency frequency += (receiveBuffer[1] - 0x30) *100000; frequency += (receiveBuffer[2] - 0x30) *10000; frequency += (receiveBuffer[3] - 0x30) *1000; frequency += (receiveBuffer[4] - 0x30) *100; frequency += (receiveBuffer[5] - 0x30) *10; frequency += receiveBuffer[6] - 0x30; if(frequency > 10000) PSC_reg_val = 0; else if(frequency > 100) PSC_reg_val = 7; else PSC_reg_val = 4095; ARR_reg_val = (BASE_FREQ/(PSC_reg_val+1))/frequency; LL_TIM_WriteReg(TIM1, PSC, PSC_reg_val); LL_TIM_WriteReg(TIM1, ARR, ARR_reg_val); LL_TIM_OC_SetCompareCH4(TIM1, (ARR_reg_val/2)); //50% PWM, 100 kHz } } /* USER CODE END 0 */
Страница 10 из 182