added text to code and changed counts per revolution
This commit is contained in:
@@ -27,20 +27,22 @@ void Encoder::init()
|
||||
|
||||
led.set_lo();
|
||||
|
||||
previousC1 = c1.is_hi();
|
||||
count = 0;
|
||||
|
||||
activeEncoder = this;
|
||||
|
||||
// Enable pin-change interrupts for PORTB
|
||||
PCICR |= (1 << PCIE0);
|
||||
|
||||
// Enable interrupt specifically for PB0 / D8 / C1
|
||||
PCMSK0 |= (1 << PCINT0);
|
||||
|
||||
// Clear any pending PORTB pin-change interrupt
|
||||
PCIFR |= (1 << PCIF0);
|
||||
|
||||
// Enable pin-change interrupts for PORTB
|
||||
PCICR |= (1 << PCIE0);
|
||||
|
||||
// Enable interrupt specifically for PB3 / D8 / C1
|
||||
PCMSK0 |= (1 << PCINT0);
|
||||
|
||||
|
||||
//capture baseline
|
||||
previousC1 = c1.is_hi();
|
||||
count = 0;
|
||||
|
||||
// Enable global interrupts
|
||||
sei();
|
||||
|
||||
@@ -94,8 +96,8 @@ int Encoder::speed()
|
||||
uint32_t currentTime = micros(); //gives arduino microseconds since program started running
|
||||
|
||||
//from spec sheet we get 1400 counts per revolution from driver
|
||||
// or 700 from red beard??
|
||||
int rpm = ((currentCount-pastCount)*6e7)/((currentTime-pastTime)*1400); // we turn counts to rotations by dividing by 1400 and microsecond to minutes by multiplying with 60 and 10^6
|
||||
// or from assignment 1: 2100
|
||||
int rpm = ((currentCount-pastCount)*6e7)/((currentTime-pastTime)*2100); // we turn counts to rotations by dividing by 1400 and microsecond to minutes by multiplying with 60 and 10^6
|
||||
|
||||
pastTime = currentTime;
|
||||
pastCount = currentCount;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
int main()
|
||||
{
|
||||
init();
|
||||
|
||||
Encoder encoder(0, 1, 5);
|
||||
//C1pin, C2pin, led pin
|
||||
Encoder encoder(0, 1, 5); //d8 d9
|
||||
|
||||
encoder.init();
|
||||
|
||||
@@ -13,8 +13,8 @@ int main()
|
||||
|
||||
while (1)
|
||||
{
|
||||
Serial.println(encoder.position());
|
||||
//Serial.println(encoder.speed());
|
||||
//Serial.println(encoder.position());
|
||||
Serial.println(encoder.speed());
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user