mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-02-06 02:02:34 +08:00
+or, and, threshold, autophase
This commit is contained in:
@@ -237,7 +237,7 @@ SYMBOL res 3824 0 R90
|
||||
WINDOW 0 0 56 VBottom 2
|
||||
WINDOW 3 32 56 VTop 2
|
||||
SYMATTR InstName R12
|
||||
SYMATTR Value 3.6k
|
||||
SYMATTR Value 3.9k
|
||||
SYMBOL res 2816 160 R0
|
||||
SYMATTR InstName R13
|
||||
SYMATTR Value 1.4k
|
||||
@@ -279,7 +279,7 @@ SYMATTR Value SINE(1 0.5 100000 0 0 180)
|
||||
SYMATTR SpiceLine Rser=1
|
||||
SYMBOL res 3440 64 R0
|
||||
SYMATTR InstName R21
|
||||
SYMATTR Value 500
|
||||
SYMATTR Value 470
|
||||
SYMBOL res 3632 48 R90
|
||||
WINDOW 0 0 56 VBottom 2
|
||||
WINDOW 3 32 56 VTop 2
|
||||
@@ -294,7 +294,7 @@ SYMBOL res 3200 208 R90
|
||||
WINDOW 0 0 56 VBottom 2
|
||||
WINDOW 3 32 56 VTop 2
|
||||
SYMATTR InstName R20
|
||||
SYMATTR Value 3.6k
|
||||
SYMATTR Value 3.9k
|
||||
SYMBOL cap 3616 80 R0
|
||||
SYMATTR InstName C9
|
||||
SYMATTR Value 1n
|
||||
|
||||
@@ -7,11 +7,11 @@ HAL_PIN(out) = 0.0;
|
||||
MEM(float avg) = 0.0;
|
||||
|
||||
RT_FILTER(
|
||||
float i = PIN(i);
|
||||
float i = PIN(in);
|
||||
float a = PIN(ac);
|
||||
|
||||
// avg
|
||||
avg = i * ac + avg * (1 - ac);
|
||||
avg = i * a + avg * (1 - a);
|
||||
|
||||
PIN(out) = i - avg;
|
||||
);
|
||||
|
||||
26
src/comps/and.comp
Normal file
26
src/comps/and.comp
Normal file
@@ -0,0 +1,26 @@
|
||||
COMP(and);
|
||||
|
||||
HAL_PIN(in0) = 0.0;
|
||||
HAL_PIN(in1) = 0.0;
|
||||
HAL_PIN(in2) = 0.0;
|
||||
HAL_PIN(in3) = 0.0;
|
||||
HAL_PIN(nin0) = 0.0;
|
||||
HAL_PIN(nin1) = 0.0;
|
||||
HAL_PIN(nin2) = 0.0;
|
||||
HAL_PIN(nin3) = 0.0;
|
||||
HAL_PIN(out) = 0.0;
|
||||
HAL_PIN(nout) = 1.0;
|
||||
|
||||
|
||||
RC(out,
|
||||
if(PIN(in0) > 0.0 && PIN(in1) > 0.0 && PIN(in2) > 0.0 && PIN(in3) > 0.0 && PIN(nin0) == 0.0 && PIN(nin1) == 0.0 && PIN(nin2) == 0.0 && PIN(nin3) == 0.0){
|
||||
PIN(out) = 1.0;
|
||||
PIN(nout) = 0.0;
|
||||
}
|
||||
else{
|
||||
PIN(out) = 0.0;
|
||||
PIN(nout) = 1.0;
|
||||
}
|
||||
);
|
||||
|
||||
ENDCOMP;
|
||||
141
src/comps/autophase.comp
Normal file
141
src/comps/autophase.comp
Normal file
@@ -0,0 +1,141 @@
|
||||
COMP(ac);
|
||||
|
||||
HAL_PIN(fb_in) = 0.0;
|
||||
HAL_PIN(pwm_in) = 0.0;
|
||||
HAL_PIN(pwm_out) = 0.0;
|
||||
HAL_PIN(mag_pos_in) = 0.0;
|
||||
HAL_PIN(mag_pos_out) = 0.0;
|
||||
HAL_PIN(fb_offset_in) = 0.0;
|
||||
HAL_PIN(fb_offset_out) = 0.0;
|
||||
HAL_PIN(start) = 0.0;
|
||||
HAL_PIN(ready) = 0.0;
|
||||
HAL_PIN(min_step) = 0.0;
|
||||
HAL_PIN(max_error) = 0.0;
|
||||
HAL_PIN(max_time) = 0.0;
|
||||
|
||||
MEM(int state) = 0;
|
||||
MEM(float fb_offset) = 0;
|
||||
MEM(int count) = 0;
|
||||
MEM(float time) = 0.0;
|
||||
MEM(float min_s) = 0.0;
|
||||
MEM(float max_e) = 0.0;
|
||||
MEM(float max_t) = 0.0;
|
||||
MEM(float pos) = 0.0;
|
||||
|
||||
|
||||
RT_CALC(
|
||||
float start_ = PIN(start);
|
||||
float ready_ = 0.0;
|
||||
float magp = 0.0;
|
||||
float pwm = 0.0;
|
||||
float fb = PIN(fb_in);
|
||||
float e = 0.0;
|
||||
|
||||
switch(state){
|
||||
case 0: // standby
|
||||
magp = PIN(mag_pos_in);
|
||||
pwm = PIN(pwm_in);
|
||||
if(start_ == 1.0){
|
||||
ready_ = 0.0;
|
||||
min_s = PIN(min_step);
|
||||
max_e = PIN(max_error);
|
||||
max_t = PIN(max_time);
|
||||
fb_offset = PIN(fb_offset_in);
|
||||
pos = fb;
|
||||
state = 1;
|
||||
count = 0;
|
||||
time = 0.0;
|
||||
}
|
||||
break;
|
||||
case 1: // out const pwm vec
|
||||
pwm = 1.0;
|
||||
|
||||
e = minus(fb, pos);
|
||||
time += period;
|
||||
|
||||
if(time >= max_t){
|
||||
if(count == 0){
|
||||
fb_offset += DEG(5);
|
||||
time = 0.0;
|
||||
}
|
||||
else{
|
||||
state = 2;
|
||||
pwm = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
if(ABS(e) >= min_s){
|
||||
count++;
|
||||
time = 0.0;
|
||||
if(e > 0.0){
|
||||
fb_offset += DEG(90) / count;
|
||||
}
|
||||
else{
|
||||
fb_offset -= DEG(90) / count;
|
||||
}
|
||||
}
|
||||
|
||||
if(DEG(90) / count <= max_e){
|
||||
state = 2;
|
||||
pwm = 0.0;
|
||||
}
|
||||
|
||||
magp = fb_offset;
|
||||
break;
|
||||
case 2: // running
|
||||
ready_ = 1.0;
|
||||
magp = PIN(mag_pos_in);
|
||||
pwm = PIN(pwm_in);
|
||||
if(start_ == 0.0){
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ready_ = 1.0;
|
||||
}
|
||||
|
||||
PIN(pwm_out) = pwm;
|
||||
PIN(mag_pos_out) = magp;
|
||||
PIN(ready) = ready_;
|
||||
PIN(fb_offset_out) = fb_offset;
|
||||
);
|
||||
|
||||
|
||||
ENDCOMP;
|
||||
|
||||
|
||||
/*
|
||||
gpio -> hal2offset -> autophase.offset_in
|
||||
|
||||
frt/rt/nrt comp:
|
||||
rt0.trg0 <= compxy.trg
|
||||
rt0.trg1 <= compxyz.trg
|
||||
...
|
||||
compxy.trg = laufzeit
|
||||
|
||||
stat comp:
|
||||
var, avg, min, max
|
||||
length
|
||||
|
||||
res comp:
|
||||
ready wenn avg stabil
|
||||
|
||||
|
||||
term:
|
||||
comp.* = alle comp pins
|
||||
*.pins = alle pins
|
||||
*.* = alles
|
||||
|
||||
*.* = 0.0 unlink
|
||||
*.enable = 1
|
||||
pid0.*
|
||||
...
|
||||
|
||||
menge = scalar
|
||||
menge
|
||||
|
||||
|
||||
scanf für regex
|
||||
bnf -> regex parser
|
||||
|
||||
*/
|
||||
26
src/comps/or.comp
Normal file
26
src/comps/or.comp
Normal file
@@ -0,0 +1,26 @@
|
||||
COMP(or);
|
||||
|
||||
HAL_PIN(in0) = 0.0;
|
||||
HAL_PIN(in1) = 0.0;
|
||||
HAL_PIN(in2) = 0.0;
|
||||
HAL_PIN(in3) = 0.0;
|
||||
HAL_PIN(nin0) = 0.0;
|
||||
HAL_PIN(nin1) = 0.0;
|
||||
HAL_PIN(nin2) = 0.0;
|
||||
HAL_PIN(nin3) = 0.0;
|
||||
HAL_PIN(out) = 0.0;
|
||||
HAL_PIN(nout) = 1.0;
|
||||
|
||||
|
||||
RC(out,
|
||||
if(PIN(in0) > 0.0 || PIN(in1) > 0.0 || PIN(in2) > 0.0 || PIN(in3) > 0.0 || PIN(nin0) == 0.0 || PIN(nin1) == 0.0 || PIN(nin2) == 0.0 || PIN(nin3) == 0.0){
|
||||
PIN(out) = 1.0;
|
||||
PIN(nout) = 0.0;
|
||||
}
|
||||
else{
|
||||
PIN(out) = 0.0;
|
||||
PIN(nout) = 1.0;
|
||||
}
|
||||
);
|
||||
|
||||
ENDCOMP;
|
||||
19
src/comps/threshold.comp
Normal file
19
src/comps/threshold.comp
Normal file
@@ -0,0 +1,19 @@
|
||||
COMP(threshold);
|
||||
|
||||
HAL_PIN(in) = 0.0;
|
||||
HAL_PIN(tre) = 0.0;
|
||||
HAL_PIN(out) = 0.0;
|
||||
HAL_PIN(nout) = 0.0;
|
||||
|
||||
RC(out,
|
||||
if(PIN(in) >= PIN(tre)){
|
||||
PIN(out) = 1.0;
|
||||
PIN(nout) = 0.0;
|
||||
}
|
||||
else{
|
||||
PIN(out) = 0.0;
|
||||
PIN(nout) = 1.0;
|
||||
}
|
||||
);
|
||||
|
||||
ENDCOMP;
|
||||
@@ -7,7 +7,7 @@ MEM(float data[100]);
|
||||
MEM(int pos) = 0;
|
||||
|
||||
RT_FILTER(
|
||||
float i = PIN(i);
|
||||
float i = PIN(in);
|
||||
float avg = 0.0;
|
||||
float o = 0.0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user