interfacing multiple shift registers with atmega128

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

Hello , I am using Atmega128 and 8 shift registers 6D595 the ser_out of each register is connected to the next shift register's ser_in so they form a chain. There is no issue with the hardware it has been tested. I am using 4 16 bit variables to send data to shift registers. the  problem that i am facing is that only once i am able to latch out the values only once .. For example if i send 4 variables as 0x0011,0xFF00,0x3c1d,0x1100 (they can be anything ) then i get the output on my 8 segment panel. but i am only able to update my registers only once . if i try to update them in a loop the program only shows the first value that i had sent to the shift register function

 

here is what i am doing in my shift out register

<code>

void shift_out(uint16_t data[4])

make latch pin HIGH

for(int x=0;x<3;x++)

{

      for(int i=0;i<16;i++) 

     { 

             set data pin according to data[x] 

            give a low pulse to clock pin then make it high

     }

}

give a low pulse to latch pin then make it high 

</code>

 

if i call this function once it works perfectly fine 

but if i call it again with different values nothing happens 

 

 

please help me i am not sure what else information i am supposed to share.. but i am willing to share anything.. Thanks in advance!! 

 

I found out that the program doesnt return from my function but keeps on performing this function even if it is not in a loop

 

void shift_out_data2(uint16_t data1,uint16_t data2,uint16_t data3,uint16_t data4)
{    
    
    
    
    for(int i=0;i<16;i++)
    {
        if(data1 & (1<<(i)))
        PORTC |= (1<<(3));   // data pin
        else
        PORTC &= 0b11110111; // data pin
        
        PORTC |= (1<<(4));   //clock pin        
        _delay_us(10);
        PORTC &= 0b11101111; // clock pin
        
    }
    
    for(int i=0;i<16;i++)    //same loop as above but for next data
    {
        if(data2 & (1<<(i)))
        PORTC |= (1<<(3));
        else
        PORTC &= 0b11110111;
        
        PORTC |= (1<<(4));
        _delay_us(10);
        PORTC &= 0b11101111;
        
    }
    for(int i=0;i<16;i++)
    {
        if(data3 & (1<<(i)))
        PORTC |= (1<<(3));
        else
        PORTC &= 0b11110111;
        
        PORTC |= (1<<(4));
        _delay_us(10);
        PORTC &= 0b11101111;
        
    }
    
    for(int i=0;i<16;i++)
    {
        if(data4 & (1<<(i)))
        PORTC |= (1<<(3));
        else
        PORTC &= 0b11110111;
        
        PORTC |= (1<<(4));
        _delay_us(10);
        PORTC &= 0b11101111;
    }
    PORTC |= 0b00000100;    // latch pin    
      PORTC &= 0b11111011;  //latch pin
    
}

 

 

 

This topic has a solution.
Last Edited: Tue. Apr 16, 2019 - 04:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

your clock logic looks inverted - data is clocked in on the rising edge. Are the other signals set up correctly?

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

Yes i have implemented the rising edge (low pulse and the making it HIGH again) 

 

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

My latch signal is High at the begining of function and at the end of function i turn it off for 10 us then make it HIGH again. 

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

yes you were right apparently my signals were invereted but still it doesnot solve the problem.... after few checks i found out that my code is not returning after from function shift_out.. i am editing the post to add the function please have a look.. Thanks

 

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

ATMega128s that don't return are (99.99% of the time) not ATMega128s, they are ATMgea103s

 

When you first take a mega128 out of the packet to be a compatible replacement with the old ATmega103 it behaves exactly like the 103. It has a fuse called M103C (Mega 103 Compatibility) that is "active" by default. The chip only starts to behave like a mega128 when you deactivate the M103C fuse.

 

Up to that point - because mega103 and mega128 have RAM in different places - then if you build and run code as if it were for mega128 but put it into a chip that is behaving like mega103 the stack pointer will be set to a non-existent RAM location so PUSH/POP and CALL/RET won't work. When you CALL a function it will enter the function but when it comes to RET it will not return to the right place. That is what you are almost certainly seeing.

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

Exactly this was my problem and the moment i changed the fuse bit my led panel sprang to life...
Thanks (Y)

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

We get at least one person a month caught by this one! Why are people still using mega128's?

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

Maybe, the "teachers" in some institutes are caught in a time warp.

 

Ross McKenzie ValuSoft Melbourne Australia

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

no its not assigned by a teacher .. i am working on a product.. but can i ask why not Atmega128 ??? i mean it offers alot of memory and I/Os what else one should look for when selecting a microcontroller.

 

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

I am also a student so i would love to know  whether i am using an extremely outdated chip or there are better alternatives of atmega128.. please shed some light on it .. Thanks :) 

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

ATmega128 dates from around the turn of the millennium. There have been a lot more 64 pin AVR since, many with improved features (and very likely for a lower price).

 

Exactly what features of the 128 is it that you need in your project.

 

Also, is your project 5V or 3.3V? If the latter then that also opens up a whole range of Xmega chips too you too - which may have other, more advanced features that may make your implementation easier/better.

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

My last AVR design using a mega128 was in 2006. The board is still in production. At my last look at the pricing, there are a number of newer chips that are faster/cheaper/more of everything.
I originally chose the mega103 as i didn’t know how much flash I would need, so I chose the largest part. Cost wasn’t an overriding concern as it was part of a large display board that cost many $1000’s.

Last Edited: Tue. Apr 16, 2019 - 12:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I dont understand, until now i used to think very highly of Atmega 128,I usually use atmega328p though

 

The reason why i gave an edge to atmega128 over atmega328p was because it had more I/Os and also because it had 2 Usart connections .. but now i am confused.. are you saying that even atmega328p is outdated ... either that or i am unable to establish an appropriate perspective for comparison between atmega chips 

 

Also My project is 5V, can you suggest any latest alternative for atmega128 ...specifically( if that is not too much details to ask for on this forum)

Last Edited: Wed. Apr 17, 2019 - 05:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can you suggest any latest alternative for atmega128

The Mega128 is an extremely OLD chip, the newer ones are ATmega1281/2561 (same pinout) or the 100 pins ATmega640/1280/2560

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

If you were simply looking for 2 UART and a few more IO than the 328P (dates around 2007 but still has a lot of good features) then the 644P and 1284P are good chips to look at. They are available in 40 pin DIP (easy to use on breadboard) and have 2 UART. Obviously being just 40 pin they don't have quite as many IO as 128 but do you really need that many IO for what you are doing?

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

I had a look at the 644P and it seems promising I can even connect a 20MHz crystal to it and the I/Os are just enough for me as well..... Thanks!!