LED Multiplexer acting weird
hi,
i need fresh pair of eyes on code. multiplexing 43-segment display , turning segments on , off randomly. achieve this, performing own pwm splitting each cycle 64 "frames" , copying previous 1 next each cycle new segments added frame 0 able "fade in" being copied frames 1, 2, 3, 4 , on cycles progress. when segment randomly selected again, use xor function flip segment off frame 0, , off state gets copied frames 1, 2, 3, 4 , on segment fades out.
the problem is, illuminating segments 1 column on activated segments. in other words, another segment illuminates 1 column on segments in on state. code not complicated must missing straightforward , i'm @ wit's end.
a few theories have are: (1) random number generator not "random" , generating same segments, albeit 1 column over. calling random numbers every cycle sheer sample size may revealing pseudorandom nature of generators. have tried generator (2's carry) arduino's built in function random() , phenomenon persists. (2) there rogue code somewhere copying columns next 1 over. said code simple , can't find anywhere happening.
i need fresh pair of eyes on code. multiplexing 43-segment display , turning segments on , off randomly. achieve this, performing own pwm splitting each cycle 64 "frames" , copying previous 1 next each cycle new segments added frame 0 able "fade in" being copied frames 1, 2, 3, 4 , on cycles progress. when segment randomly selected again, use xor function flip segment off frame 0, , off state gets copied frames 1, 2, 3, 4 , on segment fades out.
the problem is, illuminating segments 1 column on activated segments. in other words, another segment illuminates 1 column on segments in on state. code not complicated must missing straightforward , i'm @ wit's end.
a few theories have are: (1) random number generator not "random" , generating same segments, albeit 1 column over. calling random numbers every cycle sheer sample size may revealing pseudorandom nature of generators. have tried generator (2's carry) arduino's built in function random() , phenomenon persists. (2) there rogue code somewhere copying columns next 1 over. said code simple , can't find anywhere happening.
code: [select]
const int columnpins[] = {3, a0, a1, a2, a3, a4, a5};
const int rowpins[] = {13, 5, 6, 9, 10, 11, 12};
byte colsegd[7];
int randgen;
byte colsegf[7];
byte fadeupd[64][7];
byte fadeupc[64][7];
byte fadeupb[64][7];
byte newpatternd[7];
byte newpatternc[7];
byte newpatternb[7];
unsigned long m_w = 1;
unsigned long m_z = 2;
unsigned long getrandom()
{
m_z = 36969l * (m_z & 65535l) + (m_z >> 16);
m_w = 18000l * (m_w & 65535l) + (m_w >> 16);
return (m_z << 16) + m_w; /* 32-bit result */
}
void setup() {
m_w = analogread(a8);
m_z = analogread(a8);
//serial.begin(9600);
// while (! serial);
pinmode(a8, input); //set random seed pin input
randomseed(analogread(a8));
for (int = 0; < 7; i++) //set pins outputs
{
pinmode(rowpins[i], output);
pinmode(columnpins[i], output);
}
colsegd[0] = b00000001;
colsegf[1] = b10000000;
colsegf[2] = b01000000;
colsegf[3] = b00100000;
colsegf[4] = b00010000;
colsegf[5] = b00000010;
colsegf[6] = b00000001;
//set initial pattern
for (int colcount = 0; colcount < 7; colcount++)
{
for (int rowcount = 0; rowcount < 7; rowcount++)
{
if (getrandom() % 10 == 1) //futz mod value change periodicity of segments being toggled
{
if (rowcount == 0) { //if segment activated, program direct port map segment array
fadeupc[0][colcount] |= b10000000;
}
if (rowcount == 1) {
fadeupc[0][colcount] |= b01000000;
}
if (rowcount == 2) {
fadeupd[0][colcount] |= b10000000;
}
if (rowcount == 3) {
fadeupb[0][colcount] |= b00100000;
}
if (rowcount == 4) {
fadeupb[0][colcount] |= b01000000;
}
if (rowcount == 5) {
fadeupb[0][colcount] |= b10000000;
}
if (rowcount == 6) {
fadeupd[0][colcount] |= b01000000;
}
}
}
}
}
void loop() {
for (int masterloop = 1; masterloop < 32000; masterloop++) {
for (int level = 0; level < 64; level++) //at each power level, segment activated/deactivated.
{
for (int col = 0; col < 7; col++)
{
//main multiplexing port mapping--turn segments on , off per column
portf = colsegf[col];
portd = (fadeupd[level][col] | colsegd[col]);
portb = fadeupb[level][col];
portc = fadeupc[level][col];
}
}
//turn off segments during new segment generation , frame copying
portf = 0;
portd = 0;
portb = 0;
portc = 0;
//shift levels , generate new pattern
for (int = 63; > 0; i--) //shift segments next-longest illuminated slot
{
for (int x = 0; x < 7; x++)
{
fadeupb[i][x] = fadeupb[i-1][x];
fadeupc[i][x] = fadeupc[i-1][x];
fadeupd[i][x] = fadeupd[i-1][x];
//delay(10);
}
}
for (int x = 0; x < 7; x++) //reset new pattern arrays
{
newpatternb[x] = 0;
newpatternc[x] = 0;
newpatternd[x] = 0;
}
//generate new pattern frame 0
for (int colcount = 0; colcount < 7; colcount++)
{
for (int rowcount = 0; rowcount < 7; rowcount++)
{
if (getrandom() % 800 == 0)
{
if (rowcount == 0) { //if segment activated, program direct port map fade matrix
newpatternc[colcount] |= b10000000;
}
if (rowcount == 1) {
newpatternc[colcount] |= b01000000;
}
if (rowcount == 2) {
newpatternd[colcount] |= b10000000;
}
if (rowcount == 3) {
newpatternb[colcount] |= b00100000;
}
if (rowcount == 4) {
newpatternb[colcount] |= b01000000;
}
if (rowcount == 5) {
newpatternb[colcount] |= b10000000;
}
if (rowcount == 6) {
newpatternd[colcount] |= b01000000;
}
}
}
}
//toggle segments
(int col =0; col < 7; col++) {
fadeupb[0][col] ^= newpatternb[col];
fadeupc[0][col] ^= newpatternc[col];
fadeupd[0][col] ^= newpatternd[col];
}
}
}
edit: think i've narrowed down bit of code copies levels
but don't understand?! code doesn't change column x?
code: [select]
for (int = 63; > 0; i--) //shift segments next-longest illuminated slot
{
for (int x = 0; x < 7; x++)
{
fadeupb[i][x] = fadeupb[i-1][x];
fadeupc[i][x] = fadeupc[i-1][x];
fadeupd[i][x] = fadeupd[i-1][x];
//delay(10);
}
}
but don't understand?! code doesn't change column x?
Arduino Forum > Using Arduino > Project Guidance > LED Multiplexer acting weird
arduino
Comments
Post a Comment