Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

(Solved)Again problem with matrix, this time 8x32

Status
Not open for further replies.
You still have stamina for this? phew :eek:. I see at least dat value is changed? I'll test that tomorrow if not today! Btw, I made in test purpose 8-digit display from 7 segments, I'm planning to make some 7-segment display for that matrix so matrix scrolls some programmed quotes where as 7-segment shows time....also there is just enough space for VU-stereo meter hehe (or 32-point FFT would be better for matrix perhaps). Sorry, bit off-topic :D
 
yes cause you use 2 registers which total 16 bit, actually we need to fix fontmap, and other things to reflect this adjustment....32768 = ob1000 0000 0000 0000 (2 registers) 128 = 0b1000 0000 (1 register)
lol, ya, this is like reading an episode or readers digest for me! Drift all you want! its your thread!

about 5or6yrs ago i did my first robot, it was poor design using stepper motors a DTMF receiver(touch tone) and discrete logic using all and/or gates and bcd decoder. so i was able to hook it to cellphone earphones and send tone to it, so that number 2 made it go forward, 8 bkwrds, and 5 to stop...ect, thats around when i learned about pic microcontrollers, fixing a 1 to 0 is alot easier in code than hardware, since then i have done another, better proper robot(running on IRdata from my cable box remote), as well as several other small projects,

one of the half finished ones was a quad rotor, it was able to take off but thats about it, never got as far as i wanted to
currently im working on it still, and want to redesign but with bigger dreams, which i project will take another 5 yrs or so,, right now I am doing 3d graphics and the matrix i am dealing with is using x,y,z coordinates , plus all this crazy trigonometry that goes with it, specifically this week, i just finished being able to load a QBJ file, and now learning(tryin to) some lame calculations that orbit the viewer and mouse click selecting objects, Also i am in process of hacking game controller usb protocol, so i can control robot
... always C#
My problem is staying focused , i got so many half projects started, but i never want to finish, so ya i actually sometimes look forward to these little breaks too much!
 
Last edited:
Code:
int buffer1[4];  // buffer for screen,4x8=32
int backbuffer[4];  //Spare screen for drawing on, 4x8=32
int power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };


in pixel():
Code:
int pix, msk;

Code:
void charput(unsigned char ch, signed char x, signed char y)
{
  signed char x1, y1;
  int disp;
  int disp2; 
  disp = font[ (ch)]; //look data from fontmap,
  Serial.println(disp/256, BIN);
  Serial.println(disp & 0xFF, BIN);
  for (y1 = 0; y1 < 16; y1++) // eight pixels
  {
  disp2 = disp & power[y1];
  if (disp2 > 0)
  {
  pixel(x + x1, y + y1, 0); // OR the pixel to the display buffer
  } 

  }
}

and change fontmap like this

Code:
//MSB
static unsigned int font [125]  =  //numbers stored here
{ //Position, Character
  //  B (null) M L K J I H G2,  B G1 F E D C B A DOT
  B0001100001111110, // 0  0
  B0000000000001100, // 1  1
  B0000000110110110, // 2  2
  B0000000110011110, // 3  3
  B0000000111001100, // 4  4
  B0000000111011010, // 5  5
  B0000000111111010, // 6  6
  B0000000000001110, // 7  7
  B0000000111111110, // 8  8
  B0000000111011110, // 9  9
 
Seems compiler doesn't like 16-bit fontmap, tried with other sketch too :
C:
Arduino: 1.6.7 (Windows 7), TD: 1.27, Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

In file included from C:\Users\Atte\AppData\Local\Temp\arduino_2c95d8b8a178f3b50e0698535cbfb980\_14-segment-testing.ino:1:0:

FontMap14Segment.h:5: error: 'B0001100001111110' was not declared in this scope

  B0001100001111110, // 0  0
 
hmm, that is strange to me, not that iv ever done this before, my first guess is that i always use 0b as prefix,
what would happen if you tried hex or decimal value?

0b0001100001111110, // 0 0
6270, // 0 0
0x187E, // 0 0

no need to change them all rite away, till we kno it works , cause error wont be on line 5 anymore
 
ok, that fixed fontmap error, screeen shows flickery on all second registers segments if I want to show charput(5), but when I place that counter as testing, values 0-9 are seen as coutning goes on, but second register values are still on flickering.
C:
#include "FontMap14Segment.h"

int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;


unsigned char displayPointer = 0; // for interrupt use...
unsigned char buffer1[4]; //2x8 bits
unsigned char backbuffer[4]; // Spare screen for drawing on
//unsigned char power[8] = {1, 2, 4, 8,16,32,64,128}; //B00000001,B00000010,B00000100,B00001000 for digits
int power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };


ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
  if (TIFR2) // Make sure its the timer interrupt.
  {
  setcolumn(displayPointer);  //column scanning
  setdata(buffer1[displayPointer]);
  PORTD = (1 << PORTD3);
  PORTD = (0 << PORTD3);

  //digitalWrite(latchPin ,HIGH);
  //digitalWrite(latchPin , LOW ); // STORECLOCK

  if (++displayPointer == 4)  //4 because there are two digits, each need 2x8 bits
  { displayPointer = 0;
  } // 32 LED row sections in total
  }
  TIFR2 = 0; // Clear timer 2 interrupt flag
}



