7 years, 6 months ago.  This question has been closed. Reason: Duplicate question

Unable to use mutiple tickers for my application

Hello,

I am working on Nucelo L053r8t6 custom board for one of my application. where i need to implement 5 tickers may be some times at equal intervals of time the event must work for all the tickers. But when using mutiple number of tickers happen to see only one ticker is being executed and rest of them are being ignored. I here by attch few sample snippets that i am working on. Could you please tell me the solution for the problem i am facing .

Interval at which each function to be executed

void prot_Communicate :: Sampling_Rate_Temprature(uint8_t Sampling_val)
{
	 switch(Sampling_val) 
	 {
		 case SAMPLING_1SEC :
		 {
			 Temp_Sense_Update.attach(this,&prot_Communicate :: Temperature_Sensor,1);
		 }
		 break;
		 case SAMPLING_2SEC :
		 {
			 Temp_Sense_Update.attach(this,&prot_Communicate :: Temperature_Sensor,2);
		 }
		 break;
		 case SAMPLING_5SEC :
		 {
			 Temp_Sense_Update.attach(this,&prot_Communicate :: Temperature_Sensor,5);
		 }

Decleration of tickers and the indication flags

Ticker Temp_Sense_Update;
Ticker Humid_Sense_Update;
Ticker Baro_Sense_Update;
Ticker Lux_Sense_Update; 

bool flag_temp_sensor,flag_humid_sensor,flag_baro_sensor,flag_lux_sensor,flag_accelro_sensor;

Attching the ticker with function

 void prot_Communicate :: Temperature_Sensor(void)
{
		flag_temp_sensor = 1;
}

void prot_Communicate :: Humid_Sensor(void)
{
		flag_humid_sensor = 1;
}
void prot_Communicate :: Baro_Sensor(void)
{
		flag_baro_sensor = 1;
}

void prot_Communicate :: Lux_Sensor(void)
{
		flag_lux_sensor = 1;
}

Start the device with the given sampling rate

void prot_Communicate :: Start_Stop_logger(void)
{ 
    if (f_start)
    {
				if(flag_temp_sensor)
				{
						 flag_temp_sensor = 0;
						 Temp = sht.readTemp();
						 fprintf(logFile,"\r\n%3.2f °C",Temp);
					//	 FloatSep(Temp,&package.Data[i],&package.Data[i+2]);
					//	 i += 4;
				}
				if(flag_humid_sensor)
				{
						flag_humid_sensor = 0;
						Humd = sht.readHumidity();
					  fprintf(logFile,"\r\n%3.2f RH", Humd);
						// FloatSep(Humd,&package.Data[i],&package.Data[i+2]);	
						// i += 4;
				}	
				if(flag_baro_sensor)
				{
						flag_baro_sensor = 0; 
				//		Pressure = ms.calcPressure();
					  //fprintf(logFile,"\r\n%.1f mB\n", Pressure);
						// FloatSep(Pressure,&package.Data[i],&package.Data[i+2]);
						// i += 4;
				}	
				if(flag_lux_sensor)
				{ 
						 flag_lux_sensor = 0;
						 Lux = max44009.getLUXReading();
					   fprintf(logFile,"\r\n%f lux",Lux);
						// FloatSep(Lux,&package.Data[i],&package.Data[i+2]);
						// i += 4;
				}

here comes the problem that only the temprature flag is being raised but but any other flags. I have tested using keil compiler by inserting break points at required sections but found that only temparture flag is being raised but no other flags are being raised. could you please help me in this issue. Thank you.

You've not included the bit of code you say isn't working, where do you attach to the tickers other than the temperature one?

posted by Andy A 12 Oct 2016

Also the flag variables should volatile, without that their operation will be unreliable.

posted by Andy A 12 Oct 2016

hello Andy You can now download my source code on which i am working ..... Could you please check in to that.

posted by san m 12 Oct 2016

Hello, Every time what ever the order the tickers are declared the first ticker is being executed nut rest are neglected.

Ticker Temp_Sense_Update; Ticker Humid_Sense_Update; Ticker Baro_Sense_Update; Ticker Lux_Sense_Update;

here the first ticker declared which is attached to tempreature sensor so i am able to raise the flag for temparture sensor but not for the rest.

posted by san m 12 Oct 2016

Why have you assigned this to me? I don't have your hardware, I don't even have a board with the same processor as you. By assigning it to me you have prevented anyone else from being able to answer.

I can't see anything obvious wrong with the code. If changing the order of the declarations is having an impact then either you have run out of RAM and it can't create the ticker objects or there is a bug in the library.

If it's a memory issue moving the tickers to the start of the file will change what's happening, it'll probably crash or go wrong in some other way.

Make a simple test program with two tickers driving two LEDs or something similarly simple and see if it has the same problem. If so submit it as a bug report for the mbed library. Then roll back the mbed library to one from 6 months ago and see if the problem goes away. If so include that in your bug report and for now use the old version with your project

posted by Andy A 12 Oct 2016

I am sorry i did not knew that if i assign a question means that i am preventing others to look at my code. Sorry for the inconvenience and i will try to work around the issue that you had raised and post if there are any such problem in further to mbed library.

posted by san m 12 Oct 2016