Code for a 64 led pov globe

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

Hi everybody, I am new to this site and I hope I am not making any of the mistakes people usually make in there first post. I am making a 64 led pov globe because I think they are one of the coolest things ever. :) I am using a Atmega328p as the brains, and 8 8-bit shift registers to run the leds. Now I am not a very big programmer so my code is very basic. I was wondering if there was a more efficient way than I have to write the code, to flash the leds. My code is very long, and, it is just a simple one to toggle all the leds on and off to see if they work. To advanced coders it is probably so badly written it may hurt to look at so be warned. :)

#define F_CPU 16000000UL

#include 
#include 

int cycle(int data);
int latch(void);

int main(void)
{
   

    DDRB = 0b000111;
    PORTB = 0b000000;

    while(1)
    {
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
       
     
    latch();
   

    _delay_ms(500);

        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
        cycle(1);
        cycle(0);
       
     
    latch();

    _delay_ms(500);

        }
return 1;
}
       

int latch(void)
{
    PORTB |= (1 << PIN2);
    PORTB &= ~(1 << PIN2);

    return 1;
    }
int cycle(int data)
{


    if (data == 0)
    {
        PORTB &= ~(1 << PIN0);
        PORTB |= (1 << PIN1);
        PORTB &= ~(1 << PIN1);


    }

    else
    {
         PORTB |= (1 << PIN0);
         PORTB |= (1 << PIN1);
         PORTB &= ~(1 << PIN1);
    }
    return 1;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A schematic would help. Comments would help. Pins names that define the signals would help, pin1, pin2, pin0 doesn't mean too much to anyone trying to read your code. Names like ShiftIn, ClockIn, LatchIn would make much more sense.

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

Use a for loop to replace those long segments of code:

int i;

for (i=0;i<32;i++)
{
  cycle(1);
  cycle(0);
}

latch();
_delay_ms(500); 

for (i=0;i<32;i++)
{
  cycle(1);
  cycle(0);
}

latch();
_delay_ms(500); 

That replaces most of your main routine.

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

Ahhh shoot I knew I would make a mistake... Sorry about that. It didn't even occur to me to define things since I knew what they were. I will make the changes and re post the code. Sorry again. :)

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

It is a fun project. I did one putting the LEDs into a matrix, using a mega16 I think. It was actually my first ever embedded C project. It managed to source/sink the current fine without any extra components... Soldering was a pain though!

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

Quote:
yeah, using defines will make the code more portable.

True enough. And, as has been mentioned before, while you may know what they mean now, you may not in a year when you come back to the code. So it makes maintenance easier as well.

Martin Jay McKee

As with most things in engineering, the answer is an unabashed, "It depends."

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

Why do you return 1 to your functions? Im quite a beginner myself, but I think its better to just let the functions be of type "void":
void latch(){}
and you wont need to return anything.

..det har jag aldrig provat förut så det klarar jag säkert

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

In general the usual reason for an int return on a function (assuming it's not returning an obvious result like a+b) would be to return an error code to say whether the requested action worked or not. A lot of beginners seem to overlook this idea and also ignore the error code returned by a lot of libray functions such as lcd_init() or twi_init() or whatever - there's no point in a program trying to continue if you are being told that the device you intend to use did not even initialise.

In this case I don't really see the point of the OP's int returns. They are always uncoditionally one. Also when he calls cycle() or latch() he ignores any potential return value anyway.

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

Sorry It has been a couple of days. College has really bogged me down and I am still trying to get the hardware side of this build down. You guys make very valid points. :) I will probably not know what pin1 is in the future so I will go learn how to change those. And for the return 1 and the end of each function I thought that they were necessary. Opps well like I said I am just starting out in C and i love to learn so thanks to all of you for the help. :D

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

Ok first of all I am sorry to double post, but basically it seems that I cant full this pov globe off with all these shift registers. The circuit board with them on is just to big and for some reason I cant seem to get 8 shift registers to work together. I have a new idea though, and that is to (I dont know the word so I am guessing) multiplex the leds. Basically I was going to hook up all the leds in 8 rows with 8 leds in each row, with each row having a common ground. Then I would take 8 more wires and hook them up to 1 led on each row. Would this even be possible for the Atmega 328p to handle all that current? This is a diagram of what i wanted to do with the leds. The ( l ) stands for an led, and a ( - or | ) would be a wire.

||||||||
l-l-l-l-l-l-l-l-
||||||||
l-l-l-l-l-l-l-l-
||||||||
l-l-l-l-l-l-l-l-
||||||||
l-l-l-l-l-l-l-l-
||||||||
l-l-l-l-l-l-l-l-
||||||||
l-l-l-l-l-l-l-l-
||||||||
l-l-l-l-l-l-l-l-
||||||||
l-l-l-l-l-l-l-l-
||||||||

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

If I'm reading this right it'll work just fine. Each row has a common ground and each unique position in each row is driven by a common IO pin.

Watch out for capacitance in your hardware, it'll reduce the effectiveness of the illusion.

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

Ok it seems that for the life of me I cant get a single led to even turn on and I am getting super angry at myself. I cant discover what the heck I am doing wrong. I have 64 leds wired up into 8 banks of 8 leds each. Every bank of leds has all the negatives wired up to the 8 pins of PORTB. All of the positive sides of the leds are wired up to PORTD, so every first led in every bank is wired up to PIND0, and so forth. Now I just want to see an led turn on! so I wrote this code.

#include 

int main (void)
{
	DDRB = 0b11111111;
	DDRD = 0b11111111;

	while (1)
	{
		PORTB = 0b00000000;
		PORTD = 0b10101010;

		}

		return 1;
		}

Now with this I should see every other led in every bank of leds light up right? I mean I know the leds are hooked up right. I can turn them on and off with an external battery plugged into the proper leads of the microchip socket without the microchip in place, so I know that everything is soldered correctly. What am I doing wrong?

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

My bad I forgot to say that there is a 330 ohm resistor on each of the PORTB pins, basically a resistor on all the negative legs of the leds.

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

Quote:

I know the leds are hooked up right

Just to verify that, try

      PORTB = 0b10101010; 
      PORTD = 0b00000000;

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Yes I have tried switching the PORTS around to no luck. I wonder if my chip is even working anymore?

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

Ummm I dont know how to make a schematic but it is a Atmel m328p as the mcu. I am using a usbtiny and avrdude to program it. The code was posted above. I cant even get a single led to light up which is all I am trying to do right now.

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

Do you have all the VCC and GND pins connected?
What is the reset pin connected to?

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

I have both vvc and ground pins connected to 5 v and ground respectably. I have the reset hooked up to 5v through a 22k resistor. I dont think I need to hook up the AREF so i left that alone. Is that my problem?

Edit: Ok I had some time to take some measurements and it seems that I am not getting any voltage on any of the I/O pins. I can confirm that 5 volts is getting to the chip, because I can measure 5 volts on those pins. I tried this with 2 different Atmega 328p chips, One on the stock settings and one running at 16mhz. The code I used to test this was

#define F_CPU 1000000UL

#include 

int main (void)
{
	DDRB = 0b11111111;
	DDRD = 0b11111111;
	DDRC = 0b11111111;

	while (1)
	{
	PORTB = 0b11111111;
	PORTD = 0b11111111;
	PORTC = 0b11111111;
	}
return 1;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello,

i look for all of the atmega 64 leds globe pov .
can you send me by mail the project ?

thank in advance

henri,

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

Quote:
I can confirm that 5 volts is getting to the chip

To confirm your software is running place the chip on a bread board by itself. Confirm Voltages and current draw and then the voltages on each output pin. Confirm your hardware as well without the chip my manually applying 5V to each of the led's. You may be able to manually run the shift registers input pin as well to some degree at least to confirm data flows through it.

At some point using the above instructions you will find the problem.

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

Quote:

To confirm your software is running place the chip on a bread board by itself.

Just to note that this thread was hijacked and you just responded to a post in October 2010 ;-)

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

I suggest using a buffer chip like the 74hc244 to supply current to the LEDs instead of the AVR's PortD. Each LED is using 11 mA (5V - @1.4v LEDvoltage drop/330 ohms). When PortD is outputting logic hi to the anodes of half of the LED, it can not supply @360mA of current. Try outputting PortD=0x01; PortB=0xFE; to see if one LED is lighted. If yes, then try 'walking the zero' across PortB from bit 0 to bit 7 (with a 0.5 second delay at each step) to see if it is moving the lighted LED. Then 'walk the one' on PortD to see if it works with the next column.

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

Quote:

I suggest using a buffer chip

You're doing it too? This was a dead thread that's been resurrected by a hijacking necromancer - the original discussion ended last october?!?

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

Well... it's still raining outside, week after week after week.

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

hello,

can you send me by mail,
the schématics,pcb board, firmwares ..

thank you,

henri,