summaryrefslogtreecommitdiffhomepage
path: root/analog
diff options
context:
space:
mode:
authorGuillaume Chevillot2008-03-02 22:46:46 +0100
committerGuillaume Chevillot2008-03-02 22:46:46 +0100
commit2104cfdea2b4e3cb719d454f73e90f9b7be7fafb (patch)
treef827c8c52955a387c4106bd10c0ac561754a9a05 /analog
parentb8e14afe490abb4816e3d3f09b0bbdaa53963c19 (diff)
- Fixed and improved outputs initializations
- Use LEDs to show command status
Diffstat (limited to 'analog')
-rw-r--r--analog/motor-power-avr/src/main.c8
-rw-r--r--analog/motor-power-avr/src/mp_pwm_LR_.h30
-rw-r--r--analog/motor-power-avr/src/mp_pwm_L_.c33
3 files changed, 66 insertions, 5 deletions
diff --git a/analog/motor-power-avr/src/main.c b/analog/motor-power-avr/src/main.c
index a18c0add..a691c6e4 100644
--- a/analog/motor-power-avr/src/main.c
+++ b/analog/motor-power-avr/src/main.c
@@ -82,14 +82,14 @@ int
main (int argc, char **argv)
{
avr_init (argc, argv);
- DDRD = 0x60;
/* Pull-ups. */
- PORTA = 0xff;
- PORTC = 0xff;
+ //PORTA = 0xff;
+
init_timer_LR_ ();
init_curLim ();
- //uart0_init ();
+ uart0_init ();
//postrack_init ();
+
envTest_period = 200;
proto_send0 ('z');
sei ();
diff --git a/analog/motor-power-avr/src/mp_pwm_LR_.h b/analog/motor-power-avr/src/mp_pwm_LR_.h
index 2fe44d65..999ecd67 100644
--- a/analog/motor-power-avr/src/mp_pwm_LR_.h
+++ b/analog/motor-power-avr/src/mp_pwm_LR_.h
@@ -48,7 +48,6 @@
#define _L_BL_1 PORTC |= 0x20
#define _L_BL_0 PORTC &= ~0x20
-
// _R_AH : PORTD6
#define _R_AH_1 PORTD |= 0x40
#define _R_AH_0 PORTD &= ~0x40
@@ -62,6 +61,35 @@
#define _R_BL_1 PORTC |= 0x08
#define _R_BL_0 PORTC &= ~0x08
+// _L_LED0 : PORTB0
+#define _L_LED0_1 PORTB |= 0x01
+#define _L_LED0_0 PORTB &= ~0x01
+
+// _L_LED1 : PORTB1
+#define _L_LED1_1 PORTB |= 0x02
+#define _L_LED1_0 PORTB &= ~0x02
+
+// _R_LED0 : PORTB3
+#define _R_LED0_1 PORTB |= 0x04
+#define _R_LED0_0 PORTB &= ~0x04
+
+// _R_LED1 : PORTB4
+#define _R_LED1_1 PORTB |= 0x08
+#define _R_LED1_0 PORTB &= ~0x08
+
+#define _L_ACTIVATE_OUTPUTS \
+ { \
+ DDRC |= 0xf0; /* PWM outputs */ \
+ DDRB |= 0x03; /* LED outputs */ \
+ }
+
+#define _R_ACTIVATE_OUTPUTS \
+ { \
+ DDRC |= 0x0c; /* PWM outputs */ \
+ DDRD |= 0xc0; \
+ DDRB |= 0x0c; /* LED outputs */ \
+ }
+
// Timer for _L_ and _R_ control
#define TCNT_L_ TCNT0
#define TCNT_R_ TCNT2
diff --git a/analog/motor-power-avr/src/mp_pwm_L_.c b/analog/motor-power-avr/src/mp_pwm_L_.c
index 67d28615..1eb04b71 100644
--- a/analog/motor-power-avr/src/mp_pwm_L_.c
+++ b/analog/motor-power-avr/src/mp_pwm_L_.c
@@ -19,6 +19,19 @@ static uint8_t pwm_L_;
void init_pwm_L_ (void) {
state_L_cmd = CMD_STATE_HIGH_Z;
pwm_L_ = 0x00;
+
+ // Set outputs to 0 (ie HIGH_Z)
+ _L_AL_0;
+ _L_AH_0;
+ _L_BL_0;
+ _L_BH_0;
+
+ // status LEDs
+ _L_LED0_1;
+ _L_LED1_1;
+
+ // Set IOs as outputs
+ _L_ACTIVATE_OUTPUTS;
}
// PWM rising edge on timer overflow IT
@@ -41,6 +54,11 @@ ISR(L_OVF_vect) {
_L_AL_0;
_L_AH_1;
sei(); // set back interrupts
+
+ // Display CMD_STATE on LEDs
+ _L_LED0_0;
+ _L_LED1_0;
+
break;
case CMD_STATE_DIR_1:
@@ -51,6 +69,11 @@ ISR(L_OVF_vect) {
_L_BL_0;
_L_BH_1;
sei(); // set back interrupts
+
+ // Display CMD_STATE on LEDs
+ _L_LED0_1;
+ _L_LED1_0;
+
break;
case CMD_STATE_BRAKE:
@@ -61,6 +84,11 @@ ISR(L_OVF_vect) {
_L_BH_0;
_L_BL_1;
sei(); // set back interrupts
+
+ // Display CMD_STATE on LEDs
+ _L_LED0_0;
+ _L_LED1_1;
+
break;
case CMD_STATE_HIGH_Z:
@@ -72,6 +100,11 @@ ISR(L_OVF_vect) {
_L_BL_0;
_L_BH_0;
sei(); // set back interrupts
+
+ // Display CMD_STATE on LEDs
+ _L_LED0_1;
+ _L_LED1_1;
+
break;
}