Gestion avance demandée négative
This commit is contained in:
parent
afe804c178
commit
870a31e834
174
stroboduino.ino
174
stroboduino.ino
|
@ -1,81 +1,94 @@
|
|||
//Stroboduino
|
||||
char Ver[] = "cg140417";
|
||||
//------------------------------------------------------------------------------
|
||||
// *** STROBODUINO ***
|
||||
//------------------------------------------------------------------------------
|
||||
char Ver[] = "cg230417";
|
||||
|
||||
#include <TimerOne.h>
|
||||
#include <Encoder.h>
|
||||
#include <EEPROM.h>
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PARAMETRES
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
byte D_Flash = 10; //Durée du flash en µs, autour de 10µs
|
||||
const int deg_Initial = 10; //Affiché au demarrage
|
||||
byte Ncyl = 2;
|
||||
byte Refresh = 100;
|
||||
//bool att_tour = 0; // true si on attend un tour supplémentaire avant le Flash
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// CONSTANTES
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define Etin 2 // Entrée bobine
|
||||
#define Inter 5 // Inter du codeur
|
||||
#define Flash 11 // Flash
|
||||
#define Codeur_A 3 // D3 pour entrée codeur A sous interruption
|
||||
#define Codeur_B 4 // D4 pour entrée codeur B
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// VARIABLES
|
||||
//-------------------------------------------------------------------------------
|
||||
|
||||
bool debug = 0; // Variable pour debug
|
||||
|
||||
int signed long T = 0; // Periode en cours(signée pour le calcul de D_deg)
|
||||
int unsigned long prec_H = 0; // Heure du front precedent en µs
|
||||
volatile int signed deg_dem = deg_Initial; // Compteur des degrés demandés
|
||||
int signed long D_deg = 0; // Délai pour deg_dem degrès en µs
|
||||
int unsigned long N = 0; // N en tours/mn
|
||||
int unsigned long Nc = 0; // Pour le calcul de N
|
||||
unsigned long pm = 0; // Previous millis pour Refresh LCD
|
||||
byte modconfig = 0; // Flag pour savoir si on est en mode config
|
||||
int degT = 720 / Ncyl; // Degrés entre 2 étincelles
|
||||
|
||||
LiquidCrystal lcd( 9, 17, 15, 16, 14, 10);
|
||||
//lcd(RS, E, D4, D5, D6, D7)
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// PARAMETRES
|
||||
//-----------------------------------------------------------
|
||||
|
||||
byte D_Flash = 10; //Durée du flash en µs, autour de 10µs
|
||||
const int deg_Initial = 10; //Affiché au demarrage
|
||||
byte Ncyl = 2;
|
||||
byte Refresh = 100;
|
||||
bool att_tour = 0; // true si on attend un tour supplémentaire avant le Flash
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// CONSTANTES
|
||||
//-----------------------------------------------------------
|
||||
|
||||
#define Etin 2
|
||||
#define Inter 5 //Inter du codeur
|
||||
#define Flash 11 //Flash
|
||||
#define Codeur_A 3 //D2 pour entrée codeur A sous interruption
|
||||
#define Codeur_B 4 //D3 pour entrée codeur B
|
||||
|
||||
//------------------------------------------------------------
|
||||
// VARIABLES
|
||||
//------------------------------------------------------------
|
||||
|
||||
Encoder Enco(Codeur_A, Codeur_B);
|
||||
int signed long T = 0; //Periode en cours(signée pour le calcul de D_deg)
|
||||
int unsigned long prec_H = 0; //Heure du front precedent en µs
|
||||
int unsigned long D_deg = 0; //Délai pour deg_dem degrès en µs,environ T/2, donc tj > 0
|
||||
int unsigned long N = 0; //N en tours/mn, peut monter à plus de 44 000, 4 temps
|
||||
int unsigned long Nc = 0; //Pour le calcul de N
|
||||
volatile int signed deg_dem = deg_Initial; //Compteur des degrés demandés,affiché au LCD, <=0 possible
|
||||
unsigned long pm = 0; //Previous millis pour Refresh LCD
|
||||
byte modconfig = 0; //Flag pour savoir si on est en mode config
|
||||
int degT = 720 / Ncyl; // Degrés entre 2 étincelles
|
||||
int debug = 0; //Variable pour debug, optionelle
|
||||
|
||||
//-------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------
|
||||
// ISR
|
||||
//-------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
void isrEtincelle() {
|
||||
T = micros() - prec_H; // Calculer T
|
||||
prec_H = micros(); // Heure de début prochaine periode
|
||||
T = micros() - prec_H; // Calcul de T
|
||||
prec_H = micros();
|
||||
Timer1.initialize(D_deg); // Flash après delai D_deg µs
|
||||
}
|
||||
|
||||
void isrFlash(){
|
||||
Timer1.stop();
|
||||
//Flash et flash sur LED13
|
||||
digitalWrite (Flash, 1); delayMicroseconds(D_Flash); digitalWrite (Flash, 0);
|
||||
|
||||
//Flash et flash sur LED13
|
||||
digitalWrite (Flash, 1); delayMicroseconds(D_Flash); digitalWrite (Flash, 0);
|
||||
digitalWrite (LED_BUILTIN, 1); delayMicroseconds(20 * D_Flash); digitalWrite (LED_BUILTIN, 0);
|
||||
//Délai en µs pour les degrés demandés, periode suivante
|
||||
D_deg = float(T * deg_dem) / float(degT);
|
||||
|
||||
//Délai en µs pour les degrés demandés, periode suivante
|
||||
D_deg = float(T * deg_dem) / float(degT);
|
||||
|
||||
// Si retard demandé, on ajout un tour
|
||||
if (deg_dem < 0){D_deg += float(T * 360) / float(degT);}
|
||||
|
||||
// DEBUG
|
||||
if (debug) {Serial.print("T : "); Serial.print(T); Serial.print(" D_deg : "); Serial.println(D_deg);}
|
||||
if (debug) {Serial.print("degT : "); Serial.print(degT); Serial.print(" deg_dem : "); Serial.println(deg_dem);}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------
|
||||
// FONCTIONS
|
||||
//-------------------------------------------------------------
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
void Affic_N_et_deg_dem(){
|
||||
N = Nc / T; //Calculer N en t/mn
|
||||
lcd.setCursor(0, 0); lcd.print(" ");
|
||||
lcd.setCursor(0, 0); lcd.print(N); //Régime tr/min
|
||||
void Affic_N_et_deg_dem(){
|
||||
N = Nc / T; // Calculer N en t/mn
|
||||
lcd.setCursor(0, 0); lcd.print(" ");
|
||||
lcd.setCursor(0, 0); lcd.print(N); // Régime tr/min
|
||||
lcd.setCursor(0, 1); lcd.print(" ");
|
||||
lcd.setCursor(0, 1); lcd.print(deg_dem); lcd.write(223); //Avance °
|
||||
}
|
||||
lcd.setCursor(0, 1); lcd.print(deg_dem); lcd.write(223); // Avance °
|
||||
}
|
||||
|
||||
void Affich_fond_ecran(){ //Affiche le fond d'écran au début ou après la config.
|
||||
void Affich_fond_ecran(){ // Affiche le fond d'écran au début ou après la config.
|
||||
lcd.clear();
|
||||
lcd.setCursor(5, 0);
|
||||
lcd.print("tpm");
|
||||
|
@ -88,7 +101,7 @@ void Regl(byte &var, String titre){
|
|||
lcd.clear();
|
||||
lcd.print(titre);
|
||||
Enco.write(var*4);
|
||||
while (digitalRead(Inter) == 1){ // tant qu'on appuie pas on régle
|
||||
while (digitalRead(Inter) == 1){ // tant qu'on appuie pas on régle
|
||||
var = Enco.read()/4;
|
||||
lcd.setCursor(3, 1);
|
||||
lcd.print(var);
|
||||
|
@ -105,7 +118,7 @@ void Regl(bool &var, String titre){
|
|||
lcd.print(" ");
|
||||
long flag = 0;
|
||||
Enco.write(0);
|
||||
while (digitalRead(Inter) == 1){ // tant qu'on appuie pas on régle
|
||||
while (digitalRead(Inter) == 1){ // tant qu'on appuie pas on régle
|
||||
if (flag != Enco.read()/4) {
|
||||
var = !var;
|
||||
flag = Enco.read()/4;
|
||||
|
@ -126,21 +139,26 @@ void ConfiG() {
|
|||
Regl(Ncyl, "Nb cyl.");
|
||||
Regl(D_Flash, "D Flash");
|
||||
Regl(Refresh, "Refresh");
|
||||
Regl(att_tour, "Att1tour");
|
||||
//Regl(att_tour, "FlaAp1tr");
|
||||
EEPROM.write(0, Ncyl);
|
||||
EEPROM.write(1, D_Flash);
|
||||
EEPROM.write(2, Refresh);
|
||||
IniT();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// SETUP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void IniT() {
|
||||
Ncyl = EEPROM.read(0); // on charge les parmaètres stockés en mémoire
|
||||
Ncyl = EEPROM.read(0); // on charge les paramètres stockés en mémoire
|
||||
D_Flash = EEPROM.read(1);
|
||||
Refresh = EEPROM.read(2);
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(Etin), isrEtincelle, RISING);
|
||||
Timer1.attachInterrupt(isrFlash); //Timer entre Etincelle et Flash
|
||||
Timer1.attachInterrupt(isrFlash); // Timer entre Etincelle et Flash
|
||||
Timer1.stop();
|
||||
modconfig=0;
|
||||
|
||||
//Affichage titre
|
||||
lcd.clear();
|
||||
|
@ -153,11 +171,11 @@ void IniT() {
|
|||
|
||||
//Affichage version
|
||||
lcd.clear();
|
||||
lcd.print("Version"); lcd.setCursor(0, 1); lcd.print(Ver); //N° de version
|
||||
lcd.print("Version"); lcd.setCursor(0, 1); lcd.print(Ver); // N° de version
|
||||
|
||||
delay(1000);
|
||||
if (digitalRead(Inter) == 0) {modconfig++;} //si bouton toujours appuyé
|
||||
if (modconfig >= 2){ // on entre dans le mode config
|
||||
if (digitalRead(Inter) == 0) {modconfig++;} // si bouton toujours appuyé
|
||||
if (modconfig >= 2){ // on entre dans le mode config
|
||||
modconfig=0;
|
||||
ConfiG();
|
||||
}
|
||||
|
@ -168,31 +186,35 @@ void IniT() {
|
|||
degT = 720 / Ncyl;
|
||||
Nc = 120000000 / Ncyl;
|
||||
T = 150000;
|
||||
D_deg = float(T * deg_dem) / float(degT); //Pour le premier cycle
|
||||
D_deg = float(T * deg_dem) / float(degT); // Pour le premier cycle
|
||||
|
||||
Affic_N_et_deg_dem();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); //Pour debug
|
||||
lcd.begin(8, 2);
|
||||
pinMode(Etin, INPUT); // Entrée bobine
|
||||
pinMode(Flash, OUTPUT); // Sortie FLASH
|
||||
if (debug) {Serial.begin(9600);} // Pour debug
|
||||
pinMode(Etin, INPUT); // Entrée bobine
|
||||
pinMode(Flash, OUTPUT); // Sortie FLASH
|
||||
pinMode(Codeur_A, INPUT_PULLUP);
|
||||
pinMode(Codeur_B, INPUT_PULLUP);
|
||||
pinMode(Inter, INPUT_PULLUP); // Le codeur met son inter à la masse quand poussé
|
||||
IniT();
|
||||
}
|
||||
pinMode(Inter, INPUT_PULLUP); // Le codeur met son inter à la masse quand poussé
|
||||
lcd.begin(8, 2);
|
||||
IniT();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// LOOP
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void loop(){
|
||||
if (millis() - pm > Refresh) { // Mise à jour affichage LCD
|
||||
Affic_N_et_deg_dem();
|
||||
if (millis() - pm > Refresh) { // Mise à jour affichage LCD
|
||||
Affic_N_et_deg_dem(); // Affichage tr/min et deg_demandés
|
||||
pm = millis();
|
||||
deg_dem = Enco.read()/4;
|
||||
deg_dem = Enco.read()/4; // On lit les degrés demandés via l'encodeur
|
||||
}
|
||||
|
||||
if (digitalRead(Inter) == 0) { //Si l'inter du codeur est poussé, geler l'affichage
|
||||
delay(1000); while (digitalRead(Inter) == 0); //Encore poussé, attendre
|
||||
delay(100); //Continuer
|
||||
if (digitalRead(Inter) == 0) { // Si l'inter du codeur est poussé, geler l'affichage
|
||||
delay(1000); while (digitalRead(Inter) == 0); // Encore poussé, attendre
|
||||
delay(100); // Continuer
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue