Created
February 20, 2024 06:06
-
-
Save jaggzh/552022494eff43cf2a3712931d315c4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void loop() { | |
| unsigned long cmicros = micros(); | |
| unsigned long cmillis = millis(); | |
| static unsigned long last_read = cmillis; | |
| static unsigned long last_print = cmillis; | |
| #define BB 300 | |
| unsigned long buf_us[BB+1]; | |
| float buf_v[BB+1]; | |
| float pbuf_v[BB+1]; | |
| float pbuf_slv[BB+1]; | |
| float buf_slv[BB+1]; | |
| #define TEST_TIMING_PULLUP | |
| #ifdef TEST_TIMING_PULLUP | |
| if (cmillis-last_read > 150) { | |
| cmicros = micros(); | |
| pinMode(IN1PIN, INPUT); | |
| for (int i=0; i<BB; i++) { | |
| buf_us[i] = micros(); | |
| buf_v[i] = analogRead(IN1PIN); | |
| delayMicroseconds(20); | |
| } | |
| #define CHOP BB/2 | |
| /* I'm leaving in this extra code in for other processing I was experimenting with. */ | |
| for (int i=0; i<CHOP; i++) { | |
| pbuf_v[i]=buf_v[i]; | |
| } | |
| for (int i=0; i<CHOP; i++) { | |
| pbuf_slv[i]=buf_slv[i]; | |
| } | |
| for (int i=1; i<CHOP; i++) | |
| pbuf_slv[i] = pbuf_slv[i] - (pbuf_slv[i-1]-buf_slv[i])/3; | |
| /* slowv = buf_v[0]; */ | |
| /* for (int i=0; i<BB/8; i++) { */ | |
| /* slowv = slowv + (buf_v[i]-slowv)/3; */ | |
| /* buf_slv[i]=slowv; */ | |
| /* } */ | |
| for (int i=0; i<CHOP; i+=4) { | |
| /* sp("us:"); spt(buf_us[i]-cmicros); */ | |
| sp("v:"); spt(1 * buf_v[i]); | |
| /* sp("slv:"); spt(buf_slv[i]); */ | |
| /* sp("dslv:"); spl(pbuf_slv[i]-pbuf_slv[i]); */ | |
| spl(""); | |
| } | |
| /* lastv = buf_v[BB-1]; */ | |
| /* for (int i=0; i<3; i++) { */ | |
| /* lastv += analogRead(IN1PIN); */ | |
| /* delayMicroseconds(1000); */ | |
| /* } */ | |
| pinMode(IN1PIN, OUTPUT); | |
| digitalWrite(IN1PIN, LOW); | |
| last_read = cmillis; | |
| return; | |
| smoothv = (float)smoothv + (float)(lastv-smoothv)/3; | |
| slowv = (float)slowv + (float)(lastv-slowv)/8; | |
| basev = (float)basev + (float)(lastv-basev)/98; | |
| last_read = cmillis; | |
| if (cmillis-last_print > 20) { | |
| /* sp("us:"); spt(cmillis-last_print); */ | |
| sp("v:"); spl(lastv-basev); | |
| /* sp("smv:"); spt(smoothv-basev); */ | |
| /* sp("slv:"); spl(slowv-basev); */ | |
| /* spl("Hit 0"); */ | |
| /* pinMode(IN1PIN, OUTPUT); */ | |
| /* digitalWrite(IN1PIN, LOW); */ | |
| last_print = cmillis; | |
| } | |
| } | |
| return; | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment