getDistanceValue() { PLIBPORTSPinDirectionOutputSet(PORTSID0, PORTCHANNELE, PORTSBITPOS5); PLIBPORTSPinToggle(PORTSID0, PORTCHANNELE, PORTSBITPOS5); delayUs(5); PLIBPORTSPinClear(PORTSID0, PORTCHANNELE, PORTSBITPOS5); PLIBPORTSPinDirectionInputSet(PORTSID0, PORTCHANNELE, PORTSBITPOS5); delayUs(20); while (PLIBPORTSPinGet(PORTSID0, PORTCHANNELE, PORTSBITPOS5) == 0) { startCountUs = _CP0GETCOUNT(); } while (PLIBPORTSPinGet(PORTSID0, PORTCHANNELE, PORTSBITPOS5) != 0) { timeUs = (CP0GETCOUNT() – startCountUs) / USSCALE; }
distance = timeUs / (PING_DISTANCE_PULSE_CONVERSION_COEFF);
return distance;
}
This function was verified as working previously using the hardware timer on the board I had.
DelayUs is a function I created that just delays by microsec using the chip clock.
Now the problem happens when I try to use software timer for this.
Basically I have the timer call back function as below:
static void vTimerCallback(TimerHandlet pxTimer){ SensorData data; data.value = getDistanceValue(); data.dataTag = DISTANCESENSOR_ONE;
if(!pushSensorData(&roverADistanceQueue, data)) {
badErrorRoutine(QUEUE_PUSH_DATA_FAIL);
}
}
And the part where I try to call it is here:
xTaskCreate((TaskFunctiont) _mytask “my tasks”, 1024, NULL, 1, NULL);
TimerHandle_t timerHandle100ms = xTimerCreate(
"timer100Ms", /* name */
pdMS_TO_TICKS(100), /* period time */
pdTRUE, /* auto reload */
(void*)0, /* timer ID */
vTimerCallback);
if (timerHandle100ms == NULL) {
// error
}
if (xTimerStart(timerHandle100ms, 0) != pdPASS) {
// error
}
/**************
* Start RTOS *
**************/
vTaskStartScheduler(); /* This function never returns. */
This is the only task that is working. and for config: /* Software timer related definitions. */ define configUSE_TIMERS 1 define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES – 1) define configTIMER_QUEUE_LENGTH 100 define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) define configUSE_DAEMON_TASK_STARTUP_HOOK 0 Yet it does not work. It seems like no data is being collected using this timer. Is it because my getSensorValue function has blocking calls in it? Thanks in advance