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