|
|||||||
![]() |
Forum Index > Projects > LED Pegboard and Matrix Projects | ||
ghosting |
|||
| | | Printable Version |
|
MarkWexler | ||||||||
|
Hello. There have been periodic discussions of ghosting (unwanted LEDs lighting up), but no really definitive recipe for getting rid of it. I have a serial version of Peggy 2, and I have serious ghosting issues with the following code: PHP Formatted Code #include <Peggy2Serial.h> union mix_t { unsigned long atemp; unsigned char c[4]; } mix; void SPI_TX(char cData) { SPDR = cData; while (!(SPSR & _BV(SPIF))) ; } Peggy2 displayArea; void setup() { displayArea.HardwareInit(); } void DrawOneDot(byte x, byte y, byte value) { byte pc, pd; byte j = y + 1; if (j < 16) { pd = j; pc = ((pd & 3) << 4) | (PORTC & 15); pd = pd & 252; } else { pd = (j - 15) << 4; pc = PORTC & 15; } if (value) mix.atemp = (uint32_t) 1 << x; else mix.atemp = 0; PORTC = PORTC & 15; PORTD = 0; SPI_TX(mix.c[3]); SPI_TX(mix.c[2]); SPI_TX(mix.c[1]); SPI_TX(mix.c[0]); PORTB |= 2U; PORTB &= 253U; PORTD = pd; PORTC = pc; } void loop() { DrawOneDot(0, 0, 1); //delay(1); // put delay to reduce (but not decrease shadow) DrawOneDot(24, 24, 1); //delay(1); }
|
![]() Apprentice Status: offline
Registered: 04/15/10 |
||||||||
|
|||||||||
|
Windell | ||||||||
|
Yes, the ghosting that you have in that example is very strong, and it is possible to do much, much better. I do understand that this is important, and you are not the only person using Peggy2 (and its variants) for visual testing. PHP Formatted Code #include <Peggy2Serial.h>union mix_t { unsigned long atemp; unsigned char c[4]; } mix; void SPI_TX(char cData) { SPDR = cData; while (!(SPSR & _BV(SPIF))) ; } Peggy2 displayArea; void setup() { displayArea.HardwareInit(); } void DrawOneDot(byte x, byte y, byte value) { byte pc, pd; byte j = y + 1; // First, send command to blank all columns. SPI_TX(0); SPI_TX(0); SPI_TX(0); SPI_TX(0); PORTB |= 2U; PORTB &= 253U; if (j < 16) { pd = j; pc = ((pd & 3) << 4) | (PORTC & 15); pd = pd & 252; } else { pd = (j - 15) << 4; pc = PORTC & 15; } if (value) mix.atemp = (uint32_t) 1 << x; else mix.atemp = 0; // You can add a delay here to reduce ghosting AT THE COST OF OVERALL BRIGHTNESS // delayMicroseconds(1000); PORTC = PORTC & 15; PORTD = 0; SPI_TX(mix.c[3]); SPI_TX(mix.c[2]); SPI_TX(mix.c[1]); SPI_TX(mix.c[0]); PORTD = pd; PORTC = pc; PORTB |= 2U; PORTB &= 253U; //asm("nop"); // short delay } void loop() { // The following variable sets the amount of time that each spot is lit. // There is a tradeoff: more time per spot is brighter and has less ghosting, // but it reduce the refresh rate. // // Sample values with two spots: // Value: 20 microseconds: Perfect flicker-free redraw, but with some ghosting // Value: 1000 microseconds: flicker-free unless you look quickly side-to-side, reduced ghosting // Value: 5000 microseconds: flickery when you look side-to-side, low ghosting unsigned int TimePerSpot = 5000; // Microseconds, up to 65535. DrawOneDot(0, 0, 1); delayMicroseconds(TimePerSpot); DrawOneDot(24, 24, 1); delayMicroseconds(TimePerSpot); }
Windell H. Oskay drwho(at)evilmadscientist.com http://www.evilmadscientist.com/ |
![]() Evil Scientist ![]() Status: offline
Registered: 06/15/06 |
||||||||
|
|||||||||
|
MarkWexler | ||||||||
|
Dear Windell, |
![]() Apprentice Status: offline
Registered: 04/15/10 |
||||||||
|
|||||||||
|
Windell | ||||||||
Unfortunately, this way of eliminating ghosting comes at a heavy price: after updating a row, you have to wait 5 milliseconds until you update another one, if you do not want the ghost of the first row to appear in the second.
Windell H. Oskay drwho(at)evilmadscientist.com http://www.evilmadscientist.com/ |
![]() Evil Scientist ![]() Status: offline
Registered: 06/15/06 |
||||||||
|
|||||||||
|
|
| All times are PDT. The time is now 04:48 PM. |
|
|
Octolively
Interactive LED kits
Meggy Jr RGB
LED matrix game
development kit.
Business-card sized
AVR target boards
Peggy 2
LED Pegboard kits