summaryrefslogtreecommitdiff
path: root/n/es/src/tourelle.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/es/src/tourelle.c')
-rw-r--r--n/es/src/tourelle.c133
1 files changed, 80 insertions, 53 deletions
diff --git a/n/es/src/tourelle.c b/n/es/src/tourelle.c
index b186cef..54e69a0 100644
--- a/n/es/src/tourelle.c
+++ b/n/es/src/tourelle.c
@@ -1,4 +1,4 @@
-/*Tourelle.c*/
+/* tourelle.c*/
/* Detector on a ATmega128. {{{
* Copyright (C) 2005 Dalmais Romain
*
@@ -21,68 +21,99 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* }}} */
-#include "Tourelle.h"
+#include "tourelle.h"
+#include "avr/signal.h"
-const int8_t delayMax = 125;
-const int8_t delayMin = 175;
-const int8_t SEUIL = 180; // 10 cm = 2.25V et 80 cm = 1.75 V
-
-//capteur sharp sur PA0
+const uint8_t delayMax = 125;
+const uint8_t delayMin = 175;
+const uint8_t pin_sharp = 3 ;
+uint8_t delay = 0;
+const uint8_t SEUIL = 180; // 10 cm = 2.25V et 80 cm = 1.75 V
+const uint8_t MILIEU = 2;
+// const int8_t PROUT = 12; A VERIFIER !!
+//capteur sharp sur PA3
+//servo sur PB
/* etat mode:
* 0 = inactif
* 1 = continu */
-int8_t etat=0;
-int8_t tableau_longueur[25];
-tourelle_init(int8_t prescaler)
+uint16_t tableau_longueur[25];
+/*
+extern uint8_t continu;
+extern uint8_t etat;
+extern uint8_t envoie;
+extern uint8_t sens;
+*/
+uint8_t valeur_actuelle1 = 0;
+uint8_t valeur_actuelle2 = 0;
+uint8_t angle_actuel1 = 0;
+uint8_t angle_actuel2 = 0;
+uint8_t valeur_ancienne1 = 0;
+uint8_t valeur_ancienne2 = 0;
+uint8_t angle_ancien1 = 0;
+uint8_t angle_ancien2 = 0;
+uint8_t nombre_actuel = 0;
+uint8_t nombre_ancien = 0;
+
+void tourelle_init (uint16_t prescaler)
{
- continu = 0;
delay = 0;
+ DDRB = 0xFF;
SFIOR |= 0x01; // prescaler autorisé
- crenaux(delay); // on met le capteur à 0°
- wait_1ms(20);
+ crenaux(delay,PORTB,7); // on met le capteur à 0°
+// wait_1ms(20);
- crenaux(delay);
- wait_1ms(20);
+ crenaux(delay,PORTB,7);
+// wait_1ms(20);
- crenaux(delay);
+ crenaux(delay,PORTB,7);
switch(prescaler)
{
- case 81: registre_prescal |= 0x03;break;
+ case 8 :
+ {
+ TCCR1B |= 0x02;
+ TCCR1B &= 0xFA;
+
+
+ }break;
case 64 :
{
- registre_prescaler &= 0xFD;
- registre_prescaler |= 0x01;
+ TCCR1B &= 0xFB;
+ TCCR1B |= 0x03;
}break;
case 256 :
{
- registre_prescaler &= 0xFD;
- registre_prescaler |= 0x01;
+ TCCR1B &= 0xFC;
+ TCCR1B |= 0x04;
}break;
- case 1024: registre_prescal |= 0x03;break;
+ case 1024:
+ {
+ TCCR1B |= 0x05;
+ TCCR1B &= 0xFD;
+ }break;
}
}
-crenaux(int8_t temps, int8_t port, int8_t pin)
+void crenaux(uint8_t temps, uint8_t port, uint8_t pin)
{
port |= pin; // en admettant que je sois sur le portb et la troisième pin
- wait_10us(temp);
+// wait_10us(temp); // TROUVER LA FONCTION !!!!!!!!
port &= 0xFF - pin; // on remet l'impulsion à 0
}
-proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+void rs232_callback (uint8_t cmd, uint8_t size, uint8_t *args, uint8_t *etat,uint8_t *envoie)
{
#define c(cmd, size) (cmd << 8 | size)
switch (c (cmd, size))
@@ -92,27 +123,28 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
/* Commands. */
case c ('c', 0):{ // continu
- etat = 1;
- envoie = 1;
- if(c(0,1)) sendValeur(); /// mettre la bonne fonction
+ (*etat) = 1;
+ (*envoie) = 1;
+// if(c(0,1)) sendValeur(); /// METTRE LA BONNE FONCTION
}break;
case c ('u',0):{ // unique
- envoie = 0;
- sendValeur();
+ (*envoie) = 0;
+// sendValeur(); /// METTRE LA BONNE FONCTION
etat = 0;
}break;
case c ('s',0): { // stop
- etat = 0;
- envoie = 0;
+ (*etat) = 0;
+ (*envoie) = 0;
}break;
+ }
}
-TournerTourelle()
+void TournerTourelle(uint8_t sens)
{
- if(delay=delayMax||delay=delayMin)
+ if( delay==delayMax || delay==delayMin)
{
sens *= -1;
@@ -128,21 +160,19 @@ TournerTourelle()
}
delay += 2 * sens;
- crenaux(delay,portc,0x07);
+ crenaux(delay,PORTB,0x07);
}
-int8_t mesurer()
+int16_t mesurer(void)
{
-
-adc_init();
-adc_start();
-while(!adc_checkf)
-{wait_1us(1)}
-return adc_read();
+ adc_init();
+ adc_start(pin_sharp);
+ while(!adc_checkf()){}
+ return adc_read();
}
-void Timer_tourelle()
+SIGNAL (SIG_INTERRUPT1)
{
// on fait la mesure
uint8_t i = 0;
@@ -154,29 +184,26 @@ void Timer_tourelle()
}
tableau_longueur[0] = mesurer();
- if(temp == tableau_longueur[MILIEU+1])
+ if(temp == tableau_longueur[MILIEU+1] && temp > SEUIL )
{
- if(nombre_valeur == 0)
+ if(nombre_actuel == 0)
{
- valeur_actuelle1 = (PROUT - distance);
+ valeur_actuelle1 = tableau_longueur[MILIEU+1];
angle_actuel1 = 45 + (delay - 6)*90/50;
}
- if(nombre_valeur == 1)
+ if(nombre_actuel == 1)
{
- valeur_actuelle2 = (PROUT - distance);
+ valeur_actuelle2 = tableau_longueur[MILIEU +1];
angle_actuel2 = 45 + (delay - 6)*90/50;
}
- if(nombre_valeur > 1)
+ if(nombre_actuel > 1)
{
-// ALARME // PROBLEME
+// ALARME // PROBLEME // ALLUMER LED
}
}
-cycle();
}
-
-