Beispiel #1
0
/**
 * ADC1+2 interrupt hander
 */
void adc1_2_irq_handler(void)
{
    uint8_t channel = 0;
    uint16_t value  = 0;
    struct adc_buf * buf;

#ifdef USE_AD1
    // Clear Injected End Of Conversion
    ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC);
    for(channel = 0; channel < NB_ADC1_CHANNELS; channel++) {
        buf = adc1_buffers[channel];
        if(buf) {
            value = ADC_GetInjectedConversionValue(ADC1, adc_injected_channels[channel]);
            adc_push_sample(buf, value);
        }
    }
    adc_new_data_trigger = 1;
#endif
#ifdef USE_AD2
    // Clear Injected End Of Conversion
    ADC_ClearITPendingBit(ADC2, ADC_IT_JEOC);
    for(channel = 0; channel < NB_ADC2_CHANNELS; channel++) {
        buf = adc2_buffers[channel];
        if(buf) {
            value = ADC_GetInjectedConversionValue(ADC2, adc_injected_channels[channel]);
            adc_push_sample(buf, value);
        }
    }
    adc_new_data_trigger = 1;
#endif
}
Beispiel #2
0
void TIM2_IRQHandler(void)
{
	int d, mv;

	//handle power 1
	d = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
	ict_vget_1 = d2mv(d);
	//printf("%d\n",ict_vget_1);
	mv = ict_vget_1 - ict_vexp_1;
	ict_vout_1 -= mv;
	d = mv2d(ict_vout_1);
	if(d < 0) d = 0;
 	DAC_SetChannel1Data(DAC_Align_12b_R, d);

	//handle power 2
	d = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_2);
	ict_vget_2 = d2mv(d);
	//printf("%d\n",ict_vget_2);
	mv = ict_vget_2 - ict_vexp_2;
	ict_vout_2 -= mv;
	d = mv2d(ict_vout_2);
	if(d < 0) d = 0;
	DAC_SetChannel2Data(DAC_Align_12b_R, d);

	//handle I1&I2
	d = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_3);
	ict_iget_1 = d2mA(d);
	d = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_4);
	ict_iget_2 = d2mA(d);
	//printf("I1 = %d I2 = %d\n", i1, i2);

	ADC_SoftwareStartInjectedConvCmd(ADC1, ENABLE);
	TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
}
Beispiel #3
0
/**
 * ADC1 interrupt hander
 */
void adc1_2_irq_handler(void)
{
	ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC);

	adc_data.battery_voltage =
		ADC_GetInjectedConversionValue(ADC1, ADC_BATTERY_VOLTAGE);
	adc_data.current =
		ADC_GetInjectedConversionValue(ADC1, ADC_CURRENT);
	adc_data.temp =
		ADC_GetInjectedConversionValue(ADC1, ADC_TEMP);

	adc_data.trigger = true;
}
/*******************************************************************************
* Function Name  : SVPWMEOCEvent
* Description    :  Routine to be performed inside the end of conversion ISR
		         It computes the bus voltage and temperature sensor sampling 
		        and disable the ext. adc triggering.	
* Input           : None
* Output         : None
* Return         : None
*******************************************************************************/
u8 SVPWMEOCEvent(void)
{
	// Store the Bus Voltage and temperature sampled values
	h_ADCTemp = ADC_GetInjectedConversionValue(ADC2,ADC_InjectedChannel_2);
	h_ADCBusvolt = ADC_GetInjectedConversionValue(ADC1,ADC_InjectedChannel_2);

	if ((State == START) || (State == RUN))//INIT状态时,直接跳过,否则禁止ADC转化触发
	{          
		// Disable EXT. ADC Triggering
		ADC1->CR2 = ADC1->CR2 & 0xFFFF7FFF;
	}
	return ((u8)(1));
}
/**
  * @brief  This function handles ADC1 and ADC2 global interrupts requests.
  * @param  None
  * @retval None
  */
