BE_VOILIER/CantoOrvikPilotes/Source/MyTimer.c

58 lines
1.7 KiB
C

#include "stm32f10x.h"
#include "Nucleo.h"
#include "Timer.h"
#include "PWM.h"
#include "GPIO.h"
// Variables
#define ARR_TIM1 0xFFAD
#define PSC_TIM1 0xFF
#define ARR_TIM2 0xFFAD
#define PSC_TIM2 0x0225
#define ARR_TIM3 0x2CF
#define PSC_TIM3 0x0
volatile int g_tick_count;
void Test(void){
// Signal
g_tick_count++;
TogglePin(GPIOA, 8);
}
void ConfigureBroches(){
ConfigureGPIO(GPIOA, 6, 4, Push-Pull); // Cela équivaut à :
// GPIOA->CRL &= ~(0xF << 6*4); // clean pin 6
// GPIOA->CRL |= (0xB << 6*4); // Alternate Function output, Push-Pull max 50 Hz
// Exemples d'_tilisation
//Mettre Broche 5 sur input Pull-up/down
ConfigureGPIO(GPIOC, 3, 0, Pull-Up);
//GPIOC ->CRL &= ~(0xF << (4 *3));
//GPIOC ->CRL |= (0x1 << (4 *3));
//Mettre Broche 5 sur input Pull-up/down
ConfigureGPIO(GPIOA, 5, 0, Pull-Up);
//GPIOA ->CRL &= ~(0xF << (4 *5));
//GPIOA ->CRL |= (0x3 << (4 *5));
//Mettre Broche D7 sur input Open drain
ConfigureGPIO(GPIOA, 0, 0, Open-Drain);
//GPIOA ->CRH &= ~(0xF << (4 *0));
//GPIOA ->CRH |= (0x7 << (4 *0));
}
void ConfigureTimers(){
MyTimer_Base_Init(TIM2, ARR_TIM2, PSC_TIM2);
MyTimer_Base_Init(TIM1, ARR_TIM1, PSC_TIM1);
MyTimer_Base_Init(TIM3, ARR_TIM2, PSC_TIM2);
}
void ConfigureIT(){
//MyTimer_ActiveIT(TIM2, 4, Test); //start interruption with priority 4
//MyTimer_ActiveIT(TIM1, 4, Test); //start interruption with priority 4
MyTimer_ActiveIT(TIM3, 4, Test); //start interruption with priority 4
}
void ConfigurePWM(){
MyTimer_PWM(TIM1, 1);
MyTimer_Set_DutyCycle(TIM1, 1, 20.0);
}