Updates to encoder
This commit is contained in:
@@ -28,13 +28,14 @@ uint32_t CurPosScale = 1;
|
|||||||
uint8_t OldLatchCEnable = 0;
|
uint8_t OldLatchCEnable = 0;
|
||||||
volatile uint8_t indexPulseFired = 0;
|
volatile uint8_t indexPulseFired = 0;
|
||||||
uint32_t nFires = 0;
|
uint32_t nFires = 0;
|
||||||
volatile uint8_t pleaseZeroTheCounter=0;
|
volatile uint8_t pleaseZeroTheCounter = 0;
|
||||||
|
uint32_t PrevTime = 0, Prev2Time = 0;
|
||||||
|
|
||||||
void cb_set_outputs(void) // Master outputs gets here, slave inputs, first operation
|
void cb_set_outputs(void) // Master outputs gets here, slave inputs, first operation
|
||||||
{
|
{
|
||||||
if (Obj.IndexLatchEnable && !OldLatchCEnable) // Should only happen first time IndexCEnable is set
|
if (Obj.IndexLatchEnable && !OldLatchCEnable) // Should only happen first time IndexCEnable is set
|
||||||
{
|
{
|
||||||
pleaseZeroTheCounter=1;
|
pleaseZeroTheCounter = 1;
|
||||||
}
|
}
|
||||||
OldLatchCEnable = Obj.IndexLatchEnable;
|
OldLatchCEnable = Obj.IndexLatchEnable;
|
||||||
|
|
||||||
@@ -55,7 +56,10 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
|||||||
nFires++;
|
nFires++;
|
||||||
PreviousEncoderCounterValue = 0;
|
PreviousEncoderCounterValue = 0;
|
||||||
}
|
}
|
||||||
Obj.DiffT = nFires;
|
uint64_t now = micros();
|
||||||
|
Obj.DiffT = now - Prev2Time;
|
||||||
|
Prev2Time = PrevTime;
|
||||||
|
PrevTime = now;
|
||||||
|
|
||||||
int64_t pos = unwrap_encoder(TIM2->CNT, &PreviousEncoderCounterValue);
|
int64_t pos = unwrap_encoder(TIM2->CNT, &PreviousEncoderCounterValue);
|
||||||
double CurPos = pos * PosScaleRes;
|
double CurPos = pos * PosScaleRes;
|
||||||
@@ -63,8 +67,8 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
|||||||
|
|
||||||
double diffT = 0;
|
double diffT = 0;
|
||||||
double diffPos = 0;
|
double diffPos = 0;
|
||||||
TDelta.push(ESCvar.Time); // Too bad resolution to measure over 1 ms. The length of the circular buffers
|
TDelta.push(ESCvar.Time); // Running average over the length of the circular buffer
|
||||||
Pos.push(CurPos); // tells over how long time the position is measured.
|
Pos.push(CurPos);
|
||||||
if (Pos.size() >= 2)
|
if (Pos.size() >= 2)
|
||||||
{
|
{
|
||||||
diffT = 1.0e-9 * (TDelta.last() - TDelta.first()); // Time is in nanoseconds
|
diffT = 1.0e-9 * (TDelta.last() - TDelta.first()); // Time is in nanoseconds
|
||||||
@@ -80,7 +84,6 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
|||||||
nFires++;
|
nFires++;
|
||||||
PreviousEncoderCounterValue = 0;
|
PreviousEncoderCounterValue = 0;
|
||||||
}
|
}
|
||||||
Obj.DiffT = nFires;
|
|
||||||
Obj.IndexByte = digitalRead(INDEX_PIN);
|
Obj.IndexByte = digitalRead(INDEX_PIN);
|
||||||
if (Obj.IndexByte)
|
if (Obj.IndexByte)
|
||||||
Serial1.printf("IS 1\n");
|
Serial1.printf("IS 1\n");
|
||||||
|
|||||||
@@ -97,10 +97,10 @@ net z-drv-target-velo cia402.1.drv-target-velocity => lcec.0.5.target-veloci
|
|||||||
setp iocontrol.0.emc-enable-in 1
|
setp iocontrol.0.emc-enable-in 1
|
||||||
#net estop iocontrol.0.emc-enable-in lcec.0.1.din-0
|
#net estop iocontrol.0.emc-enable-in lcec.0.1.din-0
|
||||||
|
|
||||||
#setp lcec.0.3.enc-pos-scale [SPINDLE_9]ENCODER_SCALE
|
setp lcec.0.3.enc-pos-scale [SPINDLE_9]ENCODER_SCALE
|
||||||
setp lcec.0.6.enc-pos-scale [SPINDLE_9]ENCODER_SCALE
|
setp lcec.0.6.enc-pos-scale [SPINDLE_9]ENCODER_SCALE
|
||||||
|
|
||||||
#net spindle-revs <= lcec.0.3.enc-pos
|
net spindle-revs <= lcec.0.3.enc-pos
|
||||||
net spindle-revs <= lcec.0.6.enc-position
|
net spindle-revs <= lcec.0.6.enc-position
|
||||||
loadrt invert
|
loadrt invert
|
||||||
loadrt mult2 names=mult2.rps,mult2.rpm
|
loadrt mult2 names=mult2.rps,mult2.rpm
|
||||||
@@ -112,10 +112,10 @@ setp invert.0.in [SPINDLE_9]ENCODER_SCALE
|
|||||||
setp mult2.rpm.in0 -60.0
|
setp mult2.rpm.in0 -60.0
|
||||||
setp mult2.rpm.in0 60.0
|
setp mult2.rpm.in0 60.0
|
||||||
#net enc-invert-pos-scale mult2.rps.in0 <= invert.0.out
|
#net enc-invert-pos-scale mult2.rps.in0 <= invert.0.out
|
||||||
#net enc-get-freq-rps mult2.rps.in1 <= lcec.0.3.enc-frequency
|
net enc-get-freq-rps mult2.rps.in1 <= lcec.0.3.enc-frequency
|
||||||
#net spindle-vel-fb-rps mult2.rpm.in1 <= mult2.rps.out
|
#net spindle-vel-fb-rps mult2.rpm.in1 <= mult2.rps.out
|
||||||
#net spindle-vel-fb-rpm mult2.rpm.out
|
#net spindle-vel-fb-rpm mult2.rpm.out
|
||||||
#net spindle-index-enable lcec.0.3.enc-index-c-enable
|
net spindle-index-enable lcec.0.3.enc-index-c-enable
|
||||||
|
|
||||||
net spindle-vel-fb-rps mult2.rpm.in1 <= lcec.0.6.enc-frequency
|
net spindle-vel-fb-rps mult2.rpm.in1 <= lcec.0.6.enc-frequency
|
||||||
net spindle-vel-fb-rpm mult2.rpm.out
|
net spindle-vel-fb-rpm mult2.rpm.out
|
||||||
|
|||||||
@@ -7,16 +7,6 @@ function _;
|
|||||||
license "GPL";
|
license "GPL";
|
||||||
;;
|
;;
|
||||||
|
|
||||||
// general pin set true function
|
|
||||||
void set(hal_bit_t *p){
|
|
||||||
*p = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// general pin set false function
|
|
||||||
void unset(hal_bit_t *p){
|
|
||||||
*p = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//main function
|
//main function
|
||||||
FUNCTION(_) {
|
FUNCTION(_) {
|
||||||
index_latch_enable = index_c_enable;
|
index_latch_enable = index_c_enable;
|
||||||
|
|||||||
Reference in New Issue
Block a user