Maker Pro
Maker Pro

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

Muhammad Saad

Oct 16, 2014
8
Joined
Oct 16, 2014
Messages
8
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.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
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.
 

BobK

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

Bob
 

Muhammad Saad

Oct 16, 2014
8
Joined
Oct 16, 2014
Messages
8
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
 

Attachments

  • Coding of circuit.txt
    728 bytes · Views: 242

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
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.
 

Muhammad Saad

Oct 16, 2014
8
Joined
Oct 16, 2014
Messages
8
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
 

Attachments

  • Proteus diagram.png
    Proteus diagram.png
    36.5 KB · Views: 849
  • Assembly Language code.txt
    821 bytes · Views: 194

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
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.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
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.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
Great explanation Steve!

Thanks Kris. My explanation does confuse strobe by explaining it in both edge sensitive and level sensitive ways. It is actually level sensitive.

On the rising edge of strobe, the data is transferred from the shift register to the latch

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

So the output latches are transparent; they follow the shift register while STROBE is high?

That's a far better way of explaining it.

I was trying to understand how it works by looking at the ON Semi data sheet but it wasn't very clearly explained.

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

The 74HC595 might be a better choice than the CD4094 for 5V circuits.

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.
 

Muhammad Saad

Oct 16, 2014
8
Joined
Oct 16, 2014
Messages
8
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...
 

Attachments

  • Assembly Language code.txt
    1 KB · Views: 202

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
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.
 

Muhammad Saad

Oct 16, 2014
8
Joined
Oct 16, 2014
Messages
8
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
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Why did you repost your question?

Did you see my response in post #11?
 

Muhammad Saad

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

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Yes it can, but you can't modify it by accessing the PINx register. You need to use the PORTx register.
 

Muhammad Saad

Oct 16, 2014
8
Joined
Oct 16, 2014
Messages
8
KrisBlueNZ: I understand your point..... My problem is solved........ Thankyou so much for helping me........
Cheers
 

Muhammad Saad

Oct 16, 2014
8
Joined
Oct 16, 2014
Messages
8
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....
 

Attachments

  • circuit.png
    circuit.png
    49.8 KB · Views: 397
  • Code.txt
    3.9 KB · Views: 202
Top