#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
- // Nano-644
+ // Nano-644 / Nano 1284
// ---------------------------------------------------------------
- // PD4 ..... Red
- // PD5 ..... Orange/Yellow
- // PD6 ..... Green
- // PD7 ..... Blue
+
+ // Nano-X-Base V1a V2a
+ // -----------------------
+ // Red PD4 PD7
+ // Orange/Yellow PD5 PD6
+ // Green PD6 PD5
+ // Blue PD7 PD4
void Led::init () {
PORTD &= ~((1 << PD7) | (1 << PD6) | (1 << PD5) | (1 << PD4));
// Arduino-Nano-5V
// ---------------------------------------------------------------
- // PD5 ..... Red
- // PB1 ..... Orange/Yellow
- // PD3 ..... Green
- // PD2 ..... Blue
+
+ // Nano-X-Base V1a V2a
+ // -----------------------
+ // Red PD5 PD2
+ // Orange/Yellow PB1 PD3
+ // Green PD3 PB1
+ // Blue PD2 PD5
void Led::init () {
PORTD &= ~((1 << PD5) | (1 << PD3) | (1 << PD2));
#define ADC0K 64
void Motor::init () {
+ DDRD |= (1 << PD7); // sensor signal toggle on PD7 (LED D4 red)
ADMUX = (1 << ADLAR) | (1 << REFS0); // ADC0, VREF=AVCC=3.3V
ADCSRA = (1 << ADEN) | 7; // ADC Enable, Prescaler 128
TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); // Fast PWM on OC0A
}
void Motor::cleanup () {
+ DDRD &= ~(1 << PD7);
ADMUX = 0;
ADCSRA = 0;
TCCR0A = 0;
bool Motor::isSensorHigh () {
return (PINB & (1 << PB0)) != 0;
}
+
+ void Motor::toggleD4 () {
+ PORTD ^= (1 << PD7);
+ }
+
#endif
#ifdef __AVR_ATmega328P__
#define ADC0K 91
void Motor::init () {
+ DDRD |= (1 << PD2); // sensor signal toggle on PD2 (LED D4 red)
ADMUX = (1 << ADLAR) | (1 << REFS0); // ADC0, VREF=AVCC=5V
ADCSRA = (1 << ADEN) | 7; // ADC Enable, Prescaler 128
TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); // Fast PWM on OC0A
}
void Motor::cleanup () {
+ DDRD &= ~(1 << PD2);
enabled = 0;
ADMUX = 0;
ADCSRA = 0;
return (PIND & (1 << PD4)) != 0;
}
+ void Motor::toggleD4 () {
+ PORTD ^= (1 << PD2);
+ }
+
#endif
int8_t Motor::run (uint8_t subtest) {
}
float rpm = 60.0 / (float)timer / 0.0001;
if (timer > 0) {
- printf_P(PSTR(" n= %4d U/min"), (int)rpm);
+ printf_P(PSTR(" n= %4d U/min (T=%04x)"), (int)rpm, timer);
} else {
- printf_P(PSTR(" no rotation "));
+ printf_P(PSTR(" no rotation (T=%04x) "), timer);
}
}
static bool lastSensorHigh = false;
bool sensorHigh = isSensorHigh();
- if (!sensorHigh && sensorHigh != lastSensorHigh && timerL > 10) {
+ if (!sensorHigh && sensorHigh != lastSensorHigh && timerL > 2) {
rpmTimer = timerL + timerH;
timerL = 0;
timerH = 0;
+ toggleD4();
}
if (sensorHigh) {
timerH = timerH < 0x4000 ? timerH + 1 : 0x4000;