Go Down

Topic: Mega 2560 PCI/Ext Int and LCD Flickering (Read 542 times) previous topic - next topic


I'm implementing an embedded system and writing code for a company to monitor the status of a product cycle test. The actual test machine is made, I'm just using the Arduino to run a state machine and publish real-time results on the local server. The majority of the code is written, but I'm having issues with the Pin Change Interrupts.

In instances where the arduino is powered by the 5VDC over USB from a laptop, the unit works fine and as expected, however using a 9V 1A barrel jack, the LCD flickers and doesn't actually show any of the text that is printed during the setup() method, rather it hangs indefinitely. I've confirmed it's a software problem, not a hardware problem, and my buddy thinks its something buried in the avr/interrupt.h file. Commenting out all of the PCI code allows it to work on both supplies. But what I don't understand is why it would work over usb, but not the barrel jack.

I'll post the relevant code, but it's also proprietary, so bear with me.

Any ideas or suggestions would be helpful!

Code: [Select]

#include <LiquidCrystal.h>
#include <EEPROM.h>
#include <Ethernet.h>
#include <SPI.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>

byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
EthernetClient client;
EthernetServer server(80);
LiquidCrystal lcd(9,8,7,6,5,4);
int mainLCDTimerRefresh = 0;

void setup() {
   //Enable External Interrupts 1 - 5 for power buttons
  EIMSK |= (1<<INT1);    //Sets External Interrupt Mask to one for INT1 (Enables)
  EICRA |= (1<<ISC10);   //Sets edge detection bit to change
  EIMSK |= (1<<INT2);
  EICRA |= (1<<ISC20);
  EIMSK |= (1<<INT3);
  EICRA |= (1<<ISC30);
  EIMSK |= (1<<INT4);
  EICRB |= (1<<ISC40);
  EIMSK |= (1<<INT5);
  EICRB |= (1<<ISC50);

  PCICR |= (1<<PCIE2);
  PCICR |= (1<<PCIE1);
  PCICR |= (1<<PCIE0);
  PCMSK2 |= (1<<PCINT23);
  PCMSK2 |= (1<<PCINT22);
  PCMSK2 |= (1<<PCINT21);
  PCMSK2 |= (1<<PCINT20);
  PCMSK2 |= (1<<PCINT19);
  PCMSK1 |= (1<<PCINT10);
  PCMSK1 |= (1<<PCINT9);
  PCMSK0 |= (1<<PCINT7);
  PCMSK0 |= (1<<PCINT6);
  PCMSK0 |= (1<<PCINT5);

  lcd.print("Beginning Program");
  for(int i = 0; i < 1024; i++){
    if(EEPROM.read(i) == 1){
      lcd.print("Reading in counts");
  if(EEPROM.read(0) == 0){
      bays[0] = StationBay();
      bays[1] = StationBay(15, 21, 15);
      bays[2] = StationBay(14, 20, 14);
      bays[3] = StationBay(13, 19, 13);
      bays[4] = StationBay(12, 18, 12);
      bays[5] = StationBay(11, 03, 11);
      lcd.print("Bays Initialized");
  lcd.print("Trying to connect");
  if(Ethernet.begin(mac) == 0){
    lcd.print("Failed to");
    lcd.setCursor(3, 1);
    lcd.print("configure DHCP");
    lcd.print("RESET REQUIRED");

Go Up