/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */
//  SEGGER_SYSVIEW_RecordEnterISR();
  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  HAL_SYSTICK_IRQHandler();
  /* USER CODE BEGIN SysTick_IRQn 1 */
//  SEGGER_SYSVIEW_RecordEnterISR();
  /* USER CODE END SysTick_IRQn 1 */
}
Example #2
0
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  HAL_SYSTICK_IRQHandler();
  /* USER CODE BEGIN SysTick_IRQn 1 */

  /* USER CODE END SysTick_IRQn 1 */
}
Example #3
0
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  HAL_SYSTICK_IRQHandler();
  /* USER CODE BEGIN SysTick_IRQn 1 */
//  HAL_GPIO_TogglePin(USB_CON_GPIO_Port, USB_CON_Pin);
  /* USER CODE END SysTick_IRQn 1 */
}
Example #4
0
//System Timer, 1ms ISR
void SysTick_Handler(void)
{
	// Decrement to zero the counter used by the delay routine.
	if(timer_delayCount != 0u)
	{
		--timer_delayCount;
	}

	//For USB delays:
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
}
Example #5
0
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  HAL_SYSTICK_IRQHandler();
  emfat_request_time++;
  /* USER CODE BEGIN SysTick_IRQn 1 */

  /* USER CODE END SysTick_IRQn 1 */
}
Example #6
0
/**
  * @brief This function handles System tick timer.
  */
void SysTick_Handler(void) {
    HAL_IncTick();
    HAL_SYSTICK_IRQHandler();

    static uint_fast16_t counter = 0;
    counter++;
    
    if (counter & 8) {
        DIO8_InputDebounce();
    }

    if (counter > 999) {
        counter = 0;
        NewSecond = 1;
        UnixTimestamp++;
    }
}
Example #7
0
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  HAL_SYSTICK_IRQHandler();
  /* USER CODE BEGIN SysTick_IRQn 1 */
#ifdef USE_STM32F4_EMWIN
//  OS_TimeMS++; // EmWin Ticks
#endif


#ifdef USE_STM32F4_AUDIO
  /* Test on the command: Recording */
  if (CmdIndex == CMD_RECORD)
  {
    /* Increments the time recording base variable */
    TimeRecBase ++;
  }
