Construction of Word Clock v1

Rasprava o AVR mikrokontrolerima, AVR projekti i drugo vezano za AVR...

Moderators: pedja089, stojke369, trax, InTheStillOfTheNight

Post Reply
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

Where did you get that code from? There is no STATUS_LED in Word Clock v1. Status LED is available only in v2 of the clock.

You should download the code from project page, and work with it to adjust your led-mappings I talked about earlier...

edit: oh, sorry. I pasted the MAIN() function to you from clock v2. Don't worry, just delete that line where STATUS_LED is used.
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

when I change this

Code: Select all

            // now rearrange the indexes
            uint8_t new_index;
            switch (j)
            {
               case 0: new_index=0; break;
               case 1: new_index=4; break;
               case 2: new_index=6; break;
               case 3: new_index=2; break;
               case 4: new_index=3; break;
               case 5: new_index=7; break;
               case 6: new_index=5; break;
               case 7: new_index=1; break;
            }
or this

Code: Select all

new_byte |= (old_byte & 0b00000001) << 4;
it dosn't change on the matrix.

only on this code

Code: Select all

max72xx_write(1, 1, 0b00000001)
can i switch the quarter.
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

When you change

Code: Select all

    new_byte |= (old_byte & 0b00000001) << 4;
to (for example)

Code: Select all

    new_byte |= (old_byte & 0b00000001) << 2;
you should see different LED turn on in your clock
... if not, then try sending

Code: Select all

    max72xx_write(1, 1, 0b11111111)
all "logical one", maybe I gave you wrong instructions the other day. :?
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

yes, when i change this code

Code: Select all

    max72xx_write(1, 1, 0b11111111)
can i switch the quarter, the rows and the columns.


But i can't adjust this. no matter what i change in this code

Code: Select all

                // now rearrange the indexes
                uint8_t new_index;
                switch (j)
                {
                   case 0: new_index=0; break;
                   case 1: new_index=4; break;
                   case 2: new_index=6; break;
                   case 3: new_index=2; break;
                   case 4: new_index=3; break;
                   case 5: new_index=7; break;
                   case 6: new_index=5; break;
                   case 7: new_index=1; break;
                }
or in this

Code: Select all

new_byte |= (old_byte & 0b00000001) << 4;
the glowing LED are the same
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

I have looked at the source code, and you are correct. Try this in the main() to see what turns ON in the first MAX:

Code: Select all

display_matrix_new[0][7] = 0b00000001;
display_matrix_new[0][6] = 0b00000001;
display_matrix_new[0][5] = 0b00000001;
display_matrix_new[0][4] = 0b00000001;
display_matrix_new[0][3] = 0b00000001;
display_matrix_new[0][2] = 0b00000001;
display_matrix_new[0][1] = 0b00000001;
display_matrix_new[0][0] = 0b00000001;
max72xx_send_matrix();
while(1);
instead of this line here:

Code: Select all

max72xx_write(0, 0, 0b00000001)
later you can test other MAX chips with the same code, just change index

Code: Select all

display_matrix_new[0] // [0] - max 1, [1] - max 2, ...
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

Sorrry for the trobble.

When i insert the code comes this error
../../../15d-09m-2012y/wc.c:176:1: error: 'display_matrix_new' undeclared (first use in this function)
i posted the completely main()

Code: Select all