void setcolumn(unsigned char col)  //loop that takes care of column scanning
{
  signed char pos;
  for (pos =8; pos > -1; pos--)  //was pos=32, but again, only 4 columns now so pos=4
  {
  if (col == pos)
  {
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these reversed unlit-lit digits
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);
  }
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}



void setdata(unsigned char dat) {
  unsigned char pos;
  for (pos = 0; pos < 16; pos++)
  {
  if (dat & 32768)  //these dat were 128, but changed them to 16 as 16=128/8
  {
  dat -= 32768;
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these caused whole screen to be reversed for lit-unlit segments
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
  }
  dat = dat * 2;
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}



void clr() //clear
{
  int addr;
  for (addr = 0; addr < 4; addr++)  // Empty display buffer, reduced from 32 to 4
  backbuffer[addr] = 0;
}




void Blit()  //transfers data between display buffer to screen buffer
{
  int addr = 0;
  noInterrupts();  // disable all interrupts during setup
  for (addr = 0; addr < 4; addr ++)  //here also changed 32 to 4
  {
  buffer1[addr] = backbuffer[addr];  // put all data from display buffer to screen buffer
  }
  interrupts();  // enable all interrupts
}


void pixel(signed char x, signed char y, int cond)
{
  int pix, msk;
  if (x < 0 || y < 0) return;  // outside drawing limits negative
  if (x > 1 || y > 15) return;  // outside drawing limits positive
  pix = power[y];
  msk = backbuffer[x];  // get exsisting data
  if (cond == 2)
  pix ^= msk;  // XOR data to screen
  if (cond == 1)
  {
  pix = ~pix;
  pix &= msk;  // AND data to screen
  }
  if (cond == 0)
  pix |= msk;  // OR data to screen
  backbuffer[x] = pix;  // apply changes
}



void charput(unsigned char ch, signed char x, signed char y)
{
  signed char x1, y1;
  unsigned char disp;
  unsigned char disp2;
  disp = font[ch]; //look data from fontmap,
  Serial.println(disp/256, BIN);
  Serial.println(disp & 0xFF, BIN);
  for (y1 = 0; y1 < 16; y1++)  // eight pixels
  {
  disp2 = disp & power[y1];
  if (disp2 > 0)
  {
  pixel(x + x1, y + y1, 0); // OR the pixel to the display buffer
  }
  }


}


/*
  void strput(const char* ch, signed char x, signed char y)
  {
  int addr;
  while (*ch )
  {
  charput(*ch++, x, y);  // write a string to the display buffer
  x += 1;
  }
  }*/






void setup() //setup runs once
{
  Serial.begin(9600);

  noInterrupts();  // disable all interrupts during setup
  DDRD = DDRD | B11111100;  //port registers used to set pin directions
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 520;  // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
  TCCR1B |= (1 << WGM12);  // CTC mode, free-running, clear on match
  TCCR1B |= (0 << CS10);  // 256 prescaler
  TCCR1B |= (0 << CS11);  // 256 prescaler
  TCCR1B |= (1 << CS12);  // 256 prescaler
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
  interrupts();  // enable all interrupts

} // End main



void loop() //just sitting here
{
  int val=millis()/1000 % 10;
  clr();
  charput(5,  0, 0);
  Blit()
}
edit: attached WRONG fontmap -_-

and here's shot from serial montior charput(5):
upload_2016-3-11_11-22-30.png
and new fontmap as attachment
 

Attachments

  • FontMap14Segment(16bit).h
    4.7 KB · Views: 331
Last edited:
try this for test loop on the registers:
Code:
void loop() //just sitting here
{
  int val=millis()/1000 % 10;
  int xa,ya;

for (ya=0;ya<8;ya++){
for (xa=0;xa<14;xa++){
clr();
  pixel(xa,ya,0);
  Blit();
delay(500);
}}}
 
Last edited:
Hmm, that test loop didn't effect anything sadly :(
 
ready to post more vids!? it will help by visualizing which parts are being passed out wrong, feel free to turn delay up if it runs too slow
 
ANYTHING to help! To give brain little "breather" I tried to combine matrix with 7 segment, so 7 segment shows values/time etc and matrix would work as text display only, didn't work....at least yet.
The video I posted eariler was output for video you asked, same result, only no even flickery numbers seen
 
post 347 should display 1 pixel at a time, should... ...pls elaborate of flickering, do you mean just like in your post 336? also i edited post 347, pls retry

wait, i thought we were using 14 seg... pls post new schematic if you have them all hooked up, may as well hook up vu meter too if that is what you want to do, also vu datasheet/partno required, we may need to be careful here, since i recall we were short on memory using the 32x8 fontmap alone...
 
post 347 should display 1 pixel at a time, should... ...pls elaborate of flickering, do you mean just like in your post 336? also i edited post 347, pls retry
wait, i thought we were using 14 seg... pls post new schematic if you have them all hooked up, may as well hook up vu meter too if that is what you want to do, also vu datasheet/partno required, we may need to be careful here, since i recall we were short on memory using the 32x8 fontmap alone...
The flicker I mean is overall refresh rate; it's smaller when ISR rate is decreased->refresh rate increases so it's "normal" flicker. At OCR1A value 100 it's barely noticeable. But screen shows nothing like in post 336, only segments that are controlled fromn second shifter are lit. YES we are using 14 segment, but I tried to hook up 7 segment to matrix as daisy chained, as it too used 8-bit values, and I ahve working code for both 7-segment as well as matrix. If we run out of memory we can use teensy, I found solution how interrupts can be used with it and tested with matrix scrolling text+real time FFT, took about 40% of program storage and 25% RAM. So the final project in any way is some-digit 7-segment, OLED 128x32 that shows FFT and matrx that scrolls some random text, perhaps "good morning" and stuff like that.
FFT+scrolling RTC is tested to be working with teensy....so many small cluster bits of working code but hard to place one bigger code with all stuff as one :D. But, there's good thing here; I see less and less place for LCD now that controlling matrises is possible.
Tested that new code from post #347 but still same result, is there any debug I can take with Serial? With your code serial is quiet, but this shows values for counter (just testing....), but nothing shows on screen except those segments I talked earlier.
C:
void loop() //just sitting here
{
 int val = millis()/1000 % 10;
  clr();
  charput(val, 0, 0);
  Blit();
}
 
Quote: Only segments that are controlled from second shifter are lit.

pls post vid, its important to see what code from post 347 does to the output matrix, in order.... unless you are saying its blank?

again, i think we are at a point where we should hook it all up , then do schematic.
 
Sorry about delay, I don't always get alerts! I'll post video soonish, and as for shematic, it's the same that I posted eariler, photo of current situation: (video is useless, this is all it does :S)
IMG_1291.jpg
 
Last edited:
k, try this:

Code:
#include "FontMap14Segment.h"

int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;

unsigned char Display_Buffer_Size =4; // number of rows for buffer
unsigned char Cathode_Register_Size  = 8;  // number of elements in cathode register  (>0)
unsigned int Anode_Register_Size = 16 // number of elements in Anode shift register


unsigned char displayPointer = 0; // for interrupt usefile:///C:/Users/DOGGY-~1/AppData/Local/Temp/FontMap14Segment(16bit).h...
unsigned int buffer1[4]; //2x8 bits
unsigned int backbuffer[4]; // Spare screen for drawing on
//unsigned char power[8] = {1, 2, 4, 8,16,32,64,128}; //B00000001,B00000010,B00000100,B00001000 for digits
unsigned int  power[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 };


ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine, called every now and then, outside of loop
{
  if (TIFR2) // Make sure its the timer interrupt.
  {
  setcolumn(displayPointer);  //column scanning
  setdata(buffer1[displayPointer]);
  PORTD = (1 << PORTD3);
  PORTD = (0 << PORTD3);
  if (++displayPointer == 2){ displayPointer = 0;}  //  number of cathodes attached, then resets to 0
  }
  TIFR2 = 0; // Clear timer 2 interrupt flag
}



void setcolumn(unsigned char col)  //loop that takes care of column scanning
{
  signed char pos;
  for (pos = Cathode_Register_Size; pos > -1; pos--)  // shift in Cathode shift register loop
  //for (pos = 0; pos < Cathode_Register_Size; pos++)  // going this way flipps the screen horizontal
  {
  if (col == pos)
  {
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these reversed unlit-lit digits
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);
  }
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}


void setdata(unsigned char dat) {
  signed int pos;
  for (pos = 0; pos < Anode_Register_Size; pos++)  //  shift in Anode shift register loop
  //for (pos = Anode_Register_Size; pos > -1; pos--)  // vertical flip
  {
  if (dat & 32768)  // Read MSB first, 0b1000 0000 0000 0000 <--16th bit
  {
  dat -= 32768;
  PORTD = (1 << PORTD2);  //digitalWrite(dataPin ,HIGH);  //swapping these caused whole screen to be reversed for lit-unlit segments
  }
  else
  {
  PORTD = (0 << PORTD2);  //digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
  }
  dat = dat * 2;
  digitalWrite(clockPin , HIGH);
  digitalWrite(clockPin , LOW);
  }
}



void clr() //clear
{
  unsigned char addr;
  for (addr = 0; addr < Display_Buffer_Size; addr++)
  backbuffer[addr] = 0;  // clears the buffer array
}

void Blit()  //transfers data between display buffer to screen buffer
{
  unsigned char addr = 0;
  noInterrupts();  // disable all interrupts during setup
  for (addr = 0; addr < Display_Buffer_Size; addr ++) 
  {
  buffer1[addr] = backbuffer[addr];  // put all data from display buffer to screen buffer
  }
  interrupts();  // enable all interrupts
}


void pixel(signed char x, signed char y, int cond)
{
  int pix, msk;
  if (x < 0 || y < 0) return;  // outside drawing limits negative
  if (x > Cathode_Register_Size - 1 || y > Anode_Register_Size - 1) return;  // outside drawing limits positive
  pix = power[y];  // gets binary position
  msk = backbuffer[x];  // get exsisting data
  if (cond == 2)
  pix ^= msk;  // XOR data to screen
  if (cond == 1)
  {
  pix = ~pix;
  pix &= msk;  // AND data to screen
  }
  if (cond == 0)
  pix |= msk;  // OR data to screen
  backbuffer[x] = pix;  // apply changes
}



void charput(unsigned char ch, signed char x, signed char y)
{
  signed char y1;
  unsigned int disp;
  unsigned int disp2;
  disp = font[ch]; //look data from fontmap,
  Serial.println(disp/256, BIN);
  Serial.println(disp & 0xFF, BIN);
  for (y1 = 0; y1 < Anode_Register_Size; y1++)  
  {
  disp2 = disp & power[y1];
  if (disp2 > 0)
  {
  pixel(x, y + y1, 0); // OR the pixel to the display buffer
  }
  }


}

  void strput(const char* ch, signed char x, signed char y)
  {
  int addr;
  while (*ch )
  {
  charput(*ch++, x, y);  // write a string to the display buffer
  x += 1;
  }
  }

void setup() //setup runs once
{
  Serial.begin(9600);

  noInterrupts();  // disable all interrupts during setup
  DDRD = DDRD | B11111100;  //port registers used to set pin directions
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 520;  // compare match register value, was 31 for matrix (1920hz= 60hzx*32) but for now there's only 4 columns so: 4*60hz=240hz; 16mhz/256/240=260
  TCCR1B |= (1 << WGM12);  // CTC mode, free-running, clear on match
  TCCR1B |= (0 << CS10);  // 256 prescaler
  TCCR1B |= (0 << CS11);  // 256 prescaler
  TCCR1B |= (1 << CS12);  // 256 prescaler
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt
  interrupts();  // enable all interrupts

} // End main

void loop() //just sitting here
{
  int val=millis()/1000 % 10;
  int xa,ya;
for (xa=0;xa<14;xa++){
clr();
  pixel(xa,0,0 );
  Blit();
delay(500);
}
for (xa=0;xa<14;xa++){
clr();
  pixel(xa,1,0 );
  Blit();
delay(500);
}
}
 
Last edited:
Still shows that x-shape, and no other numbers or anything. serial gives out fontmap positions as earlier :)
 
The idea with combinind matrix and 7-segments is that 7-segments are connected as matrix columns, so only one more shift register is needed for them, as anodes are tied to matrix's anodes. So there would be two fontmaps, one for matrix one for 7-segments and last of columns (6-8) are for 7-segments. 6 columns would be enough for 7 segments as time format is HH.MM.SS, and DD.MM.YY(or YYYY, but that needs scrlolling, probadly need anyway) i do have separate 8x8 matrix that uses same circuit as that 8x32 matrix, tested it yesterday and it worked with 8x32 code, well 8x32 would be 8x8 too if i take 24 columns off....I was wondering if it code could be changed for matrix+7segment combo so it fills array in first from matrux font, then from 7-segment, just thinking out loud
 
definitely possible...

also change the first line in fontmap to this:
static unsigned int font [125] =
 
did that earlier to save precious ram :)....
 
Doggy! I'm SO sorry, I started doing basic tests and send three times 0's (B00000000) and still second set were on, there was ONE wiring error,, I'll re-do those previous codes!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top