codeur incr
This commit is contained in:
parent
6868251ff9
commit
bc90d4524f
5 changed files with 101 additions and 63 deletions
|
@ -16,6 +16,38 @@ void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer ) {
|
||||||
Timer->Timer->CR1 |= (1 << 0); // Active le compteur
|
Timer->Timer->CR1 |= (1 << 0); // Active le compteur
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyTimer_EncoderMode_Conf ( TIM_TypeDef * TIM ) {
|
||||||
|
|
||||||
|
TIM->PSC = 0; // Réglage de la période du Timer
|
||||||
|
TIM->ARR = 360*4;
|
||||||
|
|
||||||
|
// CC1S= ‘01’ (TIMx_CCMR1 register, TI1FP1 mapped on TI1)
|
||||||
|
TIM->CCMR1 &= ~TIM_CCMR1_CC1S;
|
||||||
|
TIM->CCMR1 |= TIM_CCMR1_CC1S_0;
|
||||||
|
|
||||||
|
// CC2S= ‘01’ (TIMx_CCMR2 register, TI2FP2 mapped on TI2)
|
||||||
|
TIM->CCMR2 &= ~TIM_CCMR1_CC2S;
|
||||||
|
TIM->CCMR2 |= TIM_CCMR1_CC2S_0;
|
||||||
|
|
||||||
|
// CC1P= ‘0’, CC1NP = ‘0’, IC1F =’0000’ (TIMx_CCER register, TI1FP1 noninverted, TI1FP1=TI1)
|
||||||
|
TIM->CCER &= ~TIM_CCER_CC1P;
|
||||||
|
TIM->CCER &= ~TIM_CCER_CC1NP;
|
||||||
|
TIM->CCER &= ~TIM_CCMR1_IC1F;
|
||||||
|
|
||||||
|
// CC2P= ‘0’, CC2NP = ‘0’, IC2F =’0000’ (TIMx_CCER register, TI2FP2 noninverted, TI2FP2=TI2)
|
||||||
|
TIM->CCER &= ~TIM_CCER_CC2P;
|
||||||
|
TIM->CCER &= ~TIM_CCER_CC2NP;
|
||||||
|
TIM->CCER &= ~TIM_CCMR1_IC2F; // ou CCMR2 ?
|
||||||
|
|
||||||
|
// SMS= ‘011’ (TIMx_SMCR register, both inputs are active on both rising and falling edges)
|
||||||
|
TIM->SMCR &= ~TIM_SMCR_SMS;
|
||||||
|
TIM->SMCR |= TIM_SMCR_SMS_0;
|
||||||
|
TIM->SMCR |= TIM_SMCR_SMS_1;
|
||||||
|
|
||||||
|
// CEN = 1 (TIMx_CR1 register, Counter is enabled)
|
||||||
|
TIM->CR1 |= TIM_CR1_CEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MyTimer_ActiveIT ( TIM_TypeDef * Timer , char Prio , void (* IT_function ) ( void ) ) {
|
void MyTimer_ActiveIT ( TIM_TypeDef * Timer , char Prio , void (* IT_function ) ( void ) ) {
|
||||||
char num_IT;
|
char num_IT;
|
||||||
|
|
|
@ -22,6 +22,14 @@ conf plus fines (PWM, codeur inc . . . )
|
||||||
void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer ) ;
|
void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer ) ;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*****************************************************************************************
|
||||||
|
* @brief
|
||||||
|
* @param -> - TIM_TypeDef * Timer : Timer concerne
|
||||||
|
* @Note ->
|
||||||
|
*************************************************************************************************
|
||||||
|
*/
|
||||||
|
void MyTimer_EncoderMode_Conf ( TIM_TypeDef *TIM ) ;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -5,10 +5,14 @@
|
||||||
|
|
||||||
#define TIMER_PWM (TIM3)
|
#define TIMER_PWM (TIM3)
|
||||||
#define CANAL_PWM (1)
|
#define CANAL_PWM (1)
|
||||||
|
#define TIMER_CI (TIM2) // Timer codeur incrémental
|
||||||
|
#define GIROUETTE_PHA (PA1)
|
||||||
|
#define GIROUETTE_PHB (PA4)
|
||||||
|
#define GIROUETTE_INDEX (PB0)
|
||||||
|
#define SERVO_VOILE_PWM (PA4)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*****************************************************************************************
|
*************************************************************************************************
|
||||||
* @brief
|
* @brief
|
||||||
* @param -> int angle : angle que l'on veut donner à la voile (entre 0 et 90°)
|
* @param -> int angle : angle que l'on veut donner à la voile (entre 0 et 90°)
|
||||||
* @Note ->
|
* @Note ->
|
||||||
|
@ -29,6 +33,19 @@ int bordage ( int angle ) {
|
||||||
MyTimer_PWM (TIMER_PWM, CANAL_PWM);
|
MyTimer_PWM (TIMER_PWM, CANAL_PWM);
|
||||||
Set_Duty_Cycle(TIMER_PWM, CANAL_PWM, duty_cycle);
|
Set_Duty_Cycle(TIMER_PWM, CANAL_PWM, duty_cycle);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*************************************************************************************************
|
||||||
|
* @brief Handler a appeler lorsque l'angle de roulis est supérieur à 40°
|
||||||
|
* @param ->
|
||||||
|
* @Note ->
|
||||||
|
*************************************************************************************************
|
||||||
|
*/
|
||||||
|
void Roulis_Handler ( void )
|
||||||
|
{
|
||||||
|
bordage(0);
|
||||||
|
}
|
||||||
|
|
|
@ -14,39 +14,11 @@ void CallBack ( void )
|
||||||
|
|
||||||
int main ( void ) {
|
int main ( void ) {
|
||||||
|
|
||||||
int res = 0;
|
|
||||||
|
|
||||||
// Configuration du timer
|
|
||||||
MyTimer_Struct_TypeDef TIM;
|
|
||||||
TIM.Timer = TIM3;
|
|
||||||
TIM.ARR = 719; //2000
|
|
||||||
TIM.PSC = 0; // 18000
|
|
||||||
MyTimer_Base_Init(&TIM);
|
|
||||||
|
|
||||||
// Configuration de la diode PA.6
|
|
||||||
GPIO_Struct.GPIO = GPIOA;
|
|
||||||
GPIO_Struct.GPIO_Pin = 6;
|
|
||||||
GPIO_Struct.GPIO_Conf = AltOut_Ppull;
|
|
||||||
MyGPIO_Init(&GPIO_Struct);
|
|
||||||
|
|
||||||
// PWM à 100kHz avec un rapport cyclique de 0% sur le Timer 3 et le canal 1.
|
|
||||||
MyTimer_PWM (TIM3, 1);
|
|
||||||
Set_Duty_Cycle(TIM3, 1, 0);
|
|
||||||
|
|
||||||
// Configuration de la broche PB.0
|
|
||||||
GPIO_Struct.GPIO = GPIOB;
|
|
||||||
GPIO_Struct.GPIO_Pin = 0;
|
|
||||||
GPIO_Struct.GPIO_Conf = In_Analog;
|
|
||||||
MyGPIO_Init(&GPIO_Struct);
|
|
||||||
|
|
||||||
MyADC_Init(8);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
res = convert_single(); // conversion
|
|
||||||
Set_Duty_Cycle(TIM3, 1, 100 * res / 0xFFF ); // mise à jour de l’intensité de la led
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue