CREU Project Blog


Multitouch LED Display PART IV (FIXED BIDIRECTIONAL PROBLEM~!!)
October 15, 2007, 6:44 am
Filed under: Uncategorized

After consulting with Johnny and debugging the bidirectional LED test circuit using an oscilloscope,  we figured out the problem.  Previously in the firmware code of the, we used the Arduino API to set the state of the pin (that is to set the digital pins to input/output state).  The problem occurs at the discharing stage.  When we set the digital pin to input mode using the pinMode function, the pull up resistor is also set.  This is definitely not a good sign, because setting the pull up resistor  prevents the LED from discharging.  What this means is that we cannot call the digital I/O functions in the Arduino API.   Since the Arduino API is actually built upon the AVR-GCC, a free C compiler for the Atmega series microcontroller, we simply have to manipulate the digital I/O using the functions provided in the AVR-GCC lib.  Here is a table on how to manipulate the digital I/O on the Atmega microcontroller.

Here is the modified code


int digi_fwd = 2;
int digi_rev = 3
unsigned int count;
void setup(){
Serial.begin(9600);
Serial.println("Arduino");
DDRD |= _BV(digi_fwd); //set port D pin 2 as output
DDRD |= _BV(digi_rev);
}
void loop(){

//Emitting
PORTD |= _BV(digi_fwd); //set digi_fwd high
PORTD &= ~_BV(digi_rev); //set digi_rev low

//Reverse Bias
PORTD |= _BV(digi_rev); //set digi_rev high
PORTD &= ~_BV(digi_fwd); //set digi_fwd low

//Discharge
DDRD &= ~_BV(digi_rev); //set digi_rev input
PORTD &= ~_BV(digi_rev); //Disable pull up

count = 0;
while(digitalRead(digi_rev)){
count++;
}

Serial.println(count, DEC);

DDRD |= _BV(digi_rev); //set digi_rev input
}

Advertisements

Leave a Comment so far
Leave a comment



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



%d bloggers like this: