Simplify setting of STATE_CYCLE and ISR interval.
Set sys.state to STATE_CYCLE directly instead of calling back to st_wakeup(). Convert get_step_time() to a constant and rename it to ISR_INTERVAL.
This commit is contained in:
parent
783100db7d
commit
59e906f7e8
@ -29,6 +29,11 @@
|
|||||||
#include "../nuts_bolts.h"
|
#include "../nuts_bolts.h"
|
||||||
#include "simulator.h"
|
#include "simulator.h"
|
||||||
|
|
||||||
|
// Derived from OCR2A set during stepper init. Not simplified because
|
||||||
|
// OCR2A formula results in an unsigned int, which results in a slightly
|
||||||
|
// different value than simplifying to 1 / ISR_TICKS_PER_SECOND.
|
||||||
|
#define ISR_INTERVAL ((F_CPU/ISR_TICKS_PER_SECOND)/8) * 8.0 / F_CPU
|
||||||
|
|
||||||
// This variable is needed to determine if execute_runtime() is called in a loop
|
// This variable is needed to determine if execute_runtime() is called in a loop
|
||||||
// waiting for the buffer to empty, as in plan_synchronize()
|
// waiting for the buffer to empty, as in plan_synchronize()
|
||||||
// it is reset in serial_write() because this is certainly called at the end of
|
// it is reset in serial_write() because this is certainly called at the end of
|
||||||
@ -85,13 +90,15 @@ void sim_stepper() {
|
|||||||
// to let it handle sys.cycle_start etc.
|
// to let it handle sys.cycle_start etc.
|
||||||
if(current_block==NULL) {
|
if(current_block==NULL) {
|
||||||
interrupt_TIMER2_COMPA_vect();
|
interrupt_TIMER2_COMPA_vect();
|
||||||
sim_time+= get_step_time();
|
sim_time+= ISR_INTERVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sys.state = STATE_CYCLE;
|
||||||
|
|
||||||
while(current_block==plan_get_current_block()) {
|
while(current_block==plan_get_current_block()) {
|
||||||
interrupt_TIMER2_COMPA_vect();
|
interrupt_TIMER2_COMPA_vect();
|
||||||
sim_time+= get_step_time();
|
sim_time+= ISR_INTERVAL;
|
||||||
|
|
||||||
// Check to see if we should print some info
|
// Check to see if we should print some info
|
||||||
if(step_time>0.0) {
|
if(step_time>0.0) {
|
||||||
@ -108,6 +115,7 @@ void sim_stepper() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// always print stepper values at the end of a block
|
// always print stepper values at the end of a block
|
||||||
if(step_time>0.0) {
|
if(step_time>0.0) {
|
||||||
fprintf(step_out_file, "%20.15f, %d, %d, %d\n", sim_time, sys.position[X_AXIS], sys.position[Y_AXIS], sys.position[Z_AXIS]);
|
fprintf(step_out_file, "%20.15f, %d, %d, %d\n", sim_time, sys.position[X_AXIS], sys.position[Y_AXIS], sys.position[Z_AXIS]);
|
||||||
@ -171,12 +179,6 @@ void printBlock() {
|
|||||||
// Only when plan_synchronize() wait for the whole buffer to clear, the stepper interrupt
|
// Only when plan_synchronize() wait for the whole buffer to clear, the stepper interrupt
|
||||||
// to finish all pending moves.
|
// to finish all pending moves.
|
||||||
void handle_buffer() {
|
void handle_buffer() {
|
||||||
if (plan_check_full_buffer() && sys.state != STATE_CYCLE) {
|
|
||||||
// Autostart the cycle, and call st_wake_up()
|
|
||||||
sys.state = STATE_CYCLE;
|
|
||||||
st_wake_up();
|
|
||||||
}
|
|
||||||
|
|
||||||
// runtime_second_call is reset by serial_write() after every command.
|
// runtime_second_call is reset by serial_write() after every command.
|
||||||
// Only when execute_runtime() is called repeatedly by plan_synchronize()
|
// Only when execute_runtime() is called repeatedly by plan_synchronize()
|
||||||
// runtime_second_call will be incremented above 2
|
// runtime_second_call will be incremented above 2
|
||||||
@ -189,37 +191,3 @@ void handle_buffer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_step_time() {
|
|
||||||
/* code for the old stepper algorithm
|
|
||||||
uint16_t ceiling;
|
|
||||||
uint16_t prescaler;
|
|
||||||
uint32_t actual_cycles;
|
|
||||||
uint8_t invalid_prescaler= 0;
|
|
||||||
|
|
||||||
prescaler= ((TCCR1B>>CS10) & 0x07) - 1;
|
|
||||||
ceiling= OCR1A;
|
|
||||||
|
|
||||||
switch(prescaler) {
|
|
||||||
case 0:
|
|
||||||
actual_cycles= ceiling;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
actual_cycles= ceiling * 8L;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
actual_cycles = ceiling * 64L;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
actual_cycles = ceiling * 256L;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
actual_cycles = ceiling * 1024L;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
invalid_prescaler= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(invalid_prescaler) return 12345.0;
|
|
||||||
else return (double)actual_cycles/F_CPU;*/
|
|
||||||
return (double)((ocr2a+1)*8)/(double)(F_CPU);
|
|
||||||
}
|
|
||||||
|
@ -51,10 +51,4 @@ void handle_buffer();
|
|||||||
// Print information about the most recently inserted block
|
// Print information about the most recently inserted block
|
||||||
void printBlock();
|
void printBlock();
|
||||||
|
|
||||||
// Calculate the time between stepper interrupt calls from TCCR1B and OCR1A AVR registers
|
|
||||||
// which are set in config_step_timer in stepper.c
|
|
||||||
// This reconstructs the stepper-internal value of variable st.cycles_per_step_event
|
|
||||||
// The reconstruction is done to truely decouple the simulator from the actual grbl code
|
|
||||||
double get_step_time();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user