fin act2 + Timer 1

This commit is contained in:
Alix Chagot 2023-03-21 16:32:04 +01:00
parent 125c801a01
commit e3014aefef
3 changed files with 38 additions and 8 deletions

View file

@ -4,12 +4,14 @@
void plantage(void) { void plantage(void) {
while(1); while(1);
} }
void (*IT_Tim1) (void) = plantage;
void (*IT_Tim2) (void) = plantage; void (*IT_Tim2) (void) = plantage;
void (*IT_Tim3) (void) = plantage; void (*IT_Tim3) (void) = plantage;
void (*IT_Tim4) (void) = plantage; void (*IT_Tim4) (void) = plantage;
void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer) { void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer) {
if ((Timer->Timer) == TIM1)
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
if ((Timer->Timer) == TIM2) if ((Timer->Timer) == TIM2)
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
if ((Timer->Timer) == TIM3) if ((Timer->Timer) == TIM3)
@ -23,7 +25,11 @@ void MyTimer_Base_Init(MyTimer_Struct_Typedef * Timer) {
void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)) { void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)) {
Timer->DIER |= TIM_DIER_UIE; Timer->DIER |= TIM_DIER_UIE;
if (Timer == TIM2) {
NVIC_EnableIRQ(TIM1_BRK_IRQn);
NVIC_SetPriority(TIM1_BRK_IRQn, Prio);
IT_Tim1 = IT_function;
}
if (Timer == TIM2) { if (Timer == TIM2) {
NVIC_EnableIRQ(TIM2_IRQn); NVIC_EnableIRQ(TIM2_IRQn);
NVIC_SetPriority(TIM2_IRQn, Prio); NVIC_SetPriority(TIM2_IRQn, Prio);
@ -41,6 +47,11 @@ void MyTimer_ActiveIT(TIM_TypeDef * Timer, char Prio, void (*IT_function) (void)
} }
} }
void TIM1_IRQHandler(void) {
TIM1->SR &= ~TIM_SR_UIF;
(*IT_Tim1)();
}
void TIM2_IRQHandler(void) { void TIM2_IRQHandler(void) {
TIM2->SR &= ~TIM_SR_UIF; TIM2->SR &= ~TIM_SR_UIF;
(*IT_Tim2)(); (*IT_Tim2)();
@ -75,7 +86,26 @@ void MyTimer_PWM(TIM_TypeDef * Timer ,char Channel)
} }
Timer->CCER |= (TIM_CCER_CC1E << (4*(Channel-1))); Timer->CCER |= (TIM_CCER_CC1E << (4*(Channel-1)));
if(Timer == TIM1)
{
TIM1->BDTR |= 0x8000;
PWM_OUT.GPIO = GPIOA;
switch (Channel) {
case 1:
PWM_OUT.GPIO_Pin = 8;
break;
case 2:
PWM_OUT.GPIO_Pin = 9;
break;
case 3:
PWM_OUT.GPIO_Pin = 10;
break;
case 4:
PWM_OUT.GPIO_Pin = 11;
break;
}
}
if(Timer == TIM2) if(Timer == TIM2)
{ {
PWM_OUT.GPIO = GPIOA; PWM_OUT.GPIO = GPIOA;

View file

@ -17,16 +17,16 @@ int main(void) {
b1.GPIO = GPIOC; b1.GPIO = GPIOC;
b1.GPIO_Pin = 13; b1.GPIO_Pin = 13;
b1.GPIO_Conf = In_PullUp; b1.GPIO_Conf = In_PullUp;
t3.Timer = TIM3; t3.Timer = TIM1;
t3.ARR = 7199; t3.ARR = 7199;
t3.PSC = 4999; t3.PSC = 4999;
MyGPIO_Init(&led2); MyGPIO_Init(&led2);
MyGPIO_Init(&b1); MyGPIO_Init(&b1);
MyTimer_Base_Init(&t3); MyTimer_Base_Init(&t3);
MyTimer_ActiveIT(TIM3, 0, &changer_led); MyTimer_ActiveIT(TIM1, 0, &changer_led);
MyTimer_PWM(TIM3, 1); MyTimer_PWM(TIM1, 1);
MyTimer_DutyCycle(TIM3,1,10); MyTimer_DutyCycle(TIM1,1,10);
MyTimer_Base_Start(t3); MyTimer_Base_Start(t3);

View file

@ -125,7 +125,7 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGDARM</Key> <Key>DLGDARM</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=920,358,1341,785,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=120,153,405,449,0)(130=-1,-1,-1,-1,0)(131=931,121,1525,872,0)(132=973,161,1567,912,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)(234=-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=920,358,1341,785,0)(121=-1,-1,-1,-1,0)(122=-1,-1,-1,-1,0)(123=-1,-1,-1,-1,0)(140=-1,-1,-1,-1,0)(240=105,137,504,482,0)(190=-1,-1,-1,-1,0)(200=-1,-1,-1,-1,0)(170=120,153,405,449,0)(130=624,173,1218,924,0)(131=931,121,1525,872,0)(132=973,161,1567,912,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)(234=-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>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>