Ejemplo n.º 1
0
//---------------------------------------------//
//	Fast low-level control dispatcher
//
//	Timer2 is also used to generate PWM for voltage 
//  and current setting
//---------------------------------------------//
void Timer2_IRQHandler(void) 
{
	static uint16_t hw_adc_counter = HW_ADC_CALL_PERIOD;
	uint16_t temp;
	// Time profiling
	uint32_t time_mark1 = 0;
	uint32_t time_mark2 = 0;
	uint32_t ticks_count;
	
	time_mark1 = DWT_Get();
/*	
	// Debug
	if (MDR_PORTA->RXTX & (1<<TXD1))
		PORT_ResetBits(MDR_PORTA, 1<<TXD1);
	else
		PORT_SetBits(MDR_PORTA, 1<<TXD1);
*/	
	
	
	if (--hw_adc_counter == 0)
	{
		hw_adc_counter = HW_ADC_CALL_PERIOD;
		Converter_HW_ADCProcess();	// Converter low-level ADC control
	}
	Converter_HWProcess();			// Converter low-level ON/OFF control and overload handling
	ProcessEncoder();				// Poll encoder				

	// Reinit timer2 CCR
	temp = MDR_TIMER2->CCR2 + HW_IRQ_PERIOD;	
	MDR_TIMER2->CCR2 = (temp > MDR_TIMER2->ARR) ? temp - MDR_TIMER2->ARR : temp;
	TIMER_ClearFlag(MDR_TIMER2, TIMER_STATUS_CCR_REF_CH2);
	//-------------------------------//
	
	time_mark2 = DWT_Get();
	
	// Update time
	ticks_count = DWT_GetDelta(time_mark1, time_mark2);
	if (ticks_count > time_profile.max_ticks_in_Timer2_ISR)
		time_profile.max_ticks_in_Timer2_ISR = ticks_count;
}
Ejemplo n.º 2
0
void DWT_Delay(uint32_t hz){
	int32_t tp = DWT_Get() + hz;
	while (DWT_Compare(tp));
}
Ejemplo n.º 3
0
void DWT_Delay(uint32_t us) // microseconds
{
  int32_t tp = DWT_Get() + us * (SystemCoreClock1/1000000);
  while (DWT_Compare(tp));
}
Ejemplo n.º 4
0
__inline uint8_t DWT_Compare(int32_t tp){
	return (((int32_t)DWT_Get() - tp) < 0);
}
Ejemplo n.º 5
0
void Delay_us(uint32_t Delay) {
    int32_t tp = DWT_Get() + Delay * (SYS_FREQUENCY/1000000);
    while (((int32_t)DWT_Get() - tp) < 0);
}