Homogénéisation visuelle
This commit is contained in:
parent
766683d008
commit
d8cda927b5
12 changed files with 87 additions and 73 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <DriverGPIO.h>
|
||||
#include "DriverGPIO.h"
|
||||
|
||||
// Constantes
|
||||
#define In_Floating 0x4
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <Horloge.h>
|
||||
#include "Horloge.h"
|
||||
|
||||
static void (*TIM2_Appel)(void) = 0;
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ void Timer_Init(TIM_TypeDef *Timer, unsigned short Autoreload, unsigned short Pr
|
|||
Timer->EGR |= TIM_EGR_UG;
|
||||
}
|
||||
|
||||
|
||||
//La fonction TIM2_IRQHandler existe déjà dans le processeur, on l'a juste redifint, tel qu'à chaque overflow on met un bit 1 dans GPIOA_ODR
|
||||
void TIM2_IRQHandler(void) { //On redefinit le IRQHandler qui est déjà ecrit dans le code source
|
||||
if (TIM2->SR & TIM_SR_UIF) { //On met le bit de overflow à un dès qu'on a overflow
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#include <stm32f10x.h>
|
||||
#include "I2C.h"
|
||||
|
||||
void initI2C(){
|
||||
RCC -> APB1ENR |= 0x1 << 21; // Enable clock
|
||||
I2C1 -> CR1 |= 0x1 << 0; // Peripheral enable
|
||||
|
||||
void initI2C() {
|
||||
RCC -> APB1ENR |= 0x1 << 21; // Enable clock
|
||||
I2C1 -> CR1 |= 0x1 << 0; // Peripheral enable
|
||||
I2C1 -> CR1 &= ~(0x1 << 1); // I2C mode
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <stm32f10x.h>
|
||||
#include <MYGPIO.h>
|
||||
#include "MYGPIO.h"
|
||||
|
||||
|
||||
//FONCTIONS POUR LE DEL INTERNE
|
||||
|
|
@ -28,19 +28,22 @@ void initGPIO_Interne(void) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int boutonAppuye_Interne(void) {
|
||||
return BUTTON_GPIO_INTERNE->IDR &(1<<BUTTON_PIN_INTERNE);
|
||||
}
|
||||
|
||||
|
||||
void allumerDEL_Interne(void) {
|
||||
LED_GPIO_INTERNE->ODR |= (0x01 << LED_PIN_INTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 1 comme ca allume le LED GREEN
|
||||
}
|
||||
|
||||
void eteindreDEL_Interne(void) {
|
||||
LED_GPIO_INTERNE->ODR &= ~(0x01 << LED_PIN_EXTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 0 comme ca eteint le LED GREEN
|
||||
//ALlumer un LED externe, PB8/D15 OUTPUT, Bouton Poussoir PB9/D14
|
||||
}
|
||||
|
||||
|
||||
|
||||
void eteindreDEL_Interne(void) { // Allumer un LED externe, PB8/D15 OUTPUT, Bouton Poussoir PB9/D14
|
||||
LED_GPIO_INTERNE->ODR &= ~(0x01 << LED_PIN_EXTERNE) ; //On essaie de mettre en position PA5 de GPIOC_ODR un 0 comme ca eteint le LED GREEN
|
||||
}
|
||||
|
||||
|
||||
void commuterDEL_Interne(void) {
|
||||
LED_GPIO_INTERNE->ODR ^= (0x01 << LED_PIN_INTERNE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <Timer.h>
|
||||
#include <MyTimer.h>
|
||||
#include <PWM.h>
|
||||
#include <DriverGPIO.h>
|
||||
#include <Horloge.h>
|
||||
#include "Timer.h"
|
||||
#include "MyTimer.h"
|
||||
#include "PWM.h"
|
||||
#include "DriverGPIO.h"
|
||||
#include "Horloge.h"
|
||||
|
||||
// Constantes
|
||||
#define ARR_TIM1 0xFFAD
|
||||
|
|
@ -23,7 +23,7 @@ void Test(void) {
|
|||
MyGPIO_Toggle(GPIOA, 8);
|
||||
}
|
||||
|
||||
|
||||
// LES COMMENTAIRES SONT POUR ACTIVER DES TIMERS QUE L'ON UTILISE PAS POUR LE MOMENT
|
||||
void ConfigureTimers() {
|
||||
// Config ARR & PSC
|
||||
//MyTimer_Base_Init(TIM2, ARR_TIM2, PSC_TIM2);
|
||||
|
|
@ -40,7 +40,7 @@ void ConfigureTimers() {
|
|||
}
|
||||
|
||||
|
||||
void ConfigureIT() { // Activate general interuption with a function and priority
|
||||
void ConfigureIT() { // Activate general interuption with a function and priority
|
||||
//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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <DriverGPIO.h>
|
||||
#include <MyTimer.h>
|
||||
#include "DriverGPIO.h"
|
||||
#include "MyTimer.h"
|
||||
|
||||
void My_USART_Config(USART_TypeDef* USARTx, uint32_t baudrate) { //QUE POUR USART1
|
||||
// Configuration PA9 (Tx) en Alternate Function Push-Pull
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
#include "stm32f10x.h"
|
||||
#include "PWM.h"
|
||||
|
||||
void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){
|
||||
|
||||
void MyTimer_PWM(TIM_TypeDef * Timer, int Channel) {
|
||||
int pwrmd;
|
||||
#if POWERMODE //Powermode 1
|
||||
pwrmd = 0b110;
|
||||
#else
|
||||
pwrmd = 0b111; //Powermode 2
|
||||
#endif
|
||||
|
||||
if (Channel == 1){
|
||||
if (Channel == 1){
|
||||
Timer->CCMR1 &= ~(0b111<<4); //On clear les trois bits qui sont de pwm
|
||||
Timer->CCMR1 |= (pwrmd<<4); //On affecte le powermode au bits de lecture pour le µ-controlleur
|
||||
Timer->CCMR1 |= TIM_CCMR1_OC1PE; //Update preload, il n'affecte pas le valeur avant que la prochaine cycle
|
||||
|
|
@ -66,20 +66,20 @@ void MyTimer_PWM(TIM_TypeDef * Timer , int Channel){
|
|||
if (Timer == TIM2){GPIOA->CRL &= ~(0xF<<3*4); GPIOA->CRL |= (0xA<<3*4);}
|
||||
if (Timer == TIM3){GPIOB->CRL &= ~(0xF<<1*4); GPIOB->CRL |= (0xA<<1*4);}
|
||||
if (Timer == TIM4){GPIOB->CRH &= ~(0xF<<1*4); GPIOB->CRH |= (0xA<<1*4);}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Une fonction qui met le bon PWM voulu
|
||||
int Set_DutyCycle_PWM(TIM_TypeDef *Timer, int Channel, int DutyC){
|
||||
int CCR_VAL = (Timer -> ARR + 1) * DutyC / 100;
|
||||
switch (Channel){
|
||||
case 1: Timer->CCR1 = CCR_VAL;
|
||||
case 2: Timer->CCR2 = CCR_VAL;
|
||||
case 3: Timer->CCR3 = CCR_VAL;
|
||||
case 4: Timer->CCR4 = CCR_VAL;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
Timer->EGR |= TIM_EGR_UG;
|
||||
int CCR_VAL = (Timer -> ARR + 1) * DutyC / 100;
|
||||
switch (Channel){
|
||||
case 1: Timer->CCR1 = CCR_VAL;
|
||||
case 2: Timer->CCR2 = CCR_VAL;
|
||||
case 3: Timer->CCR3 = CCR_VAL;
|
||||
case 4: Timer->CCR4 = CCR_VAL;
|
||||
default: break;
|
||||
}
|
||||
Timer->EGR |= TIM_EGR_UG;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <Timer.h>
|
||||
#include "Timer.h"
|
||||
|
||||
|
||||
void MyTimer_Base_Init(TIM_TypeDef * Timer, unsigned short ValARR, unsigned short ValPSC) { // Configuration du timer
|
||||
|
|
|
|||
|
|
@ -1,36 +1,37 @@
|
|||
#include <stm32f10x.h>
|
||||
#include <Horloge.h>
|
||||
#include <stdlib.h>
|
||||
#include <MySPI.h>
|
||||
#include <stdint.h>
|
||||
#include <Accelerometre.h>
|
||||
#include <Servo.h>
|
||||
#include "Horloge.h"
|
||||
#include "stdlib.h"
|
||||
#include "MySPI.h"
|
||||
#include "stdint.h"
|
||||
#include "Accelerometre.h"
|
||||
#include "Servo.h"
|
||||
|
||||
|
||||
void initAccelo(void) {
|
||||
//MySPI_Init(SPI1);
|
||||
MySPI_Init(SPI1);
|
||||
// Power_CTL register = 0x2D ? write 0x08 (MEASURE = 1)
|
||||
MySPI_Clear_NSS();
|
||||
MySPI_Send(0x31); // DATA_FORMAT
|
||||
MySPI_Send(0b00001101); // Justify met le MSB à gauche et b0 et b1 donne une resolution de +-2g
|
||||
MySPI_Set_NSS();
|
||||
|
||||
// Power_CTL register = 0x2D ? write 0x08 (MEASURE = 1)
|
||||
//MySPI_Clear_NSS();
|
||||
//MySPI_Send(0x31); // DATA_FORMAT
|
||||
//MySPI_Send(0b00001101); // Justify met le MSB à gauche et b0 et b1 donne une resolution de +-2g
|
||||
//MySPI_Set_NSS();
|
||||
|
||||
//MySPI_Clear_NSS();
|
||||
//MySPI_Send(0x2D & 0x3F); // Écriture de l'adresse (pas de bit de read!)
|
||||
//MySPI_Send(0x08); // Affectation du bit MEASURE
|
||||
//MySPI_Set_NSS();
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // Activation de l'horloge Utiliser une service pour cela peut-être ???
|
||||
for (volatile int i = 0; i < 10000; i++); // small delay
|
||||
MySPI_Clear_NSS();
|
||||
MySPI_Send(0x2D & 0x3F); // Écriture de l'adresse (pas de bit de read!)
|
||||
MySPI_Send(0x08); // Affectation du bit MEASURE
|
||||
MySPI_Set_NSS();
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; // Activation de l'horloge Utiliser une service pour cela peut-être ???
|
||||
for (volatile int i = 0; i < 10000; i++); // small delay
|
||||
}
|
||||
|
||||
|
||||
uint16_t * RecupAccelo(void) { // Recuperation des donnees de l'accelerometre
|
||||
static uint16_t Messie[3];
|
||||
uint8_t buf[6];
|
||||
//MySPI_Clear_NSS();
|
||||
MySPI_Clear_NSS();
|
||||
// Lecture multi-octet à partir de 0x32 (X0, X1, Y0, Y1, Z0 et Z1)
|
||||
//MySPI_Send(0x80 | 0x40 | 0x32); // On envoie RW MB A5 ... A0 pour recuperer les données
|
||||
//for (int i = 0; i < 6; i++) {buf[i] = (uint8_t)MySPI_Read();} // Lecture des 6 registres en séquenciel
|
||||
//MySPI_Set_NSS();
|
||||
MySPI_Send(0x80 | 0x40 | 0x32); // On envoie RW MB A5 ... A0 pour recuperer les données
|
||||
for (int i = 0; i < 6; i++) {buf[i] = (uint8_t)MySPI_Read();} // Lecture des 6 registres en séquenciel
|
||||
MySPI_Set_NSS();
|
||||
|
||||
// Conversion des données récupérés en uint16_t
|
||||
Messie[0] = (uint16_t)(buf[1] << 8 | buf[0]); // X
|
||||
|
|
@ -39,6 +40,7 @@ uint16_t * RecupAccelo(void) { // Recuperation des donnees de l'accelerometre
|
|||
return Messie;
|
||||
}
|
||||
|
||||
|
||||
void initLacheur(void) {
|
||||
GPIOB->CRH &= ~(0xF << (0 * 4));
|
||||
GPIOB->CRH |= (0xA << (0 * 4)); //On met GPIOB.8 en mode output 2Mhz, alternate pp
|
||||
|
|
@ -46,19 +48,24 @@ void initLacheur(void) {
|
|||
Timer_Init(TIM4, 0xFFFF, 22);
|
||||
}
|
||||
|
||||
|
||||
void LacheVoile(int AngelLim, uint16_t moyennen) {
|
||||
volatile uint16_t Val_lim = 0x1E20 - 60*AngelLim;
|
||||
if (moyennen<Val_lim){
|
||||
Servo_Moteur(0, TIM4, 3); // PB7 (TIM4Ch3)
|
||||
}
|
||||
}
|
||||
//int actualiserTableau(int i ){
|
||||
|
||||
|
||||
//int actualiserTableau(int i) {
|
||||
// moyenne[i] = RecupAccelo()[2]; // Récuperation et ajout de la valeur plus récente dans le tableau dans la position i
|
||||
// i++;
|
||||
// if (i >= LONGUEUR_MOY) {i = 0;} // Géstion de la position i dans le tableau pour la moyenne glissante
|
||||
// return i;
|
||||
//}
|
||||
//uint16_t moyenneGlissante(){
|
||||
|
||||
|
||||
//uint16_t moyenneGlissante() {
|
||||
// sum = 0;
|
||||
// for (int j = 0; j < LONGUEUR_MOY; j++){sum += moyenne[j];} moy = sum / LONGUEUR_MOY; // Calcul de la moyenne glissante
|
||||
// return(moy);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#define POSITIONS (360*4) //0x5A0
|
||||
|
||||
void configEncoder(TIM_TypeDef * Timer){
|
||||
void configEncoder(TIM_TypeDef * Timer) {
|
||||
// Timer
|
||||
EnableTimer(Timer);
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ void configEncoder(TIM_TypeDef * Timer){
|
|||
}
|
||||
|
||||
|
||||
int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent
|
||||
int angleVent(TIM_TypeDef * Timer) { // Returner l'angle du vent
|
||||
int angle =(((Timer -> CNT*360)/POSITIONS ));
|
||||
if (angle > 180){
|
||||
angle = 360 - angle; // Pour que l'angle soit entre 0 et 180
|
||||
|
|
@ -39,7 +39,8 @@ int angleVent (TIM_TypeDef * Timer){ // Returner l'angle du vent
|
|||
return(angle);
|
||||
}
|
||||
|
||||
int vent2voile(int angle){ // Conversion angle vent à angle voile
|
||||
|
||||
int vent2voile(int angle) { // Conversion angle vent à angle voile
|
||||
if(angle < 45){
|
||||
return 0; // Les voiles restent immobiles
|
||||
}
|
||||
|
|
@ -48,8 +49,8 @@ int vent2voile(int angle){ // Conversion angle vent
|
|||
}
|
||||
}
|
||||
|
||||
// Localisation de z
|
||||
void LocaliserZero(void){
|
||||
|
||||
void LocaliserZero(void) { // Localisation de z
|
||||
int Z_trouve = 0;
|
||||
while (Z_trouve != 1){
|
||||
if(MyGPIO_Read(GPIOA,8)){ // Index
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
#include <Servo.h>
|
||||
#include <DriverGPIO.h>
|
||||
#include <PWM.h>
|
||||
#include <Horloge.h>
|
||||
#include "Servo.h"
|
||||
#include "DriverGPIO.h"
|
||||
#include "PWM.h"
|
||||
#include "Horloge.h"
|
||||
|
||||
void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel){ // Controle du moteur
|
||||
|
||||
void Servo_Moteur(int angle, TIM_TypeDef * Timer, int Channel) { // Controle du moteur
|
||||
int dutyCycle = (5* angle + 5*90)/90; // 5-10 % Duty Cycle
|
||||
Set_DutyCycle_PWM(Timer, Channel, dutyCycle);
|
||||
}
|
||||
|
||||
void initServo(TIM_TypeDef * Timer, int Channel){ // Config du moteur servo
|
||||
|
||||
void initServo(TIM_TypeDef * Timer, int Channel) { // Config du moteur servo
|
||||
if (Timer == TIM4) {
|
||||
Timer_Init(TIM4, 0xFFFF, 22); // Pour obtenir un période de 20 ms
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue