john6340 wrote on Tuesday, March 19, 2019:
Hello!
A quick question.
So basically, I had a code snippet something like this:
getDistanceValue() {
PLIB_PORTS_PinDirectionOutputSet(PORTS_ID_0, PORT_CHANNEL_E, PORTS_BIT_POS_5);
PLIB_PORTS_PinToggle(PORTS_ID_0, PORT_CHANNEL_E, PORTS_BIT_POS_5);
delayUs(5);
PLIB_PORTS_PinClear(PORTS_ID_0, PORT_CHANNEL_E, PORTS_BIT_POS_5);
PLIB_PORTS_PinDirectionInputSet(PORTS_ID_0, PORT_CHANNEL_E, PORTS_BIT_POS_5);
delayUs(20);
while (PLIB_PORTS_PinGet(PORTS_ID_0, PORT_CHANNEL_E, PORTS_BIT_POS_5) == 0) {
startCountUs = _CP0_GET_COUNT();
}
while (PLIB_PORTS_PinGet(PORTS_ID_0, PORT_CHANNEL_E, PORTS_BIT_POS_5) != 0) {
timeUs = (_CP0_GET_COUNT() - startCountUs) / US_SCALE;
}
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(TimerHandle_t pxTimer){
SensorData data;
data.value = getDistanceValue();
data.dataTag = DISTANCE_SENSOR_ONE;
if(!pushSensorData(&roverADistanceQueue, data)) {
badErrorRoutine(QUEUE_PUSH_DATA_FAIL);
}
}
And the part where I try to call it is here:
xTaskCreate((TaskFunction_t) _my_task
“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