TP_microcontroleur/timer_act2/Source/principal.c
2021-09-27 16:54:47 +02:00

53 lines
1.1 KiB
C

#include "stm32f10x.h"
#include "Driver_GPIO.h"
#include "Driver_TIMER.h"
MyTimer_Struct_TypeDef MonTimer ;
MyGPIO_Struct_TypeDef greenLed ;
MyGPIO_Struct_TypeDef sortiePWM ;
void handle_TIM2(void) {
MyGPIO_Toggle(greenLed.GPIO, greenLed.GPIO_Pin);
}
int main(void) {
Activate_TIM(2);
MyGPIO_Activate(1);
//sortie PWM timer 2 channel 3 sur pin PA2
sortiePWM.GPIO = GPIOA;
sortiePWM.GPIO_Pin = 2 ;
sortiePWM.GPIO_Conf = AltOut_Ppull ;
MyGPIO_Init(&sortiePWM);
/*greenLed.GPIO = GPIOA;
greenLed.GPIO_Pin = 5 ;
greenLed.GPIO_Conf = Out_Ppull ;
MyGPIO_Init(&greenLed); */
MonTimer.Timer = TIM2 ;
//méthode PGCD
//MonTimer.ARR = 65454;
//MonTimer.PSC = 550 ;
//MonTimer.ARR = 18000;
//MonTimer.PSC = 2000 ;
//Pour une fréquence de 100kHz
MonTimer.ARR = 719 ;
MonTimer.PSC = 0 ;
MyTimer_Base_Init(&MonTimer);
/*MyGPIO_Set(greenLed.GPIO,greenLed.GPIO_Pin);
MyTimer_Active_IT(TIM2, 1, handle_TIM2);*/
MyTimer_Base_Start(MonTimer.Timer);
MyTimer_PWM(MonTimer.Timer, 3);
MyTimer_PWM_set_cycle(MonTimer.Timer, 0.20, 3);
while(1) {}
return 0;
}