//############
// Main app //
//############
int main(void)
{
   // Initialize Timer0 overflow ISR
   TCCR0A = 0;
   TCCR0B = _BV(CS00);                            // no prescaling, but timer started!
   TIMSK0 |= _BV(TOIE0);                            //-for-> ISR(TIMER0_OVF_vect)

   // Interrupts ON
   sei();

   // turn on pin-change-interrupts
   pin_interrupt_init();                            // this will set the DDRs for button/sensors and prepare the interrupts


   // initialize the MAX72XX chips
   max72xx_init_hw();                              // init the hw for MAX72XX

   // RTC init
   rtc_init();                                  // init the DS323X RTC IC

   // Light sensor init
   light_sensor_init();                           // init the light sensor

   // MAX72XX inits
   max72xx_init_all();                              // init all MAX chips in the system

   // Check to see if there is something valid in EEPROM
    uint8_t *pEE = (uint8_t *)EEPROM_START;
   if( eeprom_read_byte(pEE++) == 0xAA ) // 0xAA is my "valid flag"
   {
      calib_light_sens_min = eeprom_read_word((uint16_t *)pEE);
      pEE+=2;
      calib_light_sens_max = eeprom_read_word((uint16_t *)pEE);
      pEE+=2;
      eeprom_read_block((void *)&disp_duration,pEE,DISP_THINGS);
      pEE+=DISP_THINGS;
      bools[BUSR1] = eeprom_read_byte(pEE);
   }

   // falsify RTC changes so it display whatever is required immediatelly
   bs(bRTC_MinChg,BAPP1);
   bs(bRTC_SecChg,BAPP1);
   bs(bRTC_TempChg,BAPP1);

   delay_ms_(1000);                              // startup delay


   // scroll some intro text...
   max72xx_write(MAX72XX_COUNT+1, MAX72XX_intensity, 0x07); // set brightness to half initially



   // FINDING ROWS
   // max72xx_write(MAX ID 1..4, CLOCK LED ROW ADDRESS 1..8, DATA_HERE);         
   //max72xx_write(1, 1, 0b11111111); // turn on MAX 1 - address of DIGn (this is actually a ROW in the clock)
   //while(1); // stop here
   


display_matrix_new[0][7] = 0b00000001;
display_matrix_new[0][6] = 0b00000001;
display_matrix_new[0][5] = 0b00000001;
display_matrix_new[0][4] = 0b00000001;
display_matrix_new[0][3] = 0b00000001;
display_matrix_new[0][2] = 0b00000001;
display_matrix_new[0][1] = 0b00000001;
display_matrix_new[0][0] = 0b00000001;
max72xx_send_matrix();
while(1);


   return 0;
}
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

No, I am sorry :wink:
I don't have a compiler here at work, so I am making mistakes.

In the main() experimental code, instead of display_matrix_new, you should write display_matrix.
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

I have the 2 parts of matrix-code among copied. The first part

Code: Select all

display_matrix[2][7] = 0b00000001;
display_matrix[2][6] = 0b00000001;
display_matrix[2][5] = 0b00000001;
display_matrix[2][4] = 0b00000001;
display_matrix[2][3] = 0b00000001;
display_matrix[2][2] = 0b00000001;
display_matrix[2][1] = 0b00000001;
display_matrix[2][0] = 0b00000001;
max72xx_send_matrix();
while(1);
is good I can display the columns, but what ever i change in the second part

Code: Select all

// now rearrange the bits into a new byte
				uint8_t new_byte = 0;
				new_byte |= (old_byte & 0b00000001) << 2;
				new_byte |= (old_byte & 0b00000010);
				new_byte |= (old_byte & 0b00000100);
				new_byte |= (old_byte & 0b00001000);
				new_byte |= (old_byte & 0b00010000) >> 1;
				new_byte |= (old_byte & 0b00100000);
				new_byte |= (old_byte & 0b01000000);
				new_byte |= (old_byte & 0b10000000);

				// now rearrange the indexes
				uint8_t new_index;
				switch (j)
				{
					case 0: new_index=0; break;
					case 1: new_index=4; break;
					case 2: new_index=6; break;
					case 3: new_index=2; break;
					case 4: new_index=3; break;
					case 5: new_index=7; break;
					case 6: new_index=5; break;
					case 7: new_index=1; break;
				}
don't change anything on the matrix.

I have copy the full code (the two parts)

Code: Select all

// FINDING ROWS
       // max72xx_write(MAX ID 1..4, CLOCK LED ROW ADDRESS 1..8, DATA_HERE);         
       //max72xx_write(1, 1, 0b11111111); // turn on MAX 1 - address of DIGn (this is actually a ROW in the clock)
       //while(1); // stop here
       



display_matrix[2][7] = 0b00000001;
display_matrix[2][6] = 0b00000001;
display_matrix[2][5] = 0b00000001;
display_matrix[2][4] = 0b00000001;
display_matrix[2][3] = 0b00000001;
display_matrix[2][2] = 0b00000001;
display_matrix[2][1] = 0b00000001;
display_matrix[2][0] = 0b00000001;
max72xx_send_matrix();
while(1);


	return 0;
}

