Skip to content

Commit

Permalink
itp feed based on itp frequency
Browse files Browse the repository at this point in the history
- itp feed based on itp frequency to optimize number of calls
  • Loading branch information
Paciente8159 committed Apr 30, 2024
1 parent df99668 commit 69b28a1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
42 changes: 21 additions & 21 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,8 @@ bool cnc_dotasks(void)
return false;
}

if (cnc_has_alarm())
{
return !cnc_get_exec_state(EXEC_KILL);
}

// µCNC already in error loop. No point in sending the alarms
if (cnc_state.loop_state >= LOOP_FAULT)
if (cnc_has_alarm() || (cnc_state.loop_state >= LOOP_FAULT))
{
return !cnc_get_exec_state(EXEC_KILL);
}
Expand Down Expand Up @@ -354,31 +349,36 @@ MCU_CALLBACK void mcu_rtc_cb(uint32_t millis)
uint8_t mls = (uint8_t)(0xff & millis);
if ((mls & CTRL_SCHED_CHECK_MASK) == CTRL_SCHED_CHECK_VAL)
{
if (!cnc_lock_itp)
{
cnc_lock_itp = 1;
#ifndef ENABLE_RT_PROBE_CHECKING
mcu_probe_changed_cb();
mcu_probe_changed_cb();
#endif
#ifndef ENABLE_RT_LIMITS_CHECKING
mcu_limits_changed_cb();
mcu_limits_changed_cb();
#endif
mcu_controls_changed_cb();
mcu_controls_changed_cb();
#if (DIN_ONCHANGE_MASK != 0 && ENCODERS < 1)
// extra call in case generic inputs are running with ISR disabled. Encoders need propper ISR to work.
mcu_inputs_changed_cb();
#endif
#ifdef ENABLE_ITP_FEED_TASK
if ((cnc_state.loop_state == LOOP_RUNNING) && (cnc_state.alarm == EXEC_ALARM_NOALARM) && !cnc_get_exec_state(EXEC_INTERLOCKING_FAIL))
{
itp_run();
}
// extra call in case generic inputs are running with ISR disabled. Encoders need propper ISR to work.
mcu_inputs_changed_cb();
#endif
}

cnc_lock_itp = 0;
#ifdef ENABLE_ITP_FEED_TASK
static uint8_t itp_feed_counter = (uint8_t)CLAMP(1, (1000 / INTERPOLATOR_FREQ), 255);
mls = itp_feed_counter;
if (!cnc_lock_itp && !mls--)
{
cnc_lock_itp = 1;
if ((cnc_state.loop_state == LOOP_RUNNING) && (cnc_state.alarm == EXEC_ALARM_NOALARM) && !cnc_get_exec_state(EXEC_INTERLOCKING_FAIL))
{
itp_run();
}
mls = (uint8_t)CLAMP(1, (1000 / INTERPOLATOR_FREQ), 255);
cnc_lock_itp = 0;
}

itp_feed_counter = mls;
#endif

#ifdef ENABLE_MAIN_LOOP_MODULES
if (!cnc_get_exec_state(EXEC_ALARM))
{
Expand Down
5 changes: 0 additions & 5 deletions uCNC/src/core/interpolator.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
#define INTERPOLATOR_BUFFER_SIZE 5 // number of windows in the buffer
#endif

// sets the sample frequency for the Riemann sum integral
#ifndef INTERPOLATOR_FREQ
#define INTERPOLATOR_FREQ 100
#endif

#define INTERPOLATOR_DELTA_T (1.0f / INTERPOLATOR_FREQ)
// determines the size of the maximum riemann sample that can be performed taking in acount the maximum allowable step rate
#define INTERPOLATOR_DELTA_CONST_T (MIN((1.0f / INTERPOLATOR_BUFFER_SIZE), ((float)(0xFFFF >> DSS_MAX_OVERSAMPLING) / (float)F_STEP_MAX)))
Expand Down
5 changes: 5 additions & 0 deletions uCNC/src/core/interpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ extern "C"
#define ITP_STEP_MODE_REALTIME 2
#define ITP_STEP_MODE_SYNC 4

// sets the sample frequency for the Riemann sum integral
#ifndef INTERPOLATOR_FREQ
#define INTERPOLATOR_FREQ 100
#endif

// contains data of the block being executed by the pulse routine
// this block has the necessary data to execute the Bresenham line algorithm
typedef struct itp_blk_
Expand Down

0 comments on commit 69b28a1

Please sign in to comment.