Skip to content

Commit

Permalink
Update encodersAB
Browse files Browse the repository at this point in the history
git-svn-id: http://arbotix.googlecode.com/svn/trunk@621 0ddeed48-8230-11de-bf8c-fd130f914ac9
  • Loading branch information
MFergs7 authored and MFergs7 committed Feb 12, 2012
1 parent fa7f741 commit 8c1412e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
55 changes: 25 additions & 30 deletions arbotix/libraries/EncodersAB/EncodersAB.cpp
@@ -1,6 +1,6 @@
/*
EncodersAB.cpp - Hardware Encoder Library for Robocontrollers
Copyright (c) 2009-2011 Michael E. Ferguson. All right reserved.
Copyright (c) 2009-2012 Michael E. Ferguson. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -18,13 +18,34 @@
*/

#include <avr/interrupt.h>
#include <wiring.h>
#include <Arduino.h>
#include "EncodersAB.h"

EncodersAB::EncodersAB() : left(0), right(0) {};

EncodersAB Encoders = EncodersAB();

unsigned char lastx;
void EncodersAB::Begin(){
#if defined(__AVR_ATmega168__) // mini/arduino
attachInterrupt(0, leftCounter, RISING);
attachInterrupt(1, rightCounter, RISING);
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) // arbotix
#if defined(ARBOTIX2)
PCICR |= (1 << PCIE1) | (1 << PCIE2) ; // enable PC interrupt on port B/C
PCMSK1 |= (1<<6); // enable interrupt D6 (B6)
PCMSK2 |= (1<<4); // enable interrupt D20(C4)
#else
PCICR |= (1 << PCIE2); // enable PC interrupt on port C
PCMSK2 |= (1<<4) + (1<<6); // enable interrupt on D20(C4),D22(C6)
lastx = PINC;
#endif
#elif defined(__AVR_ATmega1280__) // arbotix+/mega
attachInterrupt(6, leftCounter, RISING);
attachInterrupt(7, rightCounter, RISING);
#endif
}

#if defined(__AVR_ATmega168__) // mini/arduino
void leftCounter(){
// d2 & d8
Expand Down Expand Up @@ -84,46 +105,20 @@ ISR(PCINT2_vect){
#endif

#elif defined(__AVR_ATmega1280__) // arbotix+/mega
ISR(INT6_vect){
//void leftCounter(){
// PE6 (int 6) & PC2 (D35)
void leftCounter(){
if(PINC&0x04)
Encoders.left++; // cw is PE6 == d35
else
Encoders.left--;
}
ISR(INT7_vect){
//void rightCounter(){
// PE7 (int 7) & PC1 (D36)
void rightCounter(){
if(PINC&0x02)
Encoders.right++; // cw is PE7 == d36
else
Encoders.right--;
}
#endif

void EncodersAB::Begin(){
#if defined(__AVR_ATmega168__) // mini/arduino
attachInterrupt(0, leftCounter, RISING);
attachInterrupt(1, rightCounter, RISING);
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) // arbotix/sanguino
#if defined(ARBOTIX2)
PCICR |= (1 << PCIE1) | (1 << PCIE2) ; // enable PC interrupt on port B/C
PCMSK1 |= (1<<6); // enable interrupt D6 (B6)
PCMSK2 |= (1<<4); // enable interrupt D20(C4)
#else
PCICR |= (1 << PCIE2); // enable PC interrupt on port C
PCMSK2 |= (1<<4) + (1<<6); // enable interrupt on D20(C4),D22(C6)
lastx = PINC;
#endif
#elif defined(__AVR_ATmega1280__) // arbotix+/mega
//attachInterrupt(6, leftCounter, RISING);
//attachInterrupt(7, rightCounter, RISING);
EICRB |= 0xf0; // rising edge both 6 and 7
EIMSK |= 0xC0; // enable 6 and 7
#endif
}

void EncodersAB::Reset(){
left = 0;
right = 0;
Expand Down
4 changes: 1 addition & 3 deletions arbotix/libraries/EncodersAB/EncodersAB.h
@@ -1,6 +1,6 @@
/*
EncodersAB.h - Hardware Encoder Library for Robocontrollers
Copyright (c) 2009-2011 Michael E. Ferguson. All right reserved.
Copyright (c) 2009-2012 Michael E. Ferguson. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -20,8 +20,6 @@
#ifndef Encoders_h
#define Encoders_h

//#define ARBOTIX2

class EncodersAB
{
public:
Expand Down

0 comments on commit 8c1412e

Please sign in to comment.