mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-03 03:13:25 +02:00
Fix the usage of vTaskDelayUntil call correctly
ix: prevent reference the uninitialized value at the first delay call. seeAlso https://www.freertos.org/vtaskdelayuntil.html
This commit is contained in:
@@ -74,10 +74,9 @@ void servosSyncTask(void *pvParameters)
|
||||
TickType_t xLastWakeTime;
|
||||
const TickType_t xServoFrequency = SERVO_TIMER_INT_FREQ; // in ticks (typically ms)
|
||||
uint16_t servo_delay_counter = 0;
|
||||
|
||||
while(true) { // don't ever return from this or the task dies
|
||||
|
||||
vTaskDelayUntil(&xLastWakeTime, xServoFrequency);
|
||||
xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.
|
||||
while(true) { // don't ever return from this or the task dies
|
||||
#ifdef SERVO_X_PIN
|
||||
X_Servo_Axis.set_location();
|
||||
|
||||
@@ -88,6 +87,7 @@ void servosSyncTask(void *pvParameters)
|
||||
#ifdef SERVO_Z_PIN
|
||||
Z_Servo_Axis.set_location();
|
||||
#endif
|
||||
vTaskDelayUntil(&xLastWakeTime, xServoFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -104,10 +104,8 @@ void servoSyncTask(void *pvParameters)
|
||||
float mpos_z, wpos_z;
|
||||
float z_offset;
|
||||
|
||||
xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.
|
||||
while(true) { // don't ever return from this or the task dies
|
||||
|
||||
vTaskDelayUntil(&xLastWakeTime, xServoFrequency);
|
||||
|
||||
if (sys.state != STATE_ALARM) { // don't move until alarm is cleared...typically homing
|
||||
if (!servo_pen_enable ) {
|
||||
servo_delay_counter++;
|
||||
@@ -120,6 +118,7 @@ void servoSyncTask(void *pvParameters)
|
||||
calc_pen_servo(wpos_z); // calculate kinematics and move the servos
|
||||
}
|
||||
}
|
||||
vTaskDelayUntil(&xLastWakeTime, xServoFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,9 +168,9 @@ void calc_pen_servo(float penZ)
|
||||
// update the PWM value
|
||||
// ledcWrite appears to have issues with interrupts, so make this a critical section
|
||||
portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED;
|
||||
taskENTER_CRITICAL(&myMutex);
|
||||
portENTER_CRITICAL(&myMutex);
|
||||
ledcWrite(SERVO_PEN_CHANNEL_NUM, servo_pen_pulse_len);
|
||||
taskEXIT_CRITICAL(&myMutex);
|
||||
portEXIT_CRITICAL(&myMutex);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -68,11 +68,9 @@ void solenoidSyncTask(void *pvParameters)
|
||||
TickType_t xLastWakeTime;
|
||||
const TickType_t xSolenoidFrequency = SOLENOID_TIMER_INT_FREQ; // in ticks (typically ms)
|
||||
uint16_t solenoid_delay_counter = 0;
|
||||
|
||||
|
||||
xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.
|
||||
while(true) { // don't ever return from this or the task dies
|
||||
|
||||
vTaskDelayUntil(&xLastWakeTime, xSolenoidFrequency);
|
||||
|
||||
if (!solenoid_pen_enable) {
|
||||
solenoid_delay_counter++;
|
||||
solenoid_pen_enable = (solenoid_delay_counter > SOLENOID_TURNON_DELAY);
|
||||
@@ -82,6 +80,7 @@ void solenoidSyncTask(void *pvParameters)
|
||||
system_convert_array_steps_to_mpos(m_pos,current_position); // convert to millimeters
|
||||
calc_solenoid(m_pos[Z_AXIS]); // calculate kinematics and move the servos
|
||||
}
|
||||
vTaskDelayUntil(&xLastWakeTime, xSolenoidFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user