int main(void)
{
	init_PM();
	init_LCD();
	init_Potentiometer();
	init_CurrentSensor();
	init_INTC();
	fill_Display();
	set_Velocidad(velocidad);
	set_Direccion(direccion);
	init_PWM(velocidad,direccion);
	while (1)
	{
		adc_start(&AVR32_ADC);
		adc_value_pot = adc_get_value(&AVR32_ADC,EXAMPLE_ADC_POTENTIOMETER_CHANNEL);
		adc_start(&AVR32_ADC);
		adc_value_current = adc_get_value(&AVR32_ADC,3);
		set_Duty_Cycle(adc_value_pot);
		set_Current(adc_value_current);
		if(bandera ==1){
			set_Velocidad(velocidad);
			set_Direccion(direccion);
			update_PWM(velocidad, direccion);
		}
		delay_ms(400);
	}//WHILE
}//MAIN
Exemple #2
0
// remodifier la valeur de la PWM
void UpdateGrandeVoile(){
	// rapports PWM pour les positions max du servo moteur
	float rapport_max = 0.925f;
	float rapport_min = 0.82f;
	
	float angle_girouette, nouveau_rapport ;
	
	angle_girouette = absFloat(GetAngle());
	
	//Si angle_girouette compris entre 45 et 180° -> (theta - 45) / 135
	//Si angle_girouette compris entre 0 et 45 		-> 0
	if (angle_girouette < 45.0 ){
		nouveau_rapport = 0.0 ;
	}	else {
		nouveau_rapport = (angle_girouette - 45.0) / 135.0;
	}
	
	if (nouveau_rapport > 1.0)
		nouveau_rapport = 1.0;
	
	nouveau_rapport = (nouveau_rapport * (rapport_max-rapport_min)) + rapport_min;
	
	//changement angle servo : modification de la période PWM
	update_PWM(TIM_SERVO, nouveau_rapport, voie);
}
Exemple #3
0
/*
Valeur mini ? 1ms
Valeur neutre ? 1,50 ms
Valeur maxi ? 2,0ms
*/
void EXTI9_5_RFHandler(){
	if(Port_IO_Read(GPIOB, PIN_RF)){
		Timer_Run(TIM_RF_CNT);
	} else {
		timcnt = TIM_RF_CNT->CNT;
		Timer_Stop(TIM_RF_CNT);
		TIM_RF_CNT->CNT = 0;
		timcnt = (timcnt*TIM_RF_US)/autoreload;
		if (first>10){
			correction = timcnt;
			first=0;
		} else if (first!=0) {
			first+=1;
		} else {
			commande = timcnt - correction;
			if (commande > commande_max){
				commande_max=commande;
			} else if ((-commande) > commande_max){
				commande_max=(-commande);
			}
			if (commande > seuilCommande) {
				Port_IO_Set(GPIOA, 2);
				rapport = (float) commande/commande_max;
			} else if (commande < -seuilCommande) {
				Port_IO_Reset(GPIOA, 2);
				rapport = (float) (-commande)/commande_max;
			} else {
				rapport = 0;
			}
			update_PWM(TIM2, 1.0f-rapport, 2);
		}
	}
	EXTI->PR |= 0x1 << 6;
}
void update_actuators(void){
  (*IOp_DO).port=((*IOp_DO).port&0xF0)|(mosi_packet.digital_out.port&0x0F);
  update_PWM();
// V3 board
  update_DAC();
}