IT_Roulis
This commit is contained in:
parent
06df73ad1a
commit
c531decce4
7 changed files with 141 additions and 39 deletions
|
@ -1,4 +1,6 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "Timer.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float gX;
|
||||
|
@ -12,3 +14,4 @@ void rouli_InitAccel(void);
|
|||
void rouli_GetAccel (XYZ * axe);
|
||||
|
||||
void rouli_IT_Bascule(void);
|
||||
|
||||
|
|
|
@ -31,6 +31,12 @@ void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void)
|
|||
|
||||
#define MyTimer_Base_Start(Timer) (Timer->CR1 |= 0x01)
|
||||
#define MyTimer_Base_Stop(Timer) (Timer->CR1 &= ~0x01)
|
||||
#define PWM_output 0x00
|
||||
#define PWM_inputTI1 0x01
|
||||
#define PWM_inputTI2 0x10
|
||||
#define PWM_inputTRC 0x11
|
||||
|
||||
void MyPWM_init ( TIM_TypeDef * Timer,char Channel);
|
||||
void MyPWM_Duty (TIM_TypeDef * Timer,char Channel, unsigned short CRR );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,92 +1,157 @@
|
|||
#include "TIMER.h"
|
||||
|
||||
/*periode_timer=peridoe_horloge*prescaler*resolution
|
||||
debordement stocké dans registre UIF
|
||||
fixer val prescaler+ autoreload(equivalent resolution)
|
||||
demarrage timer => CEN=1*/
|
||||
|
||||
void (*ptr_func)(void);
|
||||
void (*tim_ptr1_func)(void);
|
||||
void (*tim_ptr2_func)(void);
|
||||
void (*tim_ptr3_func)(void);
|
||||
void (*tim_ptr4_func)(void);
|
||||
|
||||
void MyTimer_Base_Init ( MyTimer_Struct_TypeDef * Timer)
|
||||
{
|
||||
if(Timer->Timer==TIM1)
|
||||
{
|
||||
RCC->APB2ENR |= 0x01<<11;
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
}
|
||||
else if (Timer->Timer==TIM2)
|
||||
{
|
||||
RCC->APB1ENR |= 0x01;
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||
}
|
||||
else if (Timer->Timer==TIM3)
|
||||
{
|
||||
RCC->APB1ENR |= 0x01<<1;
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
||||
}
|
||||
else if (Timer->Timer==TIM4)
|
||||
{
|
||||
RCC->APB1ENR |= 0x01<<2;
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
|
||||
}
|
||||
Timer->Timer->ARR=Timer->ARR;
|
||||
Timer->Timer->PSC=Timer->PSC;
|
||||
Timer->Timer->ARR=Timer->ARR; // On set la donnée d'autoreload
|
||||
Timer->Timer->PSC=Timer->PSC; // On set la donnée de prescaler (ce qui va nous permettre de diviser la valeur d'autoreaload)
|
||||
}
|
||||
|
||||
void MyPWM_init ( TIM_TypeDef * Timer,char Channel)
|
||||
{
|
||||
if(Channel==1)
|
||||
{
|
||||
Timer->CCMR1&=~0x00FF;
|
||||
Timer->CCMR1 &= ~TIM_CCMR1_OC1M_0;
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC1M_1| TIM_CCMR1_OC1M_2;
|
||||
Timer->CCER |= TIM_CCER_CC1E;
|
||||
|
||||
}
|
||||
if(Channel==2)
|
||||
{
|
||||
Timer->CCMR1&=~0xFF00;
|
||||
Timer->CCMR1 &= ~TIM_CCMR1_OC2M_0;
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC2M_1| TIM_CCMR1_OC2M_2;
|
||||
Timer->CCER |= TIM_CCER_CC2E;
|
||||
|
||||
}
|
||||
if(Channel==3)
|
||||
{
|
||||
Timer->CCMR2&=~0x00FF;
|
||||
Timer->CCMR2 &= ~TIM_CCMR2_OC3M_0;
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC3M_1| TIM_CCMR2_OC3M_2;
|
||||
Timer->CCER |= TIM_CCER_CC3E;
|
||||
|
||||
}
|
||||
if(Channel==4)
|
||||
{
|
||||
Timer->CCMR2&=~0xFF00;
|
||||
Timer->CCMR2 &= ~TIM_CCMR2_OC4M_0;
|
||||
Timer->CCMR2 |= TIM_CCMR2_OC4M_1| TIM_CCMR2_OC4M_2;
|
||||
Timer->CCER |= TIM_CCER_CC4E;
|
||||
|
||||
}
|
||||
}
|
||||
void MyPWM_Duty (TIM_TypeDef * Timer,char Channel, unsigned short CRR )
|
||||
{
|
||||
|
||||
|
||||
if(Channel==1)
|
||||
{
|
||||
Timer->CCR1=CRR;
|
||||
}
|
||||
if(Channel==2)
|
||||
{
|
||||
Timer->CCR2=CRR;
|
||||
}
|
||||
if(Channel==3)
|
||||
{
|
||||
Timer->CCR3=CRR;
|
||||
|
||||
}
|
||||
if(Channel==4)
|
||||
{
|
||||
Timer->CCR4=CRR;
|
||||
}
|
||||
|
||||
}
|
||||
void MyTimer_ActiveIT (TIM_TypeDef * Timer, char Prio, void (*IT_function)(void))
|
||||
{
|
||||
int num_tim;
|
||||
ptr_func=IT_function;
|
||||
Timer->DIER |= 0x01;
|
||||
Timer->DIER |= 0x01; // On autorise les interruptions sur timer
|
||||
if(Timer==TIM1)
|
||||
{
|
||||
num_tim=TIM1_UP_IRQn;
|
||||
num_tim=TIM1_UP_IRQn;
|
||||
tim_ptr1_func=IT_function;
|
||||
}
|
||||
else if(Timer==TIM2)
|
||||
{
|
||||
num_tim=TIM2_IRQn;
|
||||
tim_ptr2_func=IT_function;
|
||||
}
|
||||
else if(Timer==TIM3)
|
||||
{
|
||||
num_tim=TIM3_IRQn;
|
||||
tim_ptr3_func=IT_function;
|
||||
}
|
||||
else if(Timer==TIM4)
|
||||
{
|
||||
num_tim=TIM4_IRQn;
|
||||
tim_ptr4_func=IT_function;
|
||||
}
|
||||
NVIC->ISER[0] |= 0x01<<num_tim;
|
||||
NVIC->IP[num_tim] |= Prio << 4;
|
||||
NVIC->ISER[0] |= 0x01<<num_tim; // On précise quelle interruption on souhaite activé
|
||||
NVIC->IP[num_tim] |= Prio << 4; // On précise la priorité qu'on souhaite lui donner
|
||||
|
||||
}
|
||||
|
||||
void init_encoder_timer(TIM_TypeDef * Timer) //voir page 391
|
||||
{
|
||||
Timer->SMCR = 0x1;
|
||||
|
||||
}
|
||||
|
||||
void TIM2_IRQHandler (void)
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
if(tim_ptr2_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
(*tim_ptr2_func)();
|
||||
}
|
||||
TIM2->SR &= ~(1<<0) ;
|
||||
TIM2->SR &= ~(1<<0) ; // Remet à 0 le flag de l'interruption
|
||||
}
|
||||
|
||||
void TIM3_IRQHandler (void)
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
if(tim_ptr3_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
(*tim_ptr3_func)();
|
||||
}
|
||||
TIM3->SR &= ~(1<<0) ;
|
||||
}
|
||||
|
||||
void TIM4_IRQHandler (void)
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
if(tim_ptr4_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
(*tim_ptr4_func)();
|
||||
}
|
||||
TIM4->SR &= ~(1<<0) ;
|
||||
}
|
||||
|
||||
void TIM1_UP_IRQHandler (void) // à vérifier
|
||||
void TIM1_UP_IRQHandler (void)
|
||||
{
|
||||
if(ptr_func!=0)
|
||||
if(tim_ptr1_func!=0)
|
||||
{
|
||||
(*ptr_func)();
|
||||
(*tim_ptr1_func)();
|
||||
}
|
||||
TIM1->SR &= ~(1<<0) ;
|
||||
}
|
||||
}
|
|
@ -10,29 +10,39 @@
|
|||
void Mafonction_IT (void);
|
||||
MyGPIO_Struct_TypeDef PA5;
|
||||
MyGPIO_Struct_TypeDef PC13;
|
||||
MyTimer_Struct_TypeDef timer2;
|
||||
MyTimer_Struct_TypeDef timer2,timer3;
|
||||
//PA5 LED
|
||||
//PC13 Bouton
|
||||
char X0,X1,Y0,Y1,Z0,Z1;
|
||||
char read_DATA,read_BWR,read_PWRC;
|
||||
int16_t gX,gY,gZ;
|
||||
|
||||
int test =0;
|
||||
XYZ mesures;
|
||||
|
||||
int main ( void )
|
||||
{
|
||||
|
||||
|
||||
PA5.GPIO=GPIOA;
|
||||
PA5.GPIO_Conf=Out_Ppull;
|
||||
PA5.GPIO_Pin=5;
|
||||
MyGPIO_Init(&PA5);
|
||||
timer2.Timer=TIM2;
|
||||
timer2.ARR=35999; //pour avoir 500ms
|
||||
timer2.ARR=18000; //pour avoir 250ms
|
||||
timer2.PSC=1000;
|
||||
MyTimer_Base_Init(&timer2);
|
||||
MyTimer_ActiveIT(timer2.Timer,1, &Mafonction_IT);
|
||||
MyTimer_Base_Start(timer2.Timer);
|
||||
|
||||
timer3.Timer=TIM3;
|
||||
timer3.ARR=7200; //pour avoir 100ms
|
||||
timer3.PSC=1000;
|
||||
MyTimer_Base_Init(&timer3);
|
||||
//MyTimer_ActiveIT(timer3.Timer,2, &Mafonction_IT);
|
||||
MyTimer_Base_Start(timer3.Timer);
|
||||
MyPWM_init(timer3.Timer,3);
|
||||
|
||||
|
||||
MySPI_Init(SPI1);
|
||||
rouli_InitAccel();
|
||||
MySPI_Send(READ|DATA_FORMAT);
|
||||
|
@ -44,8 +54,19 @@ int main ( void )
|
|||
|
||||
while(1)
|
||||
{
|
||||
rouli_GetAccel(&mesures);
|
||||
//printf("%f, %f, %f\n",mesures.gX,mesures.gY,mesures.gZ);
|
||||
rouli_GetAccel(&mesures);
|
||||
if(timer2.Timer->SR&=0x04)
|
||||
{
|
||||
|
||||
if((mesures.gY <= (-0.7)) || (mesures.gY >= 0.7))
|
||||
{
|
||||
MyPWM_Duty(timer3.Timer,3,71);//0.985ms
|
||||
test = test+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -43,4 +43,6 @@ void rouli_GetAccel (XYZ * axe)
|
|||
axe->gZ = ((short int)((Z1<<8)|Z0))*0.004;
|
||||
}
|
||||
|
||||
// axe y entre -0.5 et 1
|
||||
// axe y entre -0.7 et 0.7
|
||||
|
||||
|
|
@ -312,7 +312,7 @@
|
|||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGTARM</Key>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=1190,328,1611,733,1)(121=1101,403,1522,808,0)(122=1281,393,1702,798,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=-1,-1,-1,-1,0)(132=-1,-1,-1,-1,0)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
<Name>(1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0)(100=-1,-1,-1,-1,0)(110=-1,-1,-1,-1,0)(111=-1,-1,-1,-1,0)(1011=-1,-1,-1,-1,0)(180=-1,-1,-1,-1,0)(120=900,708,1321,1113,0)(121=1464,713,1885,1118,1)(122=1281,393,1702,798,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=-1,-1,-1,-1,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=-1,-1,-1,-1,0)(130=-1,-1,-1,-1,0)(131=783,105,1377,799,1)(132=1326,11,1920,705,1)(133=-1,-1,-1,-1,0)(160=-1,-1,-1,-1,0)(161=-1,-1,-1,-1,0)(162=-1,-1,-1,-1,0)(210=-1,-1,-1,-1,0)(211=-1,-1,-1,-1,0)(220=-1,-1,-1,-1,0)(221=-1,-1,-1,-1,0)(230=-1,-1,-1,-1,0)(231=-1,-1,-1,-1,0)(232=-1,-1,-1,-1,0)(233=-1,-1,-1,-1,0)(150=-1,-1,-1,-1,0)(151=-1,-1,-1,-1,0)</Name>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
|
@ -342,6 +342,11 @@
|
|||
<WinNumber>1</WinNumber>
|
||||
<ItemText>mesures</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>test</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<MemoryWindow1>
|
||||
<Mm>
|
||||
|
@ -473,10 +478,10 @@
|
|||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>6</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\Rouli.c</PathWithFileName>
|
||||
<PathWithFileName>.\Sources\Rouli.c</PathWithFileName>
|
||||
<FilenameWithoutPath>Rouli.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
|
|
|
@ -411,7 +411,7 @@
|
|||
<File>
|
||||
<FileName>Rouli.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\Rouli.c</FilePath>
|
||||
<FilePath>.\Sources\Rouli.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
|
@ -828,7 +828,7 @@
|
|||
<File>
|
||||
<FileName>Rouli.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\Rouli.c</FilePath>
|
||||
<FilePath>.\Sources\Rouli.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
|
|
Loading…
Reference in a new issue