#endif
  /* USER CODE END SysTick_IRQn 1 */
}
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{ 
  HAL_SYSTICK_IRQHandler();
}
Example #9
0
int main(void)
{

  /* 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_ADC_Init();
  MX_TIM2_Init();
  MX_TIM21_Init();

  batpins battery3;
  batpins battery4;
  pwm_timers b3_tims;
  pwm_timers b4_tims;
  batprops props_bat3;
  batprops props_bat4;

  /* Battery 3 */
  b3_tims.conv_timer = htim2;
  b3_tims.dchg_timer = htim21;

  battery3.v_adc_chan = ADC_CHANNEL_4;
  battery3.i_adc_chan = ADC_CHANNEL_8;
  battery3.chg_port = chg_onoff_3_GPIO_Port;
  battery3.chg_pin = chg_onoff_3_Pin;
  battery3.dchg_pin = TIM_CHANNEL_1;
  battery3.conv_chg_pin = TIM_CHANNEL_1;
  battery3.conv_dchg_pin = TIM_CHANNEL_2;
  battery3.pwm_tims = b3_tims;

  props_bat3.i_adc_val = 0;
  props_bat3.v_adc_val = 0;
  props_bat3.adc_val_old = adc_read(battery3.i_adc_chan);
  props_bat3.id_adc_stpt = 400 + props_bat3.adc_val_old;
  props_bat3.ic_adc_stpt = props_bat3.adc_val_old - 600;
  props_bat3.conv_bst_stpt = 200; // Need to calibrate this to boost to desired voltage
  props_bat3.pwm_chg_stpt = 0; 	  // Initialized to 0. Program will change as needed.
  props_bat3.pwm_dchg_stpt = 720; // Initialize near where discharge FET turns on
  props_bat3.pi = 0;

  /* Battery 4 */
  b4_tims.conv_timer = htim2;
  b4_tims.dchg_timer = htim21;

  battery4.v_adc_chan = ADC_CHANNEL_11;
  battery4.i_adc_chan = ADC_CHANNEL_10;
  battery4.chg_port = chg_onoff_4_GPIO_Port;
  battery4.chg_pin = chg_onoff_4_Pin;
  battery4.dchg_pin = TIM_CHANNEL_2;
  battery4.conv_chg_pin = B4_CHG_CHAN; // Change in h file (used in multiple locations, dma_offset func)
  battery4.conv_dchg_pin = TIM_CHANNEL_4;
  battery4.pwm_tims = b4_tims;

  props_bat4.i_adc_val = 0;
  props_bat4.v_adc_val = 0;
  props_bat4.adc_val_old = adc_read(battery4.i_adc_chan);
  props_bat4.id_adc_stpt = 500 + props_bat4.adc_val_old;
  props_bat4.ic_adc_stpt = props_bat4.adc_val_old - 200;
  props_bat4.conv_bst_stpt = 200; // Need to calibrate this to boost to desired voltage
  props_bat4.pwm_chg_stpt = 0; 	  // Initialized to 0. Program will change as needed.
  props_bat4.pwm_dchg_stpt = 720; // Initialize near where discharge FET turns on
  props_bat4.pi = 0;

  /* Initialize global variables */
#ifdef BAT1
  TimeCounter3 = 0;
  TimeCounter4 = 0;
  uint32_t restStartms3 = 0;
  uint32_t i3 = 0;
  uint32_t voltage3 = 0;
  uint32_t current3 = 720;
  status bat_stat3 = OK;
  i3_origin = props_bat3.adc_val_old;
#endif

#ifdef BAT2
  uint32_t restStartms4 = 0;
  uint32_t i4 = 0;
  uint32_t voltage4 = 0;
  uint32_t current4 = 720;
  status bat_stat4 = OK;
  i4_origin = props_bat4.adc_val_old;
#endif

  //uint32_t dc_pwm[1] = {800};//, 500, 200, 300, 400, 500, 600, 700, 250, 750};
  //uint32_t test2[2] = {100, 900};
  //uint32_t sine = 0;

  /* Initialize converter and charge / discharge pins   */
  conv_init(battery3);
  conv_init(battery4);

  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_3, &dc_pwm, (uint16_t)1);
  //HAL_Delay(10);
  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_4, &dc_pwm[8], (uint16_t)2);
  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_1, 200, (uint16_t)SINE_RES_500HZ);
  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_4, 800, (uint16_t)SINE_RES_500HZ); //Bat2 conv dchg
  //pwm_sine_Start(battery3.pwm_tims.conv_timer, battery3.conv_dchg_pin, dc_pwm, sine); // Boost (discharge)
  //pwm_sine_Start(battery3.pwm_tims.conv_timer, battery3.conv_chg_pin,  dc_pwm, sine); // Buck (charge)
  //pwm_sine_Start(battery4.pwm_tims.conv_timer, battery4.conv_dchg_pin, test2, sine); // Boost (discharge)
  //pwm_sine_Start(battery4.pwm_tims.conv_timer, battery4.conv_chg_pin, 400, sine); // Buck (charge)
  //pwm_Set(battery3.pwm_tims.dchg_timer, battery3.dchg_pin, 750);
 // pwm_Set(battery4.pwm_tims.dchg_timer, battery4.dchg_pin, 760);
  //pwm_sine_Start(battery3.pwm_tims.conv_timer, battery3.conv_chg_pin, dc_pwm, sine); // Buck (charge)
  //HAL_GPIO_WritePin(battery3.chg_port, battery3.chg_pin, GPIO_PIN_SET); // Charging On
  //HAL_GPIO_WritePin(battery4.chg_port, battery4.chg_pin, GPIO_PIN_SET); // Charging On
  //pwm_sine_Start(battery4.pwm_tims.conv_timer, battery4.conv_chg_pin, dc_pwm, sine); // Buck (charge)
  //HAL_TIM_PWM_Start(battery4.pwm_tims.conv_timer, battery4.conv_dchg_pin);
  //HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); // Bat1 conv dchg

  uint8_t u8_oc3 = 0;
  uint8_t u8_oc4 = 0;

  // Wait for batteries to be connected
  //while(adc_read(battery3.v_adc_chan) < 500 || adc_read(battery4.v_adc_chan) < 500) {}

  /* Infinite loop */
  while (1)
  {

#ifdef BAT1
	  /* First battery */
	  if(TimeCounter3>=5) // 4ms, ie 2 periods of 500Hz sine wave
	  	  {
	  		  switch(bat_stat3) {
	  		  case DISCHARGE:
	  			  bat_stat3 = discharge_main(battery3, &props_bat3, &restStartms3, i3, bat_stat3);
	  			  break;
	  		  case CC:
	  			  bat_stat3 = chg_ctrl(battery3, &props_bat3, i3, i3_origin);
	  			  //HAL_Delay(1);
	  			  break;
	  		  case CV:
	  			  bat_stat3 = cv_main(battery3, &props_bat3, &restStartms3, i3, i3_origin, bat_stat3);
	  			  break;
	  		  case FULL:
	  			  if(HAL_GetTick() - restStartms3 >= REST)
	  			  {
						props_bat3.i_adc_val = 0;
						props_bat3.v_adc_val = 0;
						props_bat3.adc_val_old = adc_read(battery3.i_adc_chan);
						bat_stat3 = DISCHARGE;
	  			  }
	  			  break;
	  		  case LVDC:
	  			if(HAL_GetTick() - restStartms3 >= REST)
	  			  {
					  props_bat3.i_adc_val = 0;
					  props_bat3.v_adc_val = 0;
					  props_bat3.adc_val_old = adc_read(battery3.i_adc_chan);
					  bat_stat3 = CC;
	  			  }
	  			  break;
	  		  case OK:
	  			  props_bat3.i_adc_val = 0; // normally reset in d/chg func, but not used so reset here
	  			  props_bat3.v_adc_val = 0; // normally reset in d/chg func, but not used so reset here
	  			  bat_stat3 = CC;
	  			  break;
	  		  case OVERCURRENT:
	  			  bat_stat3 = OVERCURRENT;
	  			  break;
	  		  default:
	  			  bat_stat3 = OK;
	  			  break;
	  		  }
	  		  TimeCounter3 = 0;
	  		  i3 = 0;
	  	  }

  	  /* Update ADC readings */
  	  current3 = adc_read(battery3.i_adc_chan);
  	  voltage3 = adc_read(battery3.v_adc_chan);
  	  props_bat3.i_adc_val = props_bat3.i_adc_val + current3;
  	  props_bat3.v_adc_val = props_bat3.v_adc_val + voltage3;

  	  /* Over-current protection */
  	  if(current3>3950 || current3<100)
  	  {
  		  u8_oc3++;
  		  if(u8_oc3 > 15)
  		  {
  			conv_init(battery3);
  			bat_stat3 = OVERCURRENT;
  		  }
  	  }
  	  else
  	  {
  		  u8_oc3 = 0;
  	  }
  	  i3++;
#endif

#ifdef BAT2
	  /* Second battery */
	  if(TimeCounter4>=5) // 4ms, ie 2 periods of 500Hz sine wave
		  {
			  switch(bat_stat4) {
			  case DISCHARGE:
				  bat_stat4 = discharge_main(battery4, &props_bat4, &restStartms4, i4, bat_stat4);
				  break;
			  case CC:
				  bat_stat4 = chg_ctrl(battery4, &props_bat4, i4, i4_origin);
				  break;
			  case CV:
				  bat_stat4 = cv_main(battery4, &props_bat4, &restStartms4, i4, i4_origin, bat_stat4);
				  break;
			  case FULL:
				  if(HAL_GetTick() - restStartms4 >= REST)
				  {
						props_bat4.i_adc_val = 0;
						props_bat4.v_adc_val = 0;
						props_bat4.adc_val_old = adc_read(battery4.i_adc_chan);
						bat_stat4 = DISCHARGE;
				  }
				  break;
			  case LVDC:
				if(HAL_GetTick() - restStartms4 >= REST)
				  {
					  props_bat4.i_adc_val = 0;
					  props_bat4.v_adc_val = 0;
					  props_bat4.adc_val_old = adc_read(battery4.i_adc_chan);
					  bat_stat4 = CC;
				  }
				  break;
			  case OK:
				  props_bat4.i_adc_val = 0; // normally reset in d/chg func, but not used so reset here
				  props_bat4.v_adc_val = 0; // normally reset in d/chg func, but not used so reset here
				  bat_stat4 = CC;
				  break;
			  case OVERCURRENT:
				  bat_stat4 = OVERCURRENT;
				  break;
			  default:
				  bat_stat4 = OK;
				  break;
			  }
			  TimeCounter4 = 0;
			  i4 = 0;
		  }

	  /* Update ADC readings */
  	  current4 = adc_read(battery4.i_adc_chan);
  	  voltage4 = adc_read(battery4.v_adc_chan);
  	  props_bat4.i_adc_val = props_bat4.i_adc_val + current4;
  	  props_bat4.v_adc_val = props_bat4.v_adc_val + voltage4;

  	  /* Over-current protection */
  	  if(current4>3950 || current4<100)
  	  {
  		  u8_oc4++;
  		  if(u8_oc4 > 15)
  		  {
  			conv_init(battery4);
  			bat_stat4 = OVERCURRENT;
  		  }
  	  }
  	  else
  	  {
  		  u8_oc4 = 0;
  	  }
  	  i4++;

#endif

	  HAL_SYSTICK_IRQHandler();

  }


}
Example #10
0
void SysTick_Handler(void)
{
	HAL_IncTick();
	HAL_SYSTICK_IRQHandler();
	sysTick++;
}