// send "data matrix" array to all MAXes
void max72xx_send_matrix()
{
	uint8_t max_id, j, max_addr;

	// since MAXes and LEDs are arranged in a funky way, we need to "transform" the data_matrix array before sending it to MAXes
	uint8_t display_matrix_new[MAX72XX_COUNT][8];

	// copy and do some transformations because LED matrices are soldered in a funky way onto the MAX chips :)
	// MAX7219 RE-MAPPING CODE:
	for(max_id=0; max_id<MAX72XX_COUNT; max_id++) // for each MAX chip
	{
		for(j=0; j<8; j++) // and each MAX accepts 8 bytes
		{
			// MAX1 and MAX4 are soldered in the same fashion
			if(max_id==0 || max_id==3)
			{
				uint8_t old_byte = display_matrix[max_id][j];

				// now rearrange the bits into a new byte
				uint8_t new_byte = 0;
				new_byte |= (old_byte & 0b00000001);
				new_byte |= (old_byte & 0b00000010);
				new_byte |= (old_byte & 0b00000100);
				new_byte |= (old_byte & 0b00001000);
				new_byte |= (old_byte & 0b00010000);
				new_byte |= (old_byte & 0b00100000);
				new_byte |= (old_byte & 0b01000000);
				new_byte |= (old_byte & 0b10000000);

				// now rearrange the indexes
				uint8_t new_index;
				switch (j)
				{
					case 0: new_index=0; break;
					case 1: new_index=4; break;
					case 2: new_index=6; break;
					case 3: new_index=2; break;
					case 4: new_index=3; break;
					case 5: new_index=7; break;
					case 6: new_index=5; break;
					case 7: new_index=1; break;
				}

				display_matrix_new[max_id][new_index] = new_byte;
			}
			// and MAX2 and MAX3 are soldered in the same fashion
			else
			{
				uint8_t old_byte = display_matrix[max_id][j];

				// now rearrange the bits into a new byte
				uint8_t new_byte = 0;
				new_byte |= (old_byte & 0b00000001) <<3;
				new_byte |= (old_byte & 0b00000010) ;
				new_byte |= (old_byte & 0b00000100) ;
				new_byte |= (old_byte & 0b00001000) ;
				new_byte |= (old_byte & 0b00010000) ;
				new_byte |= (old_byte & 0b00100000) ;
				new_byte |= (old_byte & 0b01000000) ;
				new_byte |= (old_byte & 0b10000000) ;

				// now rearrange the indexes
				uint8_t new_index;
				switch (j)
				{
					case 0: new_index=7; break; // ili je 5 ili je 1
					case 1: new_index=6; break; // ili je 1 ili je 5
					case 2: new_index=5; break;
					case 3: new_index=4; break;
					case 4: new_index=3; break;
					case 5: new_index=2; break;
					case 6: new_index=0; break;
					case 7: new_index=1; break;
				}

				display_matrix_new[max_id][new_index] = new_byte;
			}
		}
	}

	// finally send the new display matrix to all MAXes
	for(max_id=1; max_id<=MAX72XX_COUNT; max_id++)
	{
		for(j=0, max_addr=0x01; j<8; j++, max_addr++)
		{
			max72xx_write(max_id, max_addr, display_matrix_new[max_id-1][j]); // send appropriate data to appropriate MAX :)
		}
	}

	return;
}
i dont understand why this not works
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

That is strange, it should work. You muse recompile and re-program the AVR chip after each modification to see the changes in the display (just saying :D).

Anyway, when you turn on LED columns with this instruction:

Code: Select all

display_matrix[2][7] = 0b00000001;
display_matrix[2][6] = 0b00000001;
display_matrix[2][5] = 0b00000001;
display_matrix[2][4] = 0b00000001;
display_matrix[2][3] = 0b00000001;
display_matrix[2][2] = 0b00000001;
display_matrix[2][1] = 0b00000001;
display_matrix[2][0] = 0b00000001;
max72xx_send_matrix();
while(1);
Only these LEDs should be ON in the matrix:

Code: Select all

0000000X
0000000X
0000000X
0000000X
0000000X
0000000X
0000000X
0000000X
but, if for example these LEDs turn ON instead:

Code: Select all

0000X000
0000X000
0000X000
0000X000
0000X000
0000X000
0000X000
0000X000
You must make this transformation in the function bellow:

Code: Select all

// now rearrange the bits into a new byte
            uint8_t new_byte = 0;
            new_byte |= (old_byte & 0b00000001) << 3; // move this LED to the let 3 times
            new_byte |= (old_byte & 0b00000010);
            new_byte |= (old_byte & 0b00000100);
            new_byte |= (old_byte & 0b00001000);
            new_byte |= (old_byte & 0b00010000);
            new_byte |= (old_byte & 0b00100000);
            new_byte |= (old_byte & 0b01000000);
            new_byte |= (old_byte & 0b10000000);
now that you have done it for the led 0b00000001 you must do the same for remaining 7 LEDs.

---------------

Now, for the problem you are having.
Remember, you have two sections of code in function "max72xx_send_matrix()" - the first section is for MAX 1 and MAX 4, and the second section is for the MAX 2 and MAX 3. If you are experimenting with this max ID (2):

Code: Select all

display_matrix[2][*]
you need to alter the second section of the "max72xx_send_matrix()" function, not the first one!
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

IT WORKS :ohno:

But the corner dots are on the wrong place. Can I change this in the code?
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

Great!!!

Yes you can. You need to find where you soldered them to.

Do this test in the main():

Code: Select all

// finding dots for MAX 2
display_matrix[1][7] = 0b00000000;
display_matrix[1][6] = 0b00000000;
display_matrix[1][5] = 0b00000000;
display_matrix[1][4] = 0b00000000;
display_matrix[1][3] = 0b00000000;
display_matrix[1][2] = 0b00000000;
display_matrix[1][1] = 0b11111111;
display_matrix[1][0] = 0b11111111;
// finding dots for MAX 3
display_matrix[2][7] = 0b00000000;
display_matrix[2][6] = 0b00000000;
display_matrix[2][5] = 0b00000000;
display_matrix[2][4] = 0b00000000;
display_matrix[2][3] = 0b00000000;
display_matrix[2][2] = 0b00000000;
display_matrix[2][1] = 0b11111111;
display_matrix[2][0] = 0b11111111;

max72xx_send_matrix();
while(1);
And observe to see what will turn ON. If only dots turn ON then we are OK, if not, you will need to re-wire MAX 2 and MAX 3 (not everything, only small changes - don't worry).
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

Its me again, making mistakes :-)

You will not need to re-wire anything, you will just need to re-map it in the function "max72xx_send_matrix()"...

P.S. These first two indexes for MAX 2 and MAX 3 should turn ON only the dots...

Code: Select all

display_matrix[2][1] = 0b11111111;
display_matrix[2][0] = 0b11111111;
and

Code: Select all

display_matrix[1][1] = 0b11111111;
display_matrix[1][0] = 0b11111111;
only for dots...
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

I have found the corner dots

Code: Select all

display_matrix[2][6] = 0b10000000; // BR
display_matrix[2][7] = 0b01000000; // TR
and

Code: Select all

display_matrix[1][6] = 0b10000000; // BL
display_matrix[1][7] = 0b01000000; // TL
but in the original main() blink other dots, how can i change this?
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

ok, you need to do 2 things now.

1. in the wt.H file at the bottom, you will find the DOTS definition. change that for your needs.
2. in the "max72xx_send_matrix()" function, find the portion of code with comment

Code: Select all

			// and MAX2 and MAX3 are soldered in the same fashion
			else
			{
				uint8_t old_byte = display_matrix[max_id][j];

				// now rearrange the bits into a new byte
				uint8_t new_byte = 0;
				new_byte |= (old_byte & 0b00000001) << 4;
				new_byte |= (old_byte & 0b00000010) << 1;
				new_byte |= (old_byte & 0b00000100) << 5;
				new_byte |= (old_byte & 0b00001000);
				new_byte |= (old_byte & 0b00010000) << 2;
				new_byte |= (old_byte & 0b00100000) >> 4;
				new_byte |= (old_byte & 0b01000000) >> 1;
				new_byte |= (old_byte & 0b10000000) >> 7;

				// now rearrange the indexes
				uint8_t new_index;
				switch (j)
				{
					case 0: new_index=1; break; // ili je 5 ili je 1
					case 1: new_index=5; break; // ili je 1 ili je 5
					case 2: new_index=7; break;
					case 3: new_index=3; break;
					case 4: new_index=2; break;
					case 5: new_index=6; break;
					case 6: new_index=4; break;
					case 7: new_index=0; break;
				}

				display_matrix_new[max_id][new_index] = new_byte;
			}
		}
