LED Matrix with HC595, 4017 and atmega8 not behaving as expected

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using the following circuit with the given code. When running at low speed (500 ms) all columns are displayed individually perfectly. But when trying to use POV to combine them together, the row disappears. Not sure if this the correct place to post this question, but any help would be appreciated.

#include <mega8.h>
#include <delay.h>
#include <stdint.h>
#define sclock PORTB.1    
#define slatch PORTB.2
#define sdata PORTB.0

uint8_t j,i=0,a[]={255,	255,	193,	247,	247,	193,	255,	255};
void dshift(uint8_t data)
{  uint8_t i=0;
   for(i=0;i<8;i++)
   {
      
      if(data & 0b10000000)
      {
         sdata=1;
      }
      else
      {
         
         sdata=0;
      }

      sclock=1;sclock=0;
      data=data<<1;  //Now bring next bit at MSB position

   }
   
   
   slatch=1;slatch=0;
   delay_us(5);
}
 
void main(void)
{
    

// Input/Output Ports initialization
// Port B initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRB=(1<<DDB7) | (1<<DDB6) | (1<<DDB5) | (1<<DDB4) | (1<<DDB3) | (1<<DDB2) | (1<<DDB1) | (1<<DDB0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

// Port C initialization
// Function: Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRC=(1<<DDC6) | (1<<DDC5) | (1<<DDC4) | (1<<DDC3) | (1<<DDC2) | (1<<DDC1) | (1<<DDC0);
// State: Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTC=(0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

// Port D initialization
// Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out 
DDRD=(1<<DDD7) | (1<<DDD6) | (1<<DDD5) | (1<<DDD4) | (1<<DDD3) | (1<<DDD2) | (1<<DDD1) | (1<<DDD0);
// State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 
PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);


while (1)
      {  
         dshift(a[0]);
         for(i=0,j=1;i<8;i++)
         {  
           
            delay_us(500);  
            dshift(a[(i+1)%8]);
            PORTB.3=1; 
            PORTB.3=0; 
         
         }
            

      }
}

This topic has a solution.
Last Edited: Sat. Feb 9, 2019 - 10:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your schematic shows Q8, Q9, and /CO of the 4017

all connected together, but those are all outputs.

Just connect Q8 to MR (reset) to create an eight

stage counter.

 

Aside from that I did not find a problem.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Duplicate post with this one...

 

https://www.avrfreaks.net/forum/...

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm getting very confused -- is like the paper with a question and "(over)" on the bottom; on the reverse it says "See other side".  The other thread is l9ocked for some reason.  That dealt with syntax errors, and some moved on to style suggestions.

 

Cliff, I'm not able to respond as the moderator cabal locked the thread.

1)  Like js, it gets harder and harder for me to have a bad hair day.

2)  I directly quoted what you said in the past, didn't I?  Isn't that quite different from your postings in that thread on the same topic?  Is there some reason that pointing out what was said in the past is antagonistic?

3)  Indeed, it is pretty much (the "dot syntax")  tongue-in-cheek.  Yet, by that year the "non-standard flag waving" had mellowed a bit.  Shall I dig out the lengthy thread the "prior art" of the dot syntax?

4)  I still want to hear about OP's version.  If indeed no Help and no inkling of Web presence, my first tho9ught is "cracked".

5)  How did OP get from syntax errors on a simple test program to partially-working full app in less than a day?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see two problems-
1. How do you know what state the 4017 is in? It might work on simulation, but not in real life.
2. Because you can’t directly control the columns (rows), you will get ghosting. You need to turn the column off, output new row data, then enable the next column.

The technique is called ‘multiplexing’. It relies on POV. Searching for the correct term might help with more examples.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Cliff, I'm not able to respond as the moderator cabal locked the thread.
Lee, I (Ross) didn't lock that thread but can unlock it if that would help.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. This is actually not a duplicate post. This is related to a problem with POV, while the other one had a problem with how to take input into atmega 8

2. I'm pretty sure you misunderstood the wire there: 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zackdgod wrote:

 

while (1)
      {  
         dshift(a[0]);                 //1st column data transferred, since counter is already at state 0
         for(i=0,j=1;i<8;i++)
         {  
           
            delay_us(500);             //displayed for some time
            dshift(a[(i+1)%8]);        //next column data
            PORTB.3=1;                 //clock pulse to move counter to switch on next column
            PORTB.3=0; 
         
         }
            

      }
}

 

I think I am using multiplexing here, via the 4017 itself. I was given a project to make this work on simulation, after which I can test it on real hardware from our electronics club.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The other thread is now unlocked by popular demand.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
1. How do you know what state the 4017 is in? It might work on simulation, but not in real life.
2. Because you can’t directly control the columns (rows), you will get ghosting. You need to turn the column off, output new row data, then enable the next column.

+1
.
zackdgod wrote:
When running at low speed (500 ms) all columns are displayed individually perfectly. But when trying to use POV to combine them together, the row disappears.

This is exactly what "ghosting problem" is.
İf you try on real hardware you will see the ghost!
İt is a pale copy of column apears at previous column.
Proteus does not simulate ghosting problem.
.
zackdgod wrote:
I think I am using multiplexing here, via the 4017 itself

As mentioned in #5 the key point is you need to turn off previous column before selecting next column.

.
1.turn off current data (send blank data)
2.select next column
3.send next column data
4.delay for POV

Majid

Last Edited: Sat. Feb 9, 2019 - 09:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey guys,

So I decided to use an RGB matrix instead of a red one and I need to do color mixing at different leds. So I've decided to get some common anode RGBs such that the cathode ground can be controlled to do the color mixing. 

I read up on pwm in CV AVR and realized i have to use OC01 and timer functions to control pwm. but what will i connect the pwm output to and how will i control it to make sure all the leds get the appropriate pwm at each pin? I know I have to control the duty cycle of the wave to make it pwm, but can't figure out how to get different duty cycles for different pins.

 

 

PS: the circuit will approximately be the same, with a 4017 at the anode, but 3 shift registers for each of the 3 pins. How will I pwm the shift register pins?

Any basic logic would be very helpful. 

 

PPS: I shouldn't need to go for values except 255 and 127

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ideally you would use a different chip since the mega8

only has two compare match registers on timer 1.  With

three, you could set the R, G, and B values in the OCRnA,

OCRnB, and OCRnC registers and use the timer overflow

interrupt to advance to the "next" LED.

 

The mega 328 does not have three OCR registers either

on any one timer.  The mega 128 and 2560 do, for example,

but these are much bigger chips.  Let us know if you are

"stuck" with the mega 8 for some reason.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using the electronics club's components, so i'm stuck with the mega 8. I can get them to buy any cheaper ICs though. So, if any substitute is possible, that would be helpful

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You can use binary code modulation - http://www.batsocks.co.uk/readme...

This technique has been used in the Arduino drivers for the 32x32 rgb led panels. This should allow you to get by with one timer. 

 

The 4017 has poor drive capability - you'd most likely be better using another 595. I just looked at the specs for a 4017 - lucky if you get much more than 1mA.

 

The beauty of using all 595's is that you can shift in the next frame of data whilst the current one is displaying. To update all you do is toggle the latch pin. Rinse and repeat.

 

To eliminate the ghosting you can connect the column drive 595 output enable pin to a port pin. Disable the columns, toggle the latch, re-enable the columns.

Last Edited: Mon. Feb 18, 2019 - 05:13 AM