Pages: [1]   Go Down
Author Topic: Gator+ , Interrupt, pulseIn routines and millis  (Read 745 times)
0 Members and 1 Guest are viewing this topic.
Utah
Offline Offline
Newbie
*
Karma: 0
Posts: 24
High Priced Toy Specialist
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having this incredible problem reading a simple one output encoder wheel,
the cytron simple encoder. link here:
http://www.robotshop.com/cytron-simple-rotary-encoder-kit.html
I have it connected to PD:7 or pin 11 on the Gator+ board.
I have it connected as a switch or button which I was told would work correctly.
I have modified the blink program so that when the encoder showed a high signal (button pressed) the LED would turn on.
With this test i spun the shaft by hand and the led followed the encoder, on when high off when low.
If I used the motor (25 RPM), it blinked rapidly, blur actually, but I could tell it was working.

Now, I set up the interrupt routine (see code section below) and tested in the real program. I get nada, zip, nothing on the encoder duration counts.

The rest of the program runs beautifully, I don't understand what I am doing wrong, have been searching all over this forum for info and have tried a bunch of things.

All I can think of is throw it out to the group, and take whatever flak I get.

Code:
//************Definitions here**********************************//

//define where your pins are
int automationOpenTrigger = 0;
int automationCloseTrigger = 1;
int serviceBypassTrigger = 2;
int encoder2Count = 3;
int openRollerRelay = 4;
// 5
// 6
int zipper2Status = 7;
int zipper1Status = 8;
// 9
int tiltErrorTrigger = 10;
int encoder1Count = 11;
int closeRollerRelay = 12;
int errorLED = 13;
int stopRollerRelay = 22;
int openDoorActuator = 23;
int closeDoorActuator = 24;
int errorRelaytoAutomation = 25;

//Timing Stuff

unsigned long errorClockStart = 0;
unsigned long errorClockEnd = 0;
unsigned long counterSteps = 0;
int e1duration = 0;
int e2duration = 0;

//Define Error variables for later

int Encoder1Count = 0;
int Encoder2Count = 0;

//Interrupt setup function
 ISR(PCINT3_vect)
{
  unsigned long errorFlags =0;
  errorFlags = PIND;

  // Take action based on what the various values of PIND are....
}

//************************Setup part of program here*************************
void setup() {

  Serial.begin(57600);  //start serial for dtat back during troubleshooting

//define pin modes below here
pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT); //encoder 2 interrupt pin
pinMode(openRollerRelay, OUTPUT);
pinMode(8, INPUT);
pinMode(7, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);//encoder 1 interrupt pin
pinMode(closeRollerRelay, OUTPUT);
pinMode(errorLED, OUTPUT);
pinMode(14, INPUT);
pinMode(15, INPUT);
pinMode(16, INPUT);
pinMode(17, INPUT);
pinMode(18, INPUT);
pinMode(stopRollerRelay, OUTPUT);
pinMode(openDoorActuator, OUTPUT);
pinMode(closeDoorActuator, OUTPUT);
pinMode(errorRelaytoAutomation, OUTPUT);
pinMode(26, INPUT);


// Setup Interrupt pins here
PCMSK3 = _BV(PCINT31)  // PD7 or pin11 Encoder 1
       | _BV(PCINT30);  // PD6 or pin3 Encoder 2
 PCIFR = _BV(PCIF3);     // Clear any pending pin change interrupts in group 3
 PCICR = _BV(PCIE3);     // Enable pin change interrupts in group 3 (pins 24 to 31)

  The section giving me fits is here**************************************

 //begin open roller routine here ******************************************GOOD  motor opening
   e1duration = 0;
   e2duration = 0;    
  
  
  unsigned long rollerClockStart = millis() + 5000;//5 seconds of run time
  unsigned long rollerClockCount = 0;
  while (rollerClockCount < rollerClockStart)
     {
    
    
      digitalWrite (closeRollerRelay,LOW); //make sure the relay dont conflict
      digitalWrite (openRollerRelay,HIGH); //start the roller down  
      
      
        
        //***************************Need to have monitoring loops happening here******************
         tiltErrorTrigger = digitalRead (10);
         if (tiltErrorTrigger == HIGH) {  //PD4 or Pin10 Tilt sensor
         tilterror();
         }
        zipper1Status = digitalRead (8);
         if (zipper1Status == LOW) { // PD3 or Pin8 Zipper1
         zipper1Error();
           }//end of if  
        
        //*************Encoder monitoring here **********************
        //encoderCount();
         e1duration = pulseIn (11,HIGH,200);
         delay(200);
       e2duration = pulseIn (3,HIGH,200);
         delay(200);
                
      
          
        rollerClockCount = millis();
       }//end of While
       encoderPrint();
     digitalWrite (openRollerRelay,LOW); //release the roller down relay
      
  
  
  } //end of if
  
  Serial.println("------Drop Screen Function Run-------------");
  encoderPrint();
} //end of function
    


I also have another question, after the millis routine is run, the serial port quits printing back to my computer (Mac, Snow Leopard) I have to close the monitor and reopen it. Nothing prints to screen after the open screen function is run, not even the status messages at the end of  the function.

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 633
Posts: 50217
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
 Serial.begin(57600);  //start serial for dtat back during troubleshooting

//define pin modes below here
pinMode(0, INPUT);
pinMode(1, INPUT);
You can not use pins 0 and 1 at the same time you are using them for serial input/output. If they are being used for serial purposes, you should not be setting pinMode for them.

I'd try connecting the output of the encoder to pin 2 or pin 3, and using the attachInterrupt function to define the handler to invoke when the interrupt occurs.
Logged

Utah
Offline Offline
Newbie
*
Karma: 0
Posts: 24
High Priced Toy Specialist
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great! That explains the serial data screw up.
Will the standard attach interrupt routines work with the Gator?
I used an example sent to me from RuggedCircuits.
Heres a link to their pin translation.
http://www.ruggedcircuits.com/html/arduino.html
Its towards the bottom.
I'll try the regular Arduino attach interrupt coding and move the 0-1 inputs now.
Thanks, I'll post back as soon as I try it.
Logged

Pages: [1]   Go Up
Jump to: