multi threading

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

i HAVE 2 different tasks in my implementation.
1)roatate the LEDS from 0 to untill the pressed switch.(using timer)

2)UART COMMUNICATION: ACCORDING TO THE received charecter I write into eeprom & read from eeprom.
I have no idea about multi threading.Could anyone help me?I use STK500 atmega8515.

Both implementation works separately.But WHEN include both the tasks in the main, roration of LED'S IS NOT HAPPENING. ALL THE LEDS are glowing. When I send a charecter, it interrupts the rotation of the LEDS.

Things which I want to do:
1)When I press the switch, rotation should happen accoring to the pressed switch. When none of the switch are pressed just rotate all the LEDS.(I have implemented this , it is working ,when i dont include USART)

2)uSART COMMU:I have implemented this , it is working ,when i dont include timer ROUTINE FOR RATATION)

hOW TO CONTROL THESE 2 TASKS?

extern volatile UINT8 switch_state;



extern UINT8 store_in_eeprom[200];
volatile UINT8 LEDs;

void delay(unsigned int val)
{
   volatile unsigned int temp;
   volatile unsigned int temp2;

   for(temp = 0; temp < val; temp++) 
   for (temp2 = 0; temp2 < val; temp2 ++) ;

}


int main(void)
{
	
	volatile UINT8  receivedByte, index,control_z_press ,readValue; 
	writetoreg(DDRB,0Xff);    /* Initialize port B for output (LEDs) */
	writetoreg(DDRA,0X00);    /*iNITIALIZE PORT A as input(as switches) */
	writetoreg(LEDS, 0xff);  /* Set all LEDs to OFF; invert the output since a zero means LED is ON */


	LEDs = 0;
	index = 0;
	control_z_press = 0;

	cli();  				// no interrupts while we're changing timer params!
	Inittimer0();
	serialInit();
	sei();                 //ENABLE interrupt

	

	
	
	for ( ; ; )
	{
		
			switch_state = ~(readfromreg(PINA));
			writetoreg(LEDS, LEDs); 

		receivedByte = rx();

		
		if((receivedByte == 0x1A )&& (control_z_press < 1)) 
		{

			control_z_press++;
		}
		else if((control_z_press == 1) &&  (receivedByte != 0X1A)) 
		{
			
			if((index <= 200))
			{
				delay(10);

				EEPROM_write((UINT16)(store_in_eeprom + index), receivedByte);
			
				index = index + 1;
				
				delay(10);

				tx(receivedByte);

		
		    }
						
		}
		else if ((receivedByte == 0X1A) && (control_z_press == 1))
		{
			control_z_press = 0; 
			
		}

		else if(receivedByte == 0x19)
		{
         	
			if(((--index) <= 200))
			{
		 		delay(10);

		 		readValue = EEPROM_read((UINT16)(store_in_eeprom + index));

		 		delay(10);
				tx(readValue);
		 				 
			}
		}
		else
		{
			tx(receivedByte);
		
		}

			
		
		
	} 
	

	return(0);
} 





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

I have a tutorial on multitasking -just look in the tutorials section. You might want to also look for abcminiuser's tut on interrupt driven uart comms.

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

Quote:

You might want to also look for abcminiuser's tut on interrupt driven uart comms.

I'd suggest that - this just need an interrupt for the UART - not full-blown multi-tasking.

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

couldyou please send me the link for the multitasking?

Kartman wrote:
I have a tutorial on multitasking -just look in the tutorials section. You might want to also look for abcminiuser's tut on interrupt driven uart comms.

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

Quote:

couldyou please send me the link for the multitasking?

Just pop over to the tutorials forum and use your browser to search for "multi". Or "Kartman".

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

I went to the top of this page. Clicked the "Search" link. Typed "multitasking" and set the "forum" to "Tutorials". The middle of the 3 results was:

https://www.avrfreaks.net/index.p...

Is search not working for you?

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

Ahhhhh! the power of the interwebs.