deac3 wrote on Wednesday, March 01, 2017:
Hi All,
I’m creating and starting 9 timers as part of a constructor for my class. I am creating 4 instances of this class and it looks like only the timers for the first couple are running. My constructor is as follows:
SDM220( int mod_id )
{
this->meter_id = mod_id;
printf("SDM220 #%d\n", this->meter_id );
// begin all the timers
for( int i = 0; i < NUM_TIMERS; i++ )
{
// configure a token for timer i
my_tokens[ i ].meter_id = mod_id;
my_tokens[ i ].read_type = sdm_sensor_configs[ i ].identifier;
my_tokens[ i ].config_idx = i;
void* token_ptr = &my_tokens[ i ];
// create and start timer i
xTimers[ i ] = xTimerCreate( "sdm_timer", // text name of timer, store tag?
sdm_sensor_configs[ i ].sensor_delay / portTICK_PERIOD_MS, // timer interval
pdTRUE, // reset timer?
token_ptr, // timer id, in this case token object
this->vTimerCallback ); // timer callback function
if( xTimers[ i ] != NULL )
{
if( xTimerStart( xTimers[ i ], 0 ) != pdPASS )
{
printf( "timer not activated\n" );
}
}
else
{
printf( "sdm220 constructor goofed\n" );
}
}
// create recipient queue for all the meters
xSDMQueue = xQueueCreate( 10, sizeof( sdm_read_token ) );
}
None of the xTimerStart() != pdPASS checks fail, but the timers for the later declared instances do not trigger.
For example if i declare the objects like this
// instantiate sdm meters
struct SDM220 my_sdm_1( 1 );
struct SDM220 my_sdm_2( 2 );
struct SDM220 my_sdm_3( 3 );
struct SDM220 my_sdm_4( 4 );
Then events for 1 and 2 come through fine, but 3 is spotty and 4 is nonexistent.
If I declare them like this:
// instantiate sdm meters
struct SDM220 my_sdm_2( 2 );
struct SDM220 my_sdm_3( 3 );
struct SDM220 my_sdm_4( 4 );
struct SDM220 my_sdm_1( 1 );
Then 2 and 3 come through fine, 4 is spotty, and 1 is nonexistent.
I thought it might be a stack issue on the timer service task but I increased the stack in FreeRTOSconfig.h and it remained unused! Any advice would be much appreciated!