Author Topic: Multiplexing trouble (7 Segment LED)  (Read 1056 times)

0 Members and 1 Guest are viewing this topic.

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Multiplexing trouble (7 Segment LED)
« on: June 21, 2011, 05:51:41 PM »
If you've been frequenting the electronics forum you've probably seen my other thread.  Since this is a software issue, I've posted this new question here.

So I'm simply testing things, trying to get them to work.  I know my programming technique sucks right now... but it SHOULD work.

Here's my code.  What I am trying to do is have my 2 digit seven segment display count up from 0 to 99.

I have all of the segments connected to the D pins, so they are controlled strictly by PORTD.  

The two transistors for switching between the first and second digit are connected through B6 and B7.  Hence why I switch between 0x80 and 0x40 on PORTB.  

What happens is this...

It DOES count from 0 to 99, BUT...

The tens digit is VERY dim, and the ones digit seems to write OVER the tens digit.  Kinda like when the one's digit is supposed to be displayed, the tens transistor isn't completely off, and therefore both transistors are on, letting current flow to both digits.  

I don't THINK this is a software problem (why am I posting it here again?)... What I THINK is happening is that the transistors can't switch fast enough to keep up with what I'm doing.  I mean, I'm not delaying the switching at all, it's running at CLK speed.  So, since it's switching on and off so fast, it's almost acting like PWM, therefore providing the required voltage to keep the tens digit transistor on while the one's digit is supposed to be displayed.  

I just wanted to make sure my programming was ok.  

Code: [Select]
tens = i/10; //Calculate the tens place
ones = i - (tens*10); //Calculate the ones place
Timer_start(); //Start the timer (set the prescalar to 1024)
while(count<2) //Timer is too quick, making it run through twice
PORTB = 0x80; //Turn the tens digit's transistor on
display(tens); //Display the tens digit
PORTD = 0xFF; //Turn all digit segments off
PORTB = 0x40; //Turn the ones digit's transistor on (and tens transistor off)
display(ones); //Display the ones digit
if (TIFR & 0x01) //If timer has finished...
count++; //Increment count since timer is too fast
TIFR |= 0x01; //Reset timer
count = 0; //Reset count
PORTD = 0xFF; //Turn off all display segment LEDs
PORTB = 0x00; //Turn off both transistors
Timer_stop(); //Stop the timer

**Heads off to figure out how to delay the switching down to 500Hz or so...

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Multiplexing trouble (7 Segment LED)
« Reply #1 on: June 21, 2011, 06:16:08 PM »

I figured it out.  It was a programming error.  I forgot to turn off all of the display segments after I wrote the ones digit.  So basically when it went to display the tens digit again, the PORTD register already was written to display the ones digit, and the PORTD register was never cleared.

I basically just slowed the thing down a TON, so I could physically see it switching back and forth.

I saw the tens digit display good the first time, then it displayed the ones digit, then it displayed the messed up tens digit... so SOMETHING had to go wrong between the time I displayed it the first time, till I displayed it again.  That was it.
« Last Edit: June 21, 2011, 06:18:05 PM by corrado33 »

Offline Conscripted

  • Robot Overlord
  • ****
  • Posts: 291
  • Helpful? 10
Re: Multiplexing trouble (7 Segment LED)
« Reply #2 on: June 22, 2011, 11:18:54 AM »
Congrats. It's nice when a project comes together.



Get Your Ad Here