Connect with us

Problem faced in generating more i/o's through AVR

Discussion in 'Microcontrollers, Programming and IoT' started by Muhammad Saad, Oct 16, 2014.

Scroll to continue with content
  1. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    Hi Friends,
    How can i generate more i/o's by using Atmega16 or Atmega32.... I tried different things but they doesn't work. I shall be very glad if anyone could help me in solving this problem.
    Thanks.
     
  2. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Hi Muhammad and welcome to Electronics Point :)

    The usual way to expand digital I/O on a microcontroller is with shift registers. If your device has an SPI peripheral, this is relatively easy. Outputs can be expanded using 74HC595s or 74LVC595s and inputs can be expanded using 74HC165s or 74LVC165s. Google those part numbers along with "I/O expansion" and download their data sheets for more information.
     
  3. BobK

    BobK

    7,682
    1,686
    Jan 5, 2010
    Actually, the easiest way is to get an AVR with more pins, up to a point.

    Bob
     
  4. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    Hi Friends,
    Basically I want to expand i/o ports by using atmega16 or atmega32 using I2C Protocol in AVR. So, I select the shift register which supports I2C Protocol. Therefore I choose PCF8574 (SHIFT REGISTER). I want to control 39 outputs by using this IC, and the output of shift register IC will be connected with leds.
    Now problem is that I write a code and I wanted to turn on and turn off leds according to my will. But the problem is that what sort of address and data I send to the port SLA and SDA. It turn on all the leds..... not the one that I desired to open.
    I am attaching proteus file and code on Assembly Language. This circuit is not complete. Since I will attach more Shift registers with it to get 39outputs.
    Please help me out.
    Thank you.......
    Cheers..... Proteus File.png
     

    Attached Files:

  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    The PCF8574 is a great chip, and provides more functionality than shift registers. But you can't cascade them. And it's also NOT a shift register. You will need to address each one individually.
     
  6. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    Hi Friends,
    I changed my approach and now i'm using CD4094 to expand my I/O's. It's a shift register IC. Problem is that when i send data to the data pin it doesn't switch on those leds that i want.....
    As per CD4094 i made strobe pin low before start sending data and then send data with the clock.
    I'm attaching the Proteus diagram and Assembly language code.
    Please help me out
    Thanks
     

    Attached Files:

  7. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    Start with the strobe and output enable set to 1.

    Then as you clock the chip, the value on the data pin (during the rising edge of the clock will be shifted through the outputs. You can check that by doing it slowly and having LEDs attached to the outputs.

    Once you have that working, you can use the strobe input to cause all of the outputs to be set at once. This means that while it is 0, the data will still clock in as before, but you won't see it on the outputs. On the rising edge of strobe, the data is transferred from the shift register to the latch.

    If required you can also use the output enable to effectively disconnect the outputs. I think it's unlikely you'll need to use this.

    Note that there's no way to clear the chip. You need to clock 0's through the whole string of chips and strobe that to the outputs to achieve that. This is a relatively long and complex operation, but it's also essentially the same as setting any arbitrary output so you'll need a routine to do this in your code anyway.
     
    Muhammad Saad and KrisBlueNZ like this.
  8. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Great explanation Steve! I was trying to understand how it works by looking at the ON Semi data sheet but it wasn't very clearly explained.

    So the output latches are transparent; they follow the shift register while STROBE is high? That's interesting. It's a shame there's no reset function.

    Muhammad: The 74HC595 might be a better choice than the CD4094 for 5V circuits. It's more widely used (from what I've seen, anyway), and is a lot faster at 5V. It may have a longer future availability too. The output latches are clocked, not transparent, which wouldn't make any difference in normal applications; it has tri-state outputs like the 4094; it's 16 pins, same as the 4094; and it has a reset input.
     
  9. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    Thanks Kris. My explanation does confuse strobe by explaining it in both edge sensitive and level sensitive ways. It is actually level sensitive.

    This should be "when strobe is high, the latch follows the state of the shift register"

    That's a far better way of explaining it.

    It was confusing for me for a while too. Eventually I went with the truth table. :)

    It's certainly more popular. The advantage of that is you should be able to Google for examples of people using it with your microcontroller. A brief search shows bazillions of C++ examples. Presumably you can simply translate those to assembler. Having said that, there's also examples for the 4094 too.
     
    KrisBlueNZ likes this.
  10. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    Hi Friends,
    I made the strobe pin high before sending the data. After that the leds i want to open, they didn't hold. I am using Proteus to simulate it. As i start the simulation, the leds start on one by one, but that led which i want to hold it, that couldn't hold and it goes off....
    I am attaching Assembly language code. Proteus diagram is same as previous....
    Please help me out.
    Thanks
    Cheers...
     

    Attached Files:

  11. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    It looks like you're trying to control the I/O port pins by modifying the PINC register. This is a read-only register that yields the states of the port pins. Writing to it has no effect. You should be manipulating PORTC instead.
     
  12. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    I am trying to extend my i/o's by connecting the 3 pins of strobe, data and clock with any i/o pins of controller but not getting my desired results.....
    Please help me out
    Thanks
     
  13. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Why did you repost your question?

    Did you see my response in post #11?
     
  14. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    KrisBlueNZ: Port c is an i/o port. soi guess it can be use for both read and write???
     
  15. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Yes it can, but you can't modify it by accessing the PINx register. You need to use the PORTx register.
     
  16. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    KrisBlueNZ: I understand your point..... My problem is solved........ Thankyou so much for helping me........
    Cheers
     
  17. Asad Jawed

    Asad Jawed

    1
    1
    Oct 28, 2014
    thank you kris for helping muhammad saad and me
     
    KrisBlueNZ likes this.
  18. Muhammad Saad

    Muhammad Saad

    8
    0
    Oct 16, 2014
    Hi Everyone,
    I managed to glow 40 leds for my required work.
    Now i want to control the leds with the help of 7 switches. What i want is whenever i press a switch then multiple leds will glow. I am facing problem in my coding. I managed to do it by using one switch but whenever i press another switch same combination of leds glow.. not different leds glow..
    I am attaching my code and simulation....
     

    Attached Files:

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-