void ADC1_2_IRQHandler(void)
{
  /* Clear ADC1 JEOC pending interrupt bit */
  ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC);
  
  /* Get injected channel10 and channel11 converted value */
  ADC_InjectedConvertedValueTab[Index++] = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
  ADC_InjectedConvertedValueTab[Index++] = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_2);
  
  if (Index == 32)
  {
    Index = 0;
  }
}
Beispiel #6
0
/*******************************************************************************
* Function Name  : ADC1_2_IRQHandler
* Description    : This function handles ADC1 and ADC2 global interrupts requests.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_IRQHandler(void)
{
  if((ADC1->SR & ADC_FLAG_JEOC) == ADC_FLAG_JEOC)
  {
    //It clear JEOC flag
    ADC1->SR &= ~(rt_uint32_t)(ADC_FLAG_JEOC | ADC_FLAG_JSTRT);
    MCLIB_Mesure_Structure.Mec_Angle = GET_MECHANICAL_ANGLE;
//    if (SVPWMEOCEvent())
		if (State != IDLE)
    {   
//      MCL_Calc_BusVolt();
			
      switch (State)
      {
          case RUN:          
            FOC_Model();       
          break;       
    
          case START: 
						ENC_Start_Up();	
          break; 
    
          default:
          break;
      }
			
      #ifdef BRAKE_RESISTOR
        if((wGlobal_Flags & BRAKE_ON) == BRAKE_ON)
        {
          rt_uint16_t aux;
					
          aux = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_2);
        
          if (aux < BRAKE_HYSTERESIS)
          {
           wGlobal_Flags &= ~BRAKE_ON;
           MCL_Set_Brake_Off();
          }
        }
      #endif      
    }
  }
  else 
  {  
    if(ADC_GetITStatus(ADC1, ADC_IT_AWD) == SET)
    {
#ifdef BRAKE_RESISTOR
      //Analog watchdog interrupt has been generated 
     MCL_Set_Brake_On(); 
     wGlobal_Flags |= BRAKE_ON;
#else
     if(MCL_Chk_BusVolt()==OVER_VOLT)  // ·ÀÖ¹¸ÉÈÅ
        MCL_SetFault(OVER_VOLTAGE);
#endif

     ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
    }    
  }
	
}
Beispiel #7
0
/**
  * @brief  This function handles ADC1 and ADC2 global interrupts requests.
  * @param  None
  * @retval : None
  */