Now you need to fix these indexes because they are not OK.

TO FIX:

Code: Select all

					case 0: new_index=1; break; // ili je 5 ili je 1
					case 1: new_index=5; break; // ili je 1 ili je 5
					case 2: new_index=7; break;
					case 3: new_index=3; break;
					case 4: new_index=2; break;
					case 5: new_index=6; break;
					case 6: new_index=4; break;
					case 7: new_index=0; break;
----

With the following test code you need to make sure that each row on the display corresponds to the correct row in the display_matrix[][] array. In the attachment image, you can see which matrix row represents which row in the display screen.

Code: Select all

display_matrix[1][7] = 0b11111111;
display_matrix[1][6] = 0b11111111;
display_matrix[1][5] = 0b11111111;
display_matrix[1][4] = 0b11111111;
display_matrix[1][3] = 0b11111111;
display_matrix[1][2] = 0b11111111;
display_matrix[1][1] = 0b00000000;
display_matrix[1][0] = 0b00000000;
max72xx_send_matrix();
while(1);
Attachments
max_rows.jpg
(137.78 KiB) Not downloaded yet
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

i'm almost finished.

but i have one little problem.

the time does not display correctly. we say in german to

"half past seven" (7:30) instead "half eight"

or to

"quarter past seven" (7:15) instead "quarter eight"

or to

"quarter to seven" (7:45) instead "three quarters eight"

can i change this in the code or is this fixed?

it is difficult to explain in english but i hope you understand me.
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

Yes I understand what you mean. Did you make a front panel with letters? How did you arrange them? Can I see it?

Anyway, make a copy of lang_ba.h file and name it lang_de.h
Edit wt.c and find #include "lang_ba.h" and replace it with "lang_de.h"
Then, open it and make your own language combinations. You will see which LEDs needs to turn ON to display an hour, and what LEDs turn on for minutes. Play with it a little.

Also, when you finish LED mappings for the MAX 2 and MAX 3, you will need to do the same for MAX 1 and MAX 4 - the bottom part of the clock (if you didn't do it already).
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

Anyway, make a copy of lang_ba.h file and name it lang_de.h
Edit wt.c and find #include "lang_ba.h" and replace it with "lang_de.h"
Then, open it and make your own language combinations. You will see which LEDs needs to turn ON to display an hour, and what LEDs turn on for minutes. Play with it a little.
i have made a pic for my problem.

http://imageshack.us/a/img836/4273/frontzeiten.png

when i say (7:00)

"It is 7 o'clock" is this in german "es ist um 7" (this is right in the code)

but when i say (7:30)

"it is half past 7" is this in german "es ist halb 8"

or when i say "7:45" light the 7 but i need the 8

So now must light the 8 not the 7.
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

Can you make a combination where any "time" can be written? Example: 1:47, 9:51, ... ?
How would that sound in German language?
Pielo
Pocetnik na forumu
Pocetnik na forumu
Posts: 37
Joined: 15-01-2013, 13:23
Location: Germany, Thüringen

Re: Construction of Word Clock v1

Post by Pielo »

i dont know what you mean

1:47 = es ist dreiviertel zwei ( and two corner dots)
2:00 = es ist um zwei
9:51 = es ist zehn vor um zehn (and one corner dot)

did you mean that?
User avatar
trax
Administrator sajta
Administrator sajta
Posts: 3508
Joined: 08-01-2005, 18:04
Location: 75k, BA
Contact:

Re: Construction of Word Clock v1

Post by trax »

No, I mean forget about the corner dots, can you display full time in words only?

The corner dots in this Word Clock are not for time (+1, +2, +3, +4 minutes) like in the original! They are here just for good looks :-)

How about you make a front panel with all words combinations for the time?

P.S. to make the corner dots display time (+1, +2, +3, +4 minutes) a source-code modification must be made...
Post Reply