From 9a37146148e100f503ef0dd919f4233b64795e18 Mon Sep 17 00:00:00 2001 From: pfrison Date: Wed, 8 May 2019 23:18:30 +0200 Subject: [PATCH] Programme robot --- Robot/deplacement.c | 23 ++++++++++++++++------- Robot/deplacement.h | 28 ++++------------------------ Robot/main.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ Robot/tlc5947.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Robot/tlc5947.h | 9 +++++++++ 5 files changed, 140 insertions(+), 49 deletions(-) create mode 100644 Robot/tlc5947.c create mode 100644 Robot/tlc5947.h diff --git a/Robot/deplacement.c b/Robot/deplacement.c index 3562e25..db1a129 100644 --- a/Robot/deplacement.c +++ b/Robot/deplacement.c @@ -6,27 +6,36 @@ #define STEP_DROIT 0x20 // pin 12 #define DIR_DROIT 0x10 // pin 11 +// valeurs a remplacer par ceux donne par PercTeacher const uint8_t deltaL[] = {}; const uint8_t delaiL[] = {}; const uint8_t deltaR[] = {}; const uint8_t delaiR[] = {}; - -#define GAUCHE 0 -#define DROIT 1 +#define N_DEPLACEMENT 0 void init_deplacements(void){ DDRH |= STEP_GAUCHE | DIR_GAUCHE; DDRB |= STEP_DROIT | DIR_DROIT; } -uint16_t* deplacement_commande_suivante(uint16_t num){ +static uint16_t* deplacement_commande_suivante(uint16_t num){ return {deltaL[num], delaiL[num], deltaR[num], delaiR[num]}; } -void deplacement_moteur_gauche(uint16_t delta, uint16_t delai){ deplacement_moteur(GAUCHE, delta, delai); } -void deplacement_moteur_droit(uint16_t delta, uint16_t delai){ deplacement_moteur(DROIT, delta, delai); } +void deplacement(uint8_t mot){ + int i; + for(i=0; i + +#include "tlc5947.h" + +#define DDR_DLED_CLOCK DDRE +#define PORT_DLED_CLOCK PORTE + +#define DDR_DLED_DATA DDRG +#define PORT_DLED_DATA PORTG + +#define DDR_DLED_LATCH DDRB +#define PORT_DLED_LATCH PORTB + +#define PIN_DLED_CLOCK 0x08 +#define PIN_DLED_DATA 0x20 +#define PIN_DLED_LATCH 0x10 + +void init_LED_Drivers(int nb){ + // LED drivers I/O as outputs + DDR_DLED_CLOCK |= PIN_DLED_CLOCK; + DDR_DLED_DATA |= PIN_DLED_DATA; + DDR_DLED_LATCH |= PIN_DLED_LATCH; + // Set LATCH output low + PORT_DLED_LATCH &= ~PIN_DLED_LATCH; +} + + +void set_LED_Drivers(unsigned int pwm[], int nb){ + // Set LATCH output low + PORT_DLED_LATCH &= ~PIN_DLED_LATCH; + // 24 channels per TLC5947 + int i; + for(i=DLED_CHANNELS*nb-1; i>=0; i--){ + // 12 bits per channel, send MSB first + int v=pwm[i]; + int j; + for(j=0; j<12; j++){ + // Set CLOCK output low + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK; + + // Set DATA as stated by bit #j of i + if(v & 0x0800) + PORT_DLED_DATA |= PIN_DLED_DATA; + else + PORT_DLED_DATA &= ~PIN_DLED_DATA; + + // Set CLOCK output HIGH + PORT_DLED_CLOCK |= PIN_DLED_CLOCK; + v <<= 1; + } + } + // Set CLOCK output low + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK; + + // Set LATCH output high + PORT_DLED_LATCH |= PIN_DLED_LATCH; + // Set LATCH output low + PORT_DLED_LATCH &= ~PIN_DLED_LATCH; +} diff --git a/Robot/tlc5947.h b/Robot/tlc5947.h new file mode 100644 index 0000000..dffe997 --- /dev/null +++ b/Robot/tlc5947.h @@ -0,0 +1,9 @@ +#ifndef TLC5947 +#define TLC5947 + +#define DLED_CHANNELS 24 + +void init_LED_Drivers(int nb); +void set_LED_Drivers(unsigned int pwm[], int nb); + +#endif -- libgit2 0.21.2