void ADC1_2_IRQHandler(void)
{
  /* Set PC.06 pin */
  GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_SET);
  /* Get injected channel11 converted value */
  ADC_InjectedConvertedValueTab[Index++] = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
  /* Clear ADC1 JEOC pending interrupt bit */
  ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC);
  /* Reset PC.06 pin */
  GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_RESET);
}
Beispiel #8
0
void adc1_2_irq_handler(void){
    uint16_t new_value;

    ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC);

    new_value = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);

    if(adc_delay_count == 0)
        adc_filtered = new_value;
    else
        adc_filtered = ((adc_filtered * 3) + new_value) >> 2;

    if(adc_delay_count > 5){
        if(adc_rising){
            if(adc_filtered > adc_level + 100){
                if(adc_count < 3){
                    adc_count++;
                }else{
                    LED_ORANGE_TOGGLE();
                    ADC_ExternalTrigInjectedConvCmd(ADC1, DISABLE);
                    pwm_trig_led=0;
                    if(adc_comm) comm_tim_set_next_comm();
                }
            }
        }else{
            if(adc_filtered < adc_level){
                if(adc_count < 3){
                    adc_count++;
                }else{
                    LED_ORANGE_TOGGLE();
                    ADC_ExternalTrigInjectedConvCmd(ADC1, DISABLE);
                    pwm_trig_led=0;
                    if(adc_comm) comm_tim_set_next_comm();
                }
            }
        }
    }else{
        adc_delay_count++;
    }

}
void ADC1_IRQHandler(void){
	ADC_ClearITPendingBit(ADC1, ADC_IT_JEOS);
	adc_injected_data[0]=ADC_GetInjectedConversionValue(ADC1,ADC_InjectedSequence_1);
	adc_injected_data[1]=ADC_GetInjectedConversionValue(ADC1,ADC_InjectedSequence_2);
	adc_count++;
}
Beispiel #10
0
/*******************************************************************************
* Function Name  : SysTickHandler
* Description    : This function handles SysTick Handler - runs at 100hz.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
__attribute__((externally_visible)) void SysTickHandler(void)
{
	static float I,old_pressure;
	static uint16_t Enabled_iterations;			//Note, this is going to break if we spend long periods with +ive pressure set
	static uint32_t Last_Button_Press;			//Holds the timestamp for the previous button press
	static uint8_t System_state_counter;			//Holds the system state counter
	static uint8_t tmpindex;				//Temp sensor decimator
	//FatFS timer function
	disk_timerproc();
	//Incr the system uptime
	Millis+=10;
	if(ADC_GetFlagStatus(ADC2, ADC_FLAG_JEOC)) {		//We have adc2 converted data from the injected channels
		ADC_ClearFlag(ADC2, ADC_FLAG_JEOC);		//Clear the flag
		if(Pressure_Offset)				//Only run the filter when we are sure the sensor is calibrated
			Reported_Pressure=filterloop(conv_diff(ADC_GetInjectedConversionValue(ADC2, ADC_InjectedChannel_1)));//convert injected channel 1
		//Now handle the pressure controller
		if(Pressure_control&0x7F) {//If active pressure control is enabled
			//run a PI controller on the air pump motor
			if(Pressure_Setpoint>0 && ( Button_hold_tim>(BUTTON_TURNOFF_TIME-BUTTON_MULTIPRESS_TIMEOUT) || !Button_hold_tim ) ) {
				// A Negative setpoint or prolonged button press forces a dump of air
				float error=Pressure_Setpoint-Reported_Pressure;//Pressure_Setpoint is a global containing the target diff press
				if(Enabled_iterations++>I_HOLDOFF) {
					I+=error*PRESSURE_I_CONST;//Constants defined in main.h
					if(I>PRESSURE_I_LIM)	//Enforce limits
						I=PRESSURE_I_LIM;
					if(I<-PRESSURE_I_LIM)
						I=-PRESSURE_I_LIM;
				}
				int16_t a=PRESSURE_P_CONST*error+I+PRESSURE_D_CONST*(Reported_Pressure-old_pressure);
				if(a>0)				//Make sure we are actually turning the motor on
					Set_Motor((int16_t)a);	//Set the motor gpio dir & pwm duty
			}
			else {
				Enabled_iterations=0;		//Make sure this is reset
				if(abs(Reported_Pressure)>PRESSURE_MARGIN)
					Set_Motor(-1);		//Set a dump to rapidly drop to zero pressure
				else
					Set_Motor(0);
			}
		}			
		else if(!Pressure_control)			//If the most significant bit isnt set
			Set_Motor(0);				//Sets the Rohm motor controller to idle (low current shutdown) state
		//Check the die temperature - not possible on adc1 :-(
		//Device_Temperature=convert_die_temp(ADC_GetInjectedConversionValue(ADC2, ADC_InjectedChannel_3));//The on die temperature sensor
		#if BOARD>=3
		if(Sensors&(1<<THERMISTOR_SENSOR))
			Device_Temperature=convert_thermistor_temp(ADC_GetInjectedConversionValue(ADC2, ADC_InjectedChannel_3));
		#endif
		//Could process some more sensor data here
		old_pressure=Reported_Pressure;			//Set the old pressure record here for use in the D term
	}
	ADC_SoftwareStartInjectedConvCmd(ADC2, ENABLE);		//Trigger the injected channel group
	//Read any I2C bus sensors here (100Hz)
	if(Sensors&(1<<TEMPERATURE_SENSOR)) {
		TMP102_Reported_Temperature=GET_TMP_TEMPERATURE;
		if(!tmpindex--) {				//Every 30ms
			tmpindex=3;
			//Jobs|=1<<TMP102_CONFIG;
			I2C1_Request_Job(TMP102_READ);		//Request a TMP102 read if there is one present
			I2C1_Request_Job(TMP102_CONFIG);	//Need to do this to set one shot bit is set high again to start a new single convertion
			//Some sort of i2c error here
		}
	}
	//Now process the control button functions
	if(Button_hold_tim ) {					//If a button press generated timer has been triggered
		if(GET_BUTTON) {				//Button hold turns off the device
			if(!--Button_hold_tim) {
				shutdown_filesystem();
				shutdown();			//Turn off the logger after closing any open files
			}
		}
		else {						//Button released - this can only ever run once per press
			RED_LED_OFF;				//Turn off the red LED - used to indicate button press to user
			if(Button_hold_tim<BUTTON_DEBOUNCE) {	//The button has to be held down for longer than the debounce period
				Last_Button_Press=Millis;
				if(++System_state_counter>=SYSTEM_STATES)
					System_state_counter=0;//The system can only have a limited number of states
			}
			Button_hold_tim=0;			//Reset the timer here
		}
	}
	if(Last_Button_Press&&(Millis-Last_Button_Press>BUTTON_MULTIPRESS_TIMEOUT)&&!Button_hold_tim) {//Last press timed out and button is not pressed
		if(!(System_state_Global&0x80))			//The main code has unlocked the global using the bit flag - as it has processed
			System_state_Global=0x80|System_state_counter;//The previous state update
		System_state_counter=0;				//Reset state counter here
		Last_Button_Press=0;				//Reset the last button press timestamp, as the is no button press in play
	}
}