int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_I2C3_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_TIM5_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); MX_TIM11_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start_IT(&htim11); // 100 msec timer initSonar( MAX_SONAR); initSerOutput(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ // >>>>> Sonar reading triggerSonar( COUPLE_0_2); HAL_Delay(49); triggerSonar( COUPLE_1_3); HAL_Delay(49); // <<<<< Sonar reading // >>>>> Serial Output convertMeasures(); sendMeasures(); // <<<<< Serial Output } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_RTC_Init(); MX_SPI2_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ encoderInit(); pwmInit(); // adcInit(); uartInit(); timInterruptInit(); gyroInit(GYROHIGH); calibrateGyro(); // rotaryRight(800); // HAL_Delay(500); // rotaryLeft(800); drive(VEL); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { HAL_Init(); Nucleo_BSP_Init(); MX_TIM3_Init(); HAL_TIM_Base_Start_IT(&htim3); while (1); }
int main(void) { HAL_Init(); Nucleo_BSP_Init(); MX_TIM3_Init(); HAL_TIM_OnePulse_Start(&htim3, TIM_CHANNEL_1); while (1); }
// --- Load and start FE PWM --- void startPWM_FE(uint16_t period, uint16_t width) { // Setup PWM timer MX_TIM3_Init(); htim3.Instance->CCR3 = width; htim3.Init.Period = period; HAL_TIM_Base_Init(&htim3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); }
int main(void) { int autorun; // double calcfreq; // double CurrentFreq = 144e6; /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); //MX_SPI1_Init(); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET); MX_TIM3_Init(); MX_TIM14_Init(); MX_USB_DEVICE_Init(); Morse_Init(); // prepare_pll(); // UpdateFrequencyRegisters(CurrentFreq, 50000000.0, 5000, 1, 1, &calcfreq); // PLL_Sync(); autorun = cmd_isautorun() ; /* Infinite loop */ while (1) { if (is_line_received()) { // Process received line cmd_proc(get_line_buffer()); } HAL_Delay(10); ar_count++; if ((ar_count > 1000) & (autorun>0)) { // Start Autorun cmd_autorun(autorun); cw_autorunning = 1; while(cw_autorunning) HAL_Delay(10); } } }
int main(void) { /* USER CODE BEGIN 1 */ SCB->VTOR = FLASH_START_SECTOR_ADDR; SEGGER_RTT_Init(); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_I2C2_Init(); MX_SPI1_Init(); MX_TIM3_Init(); MX_USART2_UART_Init(); MX_RTC_Init(); /* USER CODE BEGIN 2 */ //as7000_init(); /* USER CODE END 2 */ /* Call init function for freertos objects (in freertos.c) */ MX_FREERTOS_Init(); /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_COMP1_Init(); MX_COMP2_Init(); MX_I2C1_Init(); MX_TIM3_Init(); MX_USART1_UART_Init(); MX_ADC_Init(); MX_DMA_Init(); /* USER CODE BEGIN 2 */ init_all(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { period_time_check_flags(); // if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) != GPIO_PIN_RESET) // { // HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_10); // buzzer(beeps,1); // buzzer_speed(100); // } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ speed_counter++; } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_SPI1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM7_Init(); MX_TIM10_Init(); MX_TIM11_Init(); MX_TIM13_Init(); MX_TIM14_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); //Motor1 HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); //Motor2 HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); //Motor3 HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4); //Motor4 /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_IWDG_Init(); MX_SDADC1_Init(); MX_SDADC2_Init(); MX_TSC_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_SDADC3_Init(); MX_USB_DEVICE_Init(); MX_RTC_Init(); MX_TIM6_Init(); MX_TIM7_Init(); /* USER CODE BEGIN 2 */ Setup(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ loop(); } /* USER CODE END 3 */ }
int main(void) { USB_HIDDEVICE_Keyboard_t Keyboard_Data; /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM3_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ delay_ms(1000); // MX_USB_DEVICE_SendHIDAction(0x01); USB_HIDDEVICE_KeyboardStructInit(&Keyboard_Data); Keyboard_Data.Key1 = 0x01; USB_HIDDEVICE_KeyboardSend(&Keyboard_Data); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_USART2_UART_Init(); MX_USART3_UART_Init(); MX_TIM3_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start_IT(&htim3); HAL_UART_Transmit_DMA(&huart3,g_cUart3_Buff,BUFFSIZE); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ HAL_UART_Receive_DMA(&huart3,g_cUart3_Buff,BUFFSIZE); //HAL_UART_Transmit_IT(&huart3,g_cUart3_Buff,5); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { uint16_t IV[200]; float angle; HAL_Init(); Nucleo_BSP_Init(); MX_TIM3_Init(); for (uint8_t i = 0; i < 200; i++) { angle = ASR*(float)i; IV[i] = (uint16_t) rint(100 + 99*sinf(angle*(PI/180))); } HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_1, (uint32_t *)IV, 200); while (1); }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_TIM1_Init(); MX_TIM3_Init(); MX_ADC1_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ //Start PWM HAL_TIM_Base_Start(&htim1); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_ALL); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); HAL_Delay(100); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* System interrupt init*/ /* Sets the priority grouping field */ HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_I2C1_Init(); MX_I2S2_Init(); MX_I2S3_Init(); MX_SPI1_Init(); MX_SPI4_Init(); MX_TIM3_Init(); MX_USART2_UART_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /*## FatFS: Link the USER disk I/O driver ###############################*/ USER_DriverNum = FATFS_LinkDriver(&USER_Driver, USER_Path); /* USER CODE BEGIN 3 */ dabstick_loop(); // endless return 0; /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_ADC2_Init(); MX_DAC_Init(); MX_TIM2_Init(); MX_TIM3_Init(); /* USER CODE BEGIN 2 */ configure_modem(); acquisition_init(); acquisition_start(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); MX_SPI1_Init(); MX_TIM1_Init(); MX_TIM3_Init(); HAL_TIM_Base_Start(&htim1); static char buf[50]; NRF24L01_Reset(); NRF24L01_Initialize(); HAL_Delay(150); CX10_init(); HAL_Delay(50); CX10_bind(); while (1) { process_CX10(); HAL_Delay(6); } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC1_Init(); MX_ADC2_Init(); MX_TIM3_Init(); MX_TIM5_Init(); MX_USART2_UART_Init(); MX_USART3_UART_Init(); MX_USB_OTG_FS_PCD_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_RTC_Init(); //if(!(*(volatile uint32_t *) (BDCR_RTCEN_BB)))__HAL_RCC_RTC_ENABLE(); MX_TIM2_Init(); MX_TIM3_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ HAL_RTC_GetTime(&hrtc, &myTime, FORMAT_BIN); HAL_RTC_GetDate(&hrtc, &myDate, FORMAT_BIN); } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM3_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ if (data_ready) { USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*)rc_data, 10); data_ready = 0; } } /* USER CODE END 3 */ }
/* --- AOS Initialization --- */ void AOS_init(void) { /* MCU Configuration */ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Unlock the Flash Program Erase controller */ //HAL_FLASH_Unlock(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_UART_Init(); MX_TIM2_Init(); MX_TIM7_Init(); /* PWM Timers will override P1, P3 & P4 */ MX_TIM3_Init(); MX_TIM15_Init(); #ifndef TX MX_ADC_Init(); #endif /* AOS Initialization */ /* Startup indicator sequence */ blink(500); HAL_Delay(100); blink(100); HAL_Delay(100); blink(100); /* Initialize random seed for PRNG */ srand(atoi(_firmTime)); }
void board_Init(void) { /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Init Timer */ timer_init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ LED_Init(); MX_GPIO_Init(); //MX_I2C1_Init(); /* TODO: Init */ MX_I2C2_Init(); MX_SPI2_Init(); MX_SPI3_Init(); MX_TIM1_Init(); MX_TIM3_Init(); eUARTInit(&xUARTHandle, uartUARTx); }
int main(void) { HAL_Init(); Nucleo_BSP_Init(); MX_TIM3_Init(); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); /* Connect a LED to PA6 pin to see the fading effect */ uint16_t dutyCycle = HAL_TIM_ReadCapturedValue(&htim3, TIM_CHANNEL_1); while(1) { while(dutyCycle < __HAL_TIM_GET_AUTORELOAD(&htim3)) { __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, ++dutyCycle); HAL_Delay(1); } while(dutyCycle > 0) { __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, --dutyCycle); HAL_Delay(1); } } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM3_Init(); HAL_TIM_Base_Start_IT(&htim3); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5|GPIO_PIN_6, GPIO_PIN_RESET); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
/** * @brief The application entry point. * * @retval None */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_TIM3_Init(); //MX_IWDG_Init(); MX_TIM14_Init(); MX_TIM16_Init(); MX_TIM17_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM3_IRQn); HAL_TIM_Base_Start_IT(&htim3); // Seconds Counter startup duty HAL_TIM_Base_Start_IT(&htim14); HAL_TIM_Base_Stop_IT(&htim14); HAL_TIM_Base_Start_IT(&htim16); HAL_TIM_Base_Start_IT(&htim17); HAL_GPIO_WritePin(GPIOA, LED_RED_PIN, GPIO_PIN_RESET); ssd1306_Init(); current_cursor = exposition; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ //HAL_IWDG_Refresh(&hiwdg); if(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSE) HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN, GPIO_PIN_SET); else HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN, GPIO_PIN_RESET); if (update_screen_flag) { ssd1306_Fill(Black); ssd1306_UpdateScreen(); update_screen_flag = 0; } if (seconds_counter > STOP_TIME_SEC) //if more than 10 s need to stop { // Entering STOP Mode Procedure seconds_counter = 0; GPIO_InitTypeDef GPIO_InitStruct; ssd1306_WriteCommand(0xAE); // OLED Off GPIO_InitStruct.Pin = ENC_BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING_FALLING; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI4_15_IRQn); HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN|LED_RED_PIN|GATE_PIN|FOCUS_PIN, GPIO_PIN_RESET); HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE); // Exit from STOP Mode procedure SystemClock_Config(); ssd1306_WriteCommand(0xAF); // OLED On GPIO_InitStruct.Pin = ENC_BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); current_state = menu_navigation; } Menu(); if (current_state == running_timer || current_state == running_interval) { if(gate_flag) { // Reset Gate & Focus HAL_GPIO_WritePin(GPIOA, FOCUS_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GATE_PIN, GPIO_PIN_RESET); HAL_TIM_Base_Stop_IT(&htim14); HAL_Delay(500); __HAL_TIM_SET_COUNTER(&htim14, 0); HAL_TIM_Base_Start_IT(&htim14); gate_flag = 0; // If not last shot, go to Interval state if(tmp_num_shots != 0) { tmp_int_minutes = set_int_minutes; tmp_int_sec = set_int_sec; tmp_exp_minutes = set_exp_minutes; tmp_exp_sec = set_exp_sec; current_state = running_interval; HAL_GPIO_WritePin(GPIOA, LED_RED_PIN,GPIO_PIN_RESET); // 1s LED Off } else { HAL_TIM_Base_Stop_IT(&htim14); __HAL_TIM_SET_COUNTER(&htim14, 0); HAL_GPIO_WritePin(GPIOA, LED_RED_PIN,GPIO_PIN_RESET); // 1s LED Off tmp_exp_minutes = set_exp_minutes; tmp_exp_sec = set_exp_sec; current_state = menu_navigation; update_screen_flag = 1; } } } if (exiting_run) { HAL_TIM_Base_Stop_IT(&htim16); HAL_Delay(1000); exiting_run = 0; HAL_TIM_Base_Start_IT(&htim16); HAL_GPIO_WritePin(GPIOA, FOCUS_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GATE_PIN, GPIO_PIN_RESET); } } /* USER CODE END 3 */ }
void ultrasound_generator( uint32_t chanel ){ /* ##-1- Configure the TIM peripheral **************************************************************************** TIM2 Configuration: generate 4 PWM signals with 4 different duty cycles. In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1), since APB1 prescaler is equal to 1. TIM2CLK = PCLK1 PCLK1 = HCLK => TIM2CLK = HCLK = SystemCoreClock To get TIM2 counter clock at 16 MHz, the prescaler is computed as follows: Prescaler = (TIM2CLK / TIM2 counter clock) - 1 Prescaler = ((SystemCoreClock) /16 MHz) - 1 To get TIM2 output clock at 24 KHz, the period (ARR)) is computed as follows: ARR = (TIM2 counter clock / TIM2 output clock) - 1 = 665 TIM2 Channel1 duty cycle = (TIM2_CCR1/ TIM2_ARR + 1)* 100 = 50% ************************** 20KHz-> Prescaler = ( (48MHz) / 20KHz) - 1=799 30KHz-> Prescaler = ( (48MHz) / 30KHz) - 1=399 */ SystemClock_Config_48MHz(); MX_TIM3_Init(); HAL_TIM_PWM_Init(&htim3); sConfigOC.Pulse=0; HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 ); ///DCDC konverter engedélyezése (+15V) HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_1); HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_2); HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_3); HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_4); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4); for(int i=400; i < 700; i++){ //HAL_TIM_PWM_Stop(&htim3,chanel); __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,chanel, i); //HAL_TIM_OC_Init(&htim3); //TIM_OC2_SetConfig( TIM3, &sConfigOC); //HAL_TIM_PWM_Start( &htim3 , chanel ); HAL_Delay(30); } __HAL_TIM_SetCompare(&htim3,chanel, 0); HAL_TIM_PWM_Stop( &htim3 , chanel ); HAL_TIM_PWM_DeInit( &htim3 ); HAL_TIM_Base_DeInit(&htim3); GPIO_TIM3_OFF(); HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0); SystemClock_Config_8MHz(); }
void ultrasound (uint8_t bridge){ //ez a fv egyszerre csak egy hidat hajt meg! uint16_t i,old_i,temp_i,f; uint32_t CH1,CH2,CHx,CHy,tim,tim_now; //bridge1=0,bridge2=1-> hogy melyik hidat hajtsa meg if(bridge){ //bridge1 CH1=(uint32_t)TIM_CHANNEL_1; CH2=(uint32_t)TIM_CHANNEL_2; CHx=(uint32_t)TIM_CHANNEL_3; CHy=(uint32_t)TIM_CHANNEL_4; }else{ //bridge2 CH1=(uint32_t)TIM_CHANNEL_3; CH2=(uint32_t)TIM_CHANNEL_4; CHx=(uint32_t)TIM_CHANNEL_1; CHy=(uint32_t)TIM_CHANNEL_2; } SystemClock_Config_48MHz(); HAL_Delay(20); MX_TIM3_Init(); HAL_TIM_PWM_Init(&htim3); sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH1); sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH2); HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHx); HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHy); HAL_TIM_PWM_Start(&htim3, CH1); HAL_TIM_PWM_Start(&htim3, CH2); HAL_TIM_PWM_Start(&htim3, CHx); HAL_TIM_PWM_Start(&htim3, CHy); //csattanás csökkentés, 19khz kiadás eloszor HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0 ); // HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 ); //open drain kimenet,pch fet, //***************************************** /*for( i=900 ; i >= 620 ; i-=3){ __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,CH1, i); __HAL_TIM_SetCompare(&htim3,CH2, i); HAL_Delay(1); }*/ /*********************************** HAL_Delay(100); __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,CH1, i); __HAL_TIM_SetCompare(&htim3,CH2, i); HAL_Delay(1000);*/ HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 ); HAL_Delay(100); //19KHz-620 // 27KHz-440 old_i=i; for(uint8_t x=0; x < soundNum; x++){ // a következo hanghoz kis lépésenként jutunk, ígty nincs csattanás srand(HAL_GetTick()); i=(rand()%210)+440; //i=210+440; /* if( old_i < i){ // ha az új hang kissebb frekvenciájó -> nagyobb i for( temp_i=old_i ; i >= temp_i; temp_i++){ __HAL_TIM_SetAutoreload(&htim3,temp_i*2); __HAL_TIM_SetCompare(&htim3,CH1, temp_i); __HAL_TIM_SetCompare(&htim3,CH2, temp_i); HAL_Delay(1); } }else{ //ha az uj hang nagypbb frekvenciáju-> kisebb i for( temp_i=old_i ; i <= temp_i; temp_i--){ __HAL_TIM_SetAutoreload(&htim3,temp_i*2); __HAL_TIM_SetCompare(&htim3,CH1, temp_i); __HAL_TIM_SetCompare(&htim3,CH2, temp_i); HAL_Delay(1); } } */ __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,CH1, i); __HAL_TIM_SetCompare(&htim3,CH2, i); old_i=i; tim=HAL_GetTick(); //jelenlegi ido lekérdezés tim_now=HAL_GetTick(); f=i%5; while( sDelay >= (tim_now-tim) && tim <= tim_now ){ ///késleltetés if(f==3){ for(temp_i=0 ; temp_i < 10 ;temp_i++){ //itt nagyobb lesz a frekvencia i+=1; __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,CH1, i); __HAL_TIM_SetCompare(&htim3,CH2, i); HAL_Delay(1); } for(temp_i=0 ; temp_i < 10 ;temp_i++){ //itt kissebb lesz a frekvencia i-=1; __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,CH1, i); __HAL_TIM_SetCompare(&htim3,CH2, i); HAL_Delay(1); } } tim_now=HAL_GetTick(); } // HAL_Delay(sDelay); randCount++; } //csattanás csökkentés, 19khz kiadás eloszor HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0); for( i=i ; i <= 900 ; i+=3){ __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,CH1, i); __HAL_TIM_SetCompare(&htim3,CH2, i); HAL_Delay(1); } HAL_Delay(100); HAL_TIM_PWM_Stop( &htim3 , CH1 ); HAL_TIM_PWM_Stop( &htim3 , CH2 ); HAL_TIM_PWM_Stop( &htim3 , CHx ); HAL_TIM_PWM_Stop( &htim3 , CHy ); HAL_TIM_PWM_DeInit( &htim3 ); // HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 1); //open drain kimenet,pch fet, HAL_Delay(100); SystemClock_Config_8MHz(); GPIO_TIM3_OFF(); HAL_Delay(100); }
void beeps (uint8_t num,uint8_t bridge){ uint16_t temp1; uint32_t CH1,CH2,CHx,CHy; // HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 ); //open drain kimenet,pch fet, HAL_Delay(100); HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 ); //open drain kimenet,pch fet, //bridge1=0,bridge2=1-> hogy melyik hidat hajtsa meg if(bridge){ //bridge1 CH1=(uint32_t)TIM_CHANNEL_1; CH2=(uint32_t)TIM_CHANNEL_2; CHx=(uint32_t)TIM_CHANNEL_3; CHy=(uint32_t)TIM_CHANNEL_4; }else{ //bridge2 CH1=(uint32_t)TIM_CHANNEL_3; CH2=(uint32_t)TIM_CHANNEL_4; CHx=(uint32_t)TIM_CHANNEL_1; CHy=(uint32_t)TIM_CHANNEL_2; } //SystemClock_Config_48MHz(); MX_TIM3_Init(); HAL_TIM_PWM_Init(&htim3); sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH1); sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CH2); HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHx); HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , CHy); HAL_TIM_PWM_Start(&htim3, CH1); HAL_TIM_PWM_Start(&htim3, CH2); HAL_TIM_PWM_Start(&htim3, CHx); HAL_TIM_PWM_Start(&htim3, CHy); __HAL_TIM_SetCompare(&htim3,CH2,0); for( uint8_t i=0 ; i<num ; i++){ temp1=3500; for(uint8_t ii=0; ii<10 ; ii++){ __HAL_TIM_SetAutoreload(&htim3,temp1*2); __HAL_TIM_SetCompare(&htim3,CH1, temp1); //__HAL_TIM_SetCompare(&htim3,CH2,temp1); temp1 -=6; HAL_Delay(18); }/* for(uint8_t ii=0; ii<10 ; ii++){ __HAL_TIM_SetAutoreload(&htim3,temp1*2); __HAL_TIM_SetCompare(&htim3,CH1, temp1); // __HAL_TIM_SetCompare(&htim3,CH2,temp1); temp1 +=15; HAL_Delay(9); }*/ __HAL_TIM_SetCompare(&htim3,CH1, 0); // __HAL_TIM_SetCompare(&htim3,CH2,0); HAL_Delay(340); } __HAL_TIM_SetCompare(&htim3,CH1, 0); HAL_TIM_PWM_Stop( &htim3 , CH1 ); HAL_TIM_PWM_Stop( &htim3 , CH2 ); HAL_TIM_PWM_Stop( &htim3 , CHx ); HAL_TIM_PWM_Stop( &htim3 , CHy ); HAL_TIM_PWM_DeInit( &htim3 ); HAL_TIM_Base_DeInit(&htim3); GPIO_TIM3_OFF(); HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0 ); //open drain kimenet,pch fet, HAL_Delay(100); // HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 ); HAL_Delay(1000); }
void uartTester(){ //UART fogadás, teszteléshez --------------------------------------------------------- uint8_t pData; PutString("S"); HAL_UART_Receive(&huart1,&pData,1,100); if(pData=='O'){ HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin); PutString("R"); HAL_UART_Receive(&huart1,&pData,1,1000); while(pData != 'A') HAL_UART_Receive(&huart1,&pData,1,1000); HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 1 ); PutString("R"); HAL_UART_Receive(&huart1,&pData,8,1000); while(pData != 'B') HAL_UART_Receive(&huart1,&pData,8,1000); soundNum=1; sounDelay=10; SystemClock_Config_48MHz(); HAL_Delay(2); MX_TIM3_Init(); HAL_TIM_PWM_Init(&htim3); sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_1); sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; HAL_TIM_PWM_ConfigChannel( &htim3 , &sConfigOC , TIM_CHANNEL_2); HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); uint16_t i=630; __HAL_TIM_SetAutoreload(&htim3,i*2); __HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_1, i); __HAL_TIM_SetCompare(&htim3,TIM_CHANNEL_2, i); HAL_Delay(500); PutString("R"); HAL_UART_Receive(&huart1,&pData,8,1000); while(pData != 'C') HAL_UART_Receive(&huart1,&pData,8,1000); HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0); HAL_TIM_PWM_Stop( &htim3 , TIM_CHANNEL_1 ); HAL_TIM_PWM_Stop( &htim3 , TIM_CHANNEL_2 ); HAL_TIM_PWM_DeInit( &htim3 ); SystemClock_Config_8MHz(); HAL_ADC_MspDeInit(&hadc); HAL_UART_MspDeInit(&huart1); HAL_TIM_Base_DeInit(&htim3); while(1){ HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin); HAL_Delay(200); } } }
int main(void) { /* USER CODE BEGIN 1 */ CMDLINE_CONTEXT cmd_context; const char *zhonx_info = (char *)CONFIG_ZHONX_INFO_ADDR; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_ADC2_Init(); MX_ADC3_Init(); MX_I2C1_Init(); MX_RNG_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_TIM5_Init(); MX_TIM6_Init(); MX_TIM7_Init(); MX_TIM8_Init(); MX_TIM11_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ expanderInit(); HAL_Delay(100); mainControlInit(); ssd1306Init(0); timesBaseInit(); ledPowerBlink(990, 10); settingsInit(); mulimeterInit(); bluetoothInit(); toneInit(); spyPostInit(); positionControlSetPositionType(GYRO); mainControlSetFollowType(NO_FOLLOW); toneSetVolulme(100); tone(F4, 50); toneItMode(A4, 50); // Register Output callback cmd_context.out = blockingPrintf; // Initialize Command Line module cmdline_init(&cmd_context); // Check if robot name is populated in Flash memset(zhonxName, 0, sizeof(zhonxName)); // Retrieve ZHONX information from flash if any if (zhonx_info[0] == 'Z') { strcpy(zhonxName, zhonx_info); } while (zhonxName[0] == 0) { menu(zhonxNameMenu); } while (1) { menu(mainMenu); powerOffConfirmation(); } /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) ; /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ /* USER CODE END 3 */ }