Deconvolution measurement of rotational speed with embedded OLED display

  Рет қаралды 240

T.J Moir

T.J Moir

7 ай бұрын

Same as the deconvolution video previously but instead of using the serial port to display speed I am using the Adafruit SSD1306 0.96-inch 128×64 I2C OLED display instead. (I2C version).

Пікірлер: 4
@johnsim3722
@johnsim3722 7 ай бұрын
I'm trying to remember where I had to do something that had to use the instantaneous values for control, but I did a smoothing of the values and only output via serial every so often. The serial data needed to be slower simply because of the data rate so I had to decimate the data going out. Thankfully in that situation you're not having to use the main processor to output individual bits as you load up the registers of the serial port and let it deal with it after that. Often with code I try and write it in a style that I call "drop through". That is, nothing will block the code execution from top to bottom and repeating. A lot of functions I turn in to state machines and the main code is checking what state and if it needs to move to the next state, service that state and drop through the code to repeat the next time round. Sometimes there's counters in there too so that it doesn't just go straight in to the next state but has to wait, effectively a time out before executing the next part. Handy for de-bouncing I/Os. In this case I might have the loop for doing the control of the motor looping but a state machine to work through the digits for display, with the I2C output of the micro being updated with new data each time. Of course it is very dependant upon the implementation of the I2C module inside the micro. With the serial interface you'd have one byte being sent out with another then being loaded ready to go next. Looping through you could check if it was ready for a new byte rather than waiting.
@TJMoir
@TJMoir 7 ай бұрын
That's some very good advice John. You are well skilled in the black arts of micros for sure! In this particular case if you're just measuring speed as an open loop transducer the sampling rate need not be very high in any case since the speed is constant. If it's with a control loop though that's the problem though we don't need to know the exact speed to feed it back (only a signal proportional to speed) so a display isn't that necessary anyway. The problem with displaying only say 1 10th reading might be that the sampling rate must be uniform and no glitches even now and then for a display. I think National instruments had the best solution (though expensive) with they FPGA and real time processor design (Rio). It had a RTOS of course which is a better solution. All sorts of tricks like direct memory access, shared memory, FIFOs etc to speed things up. Certainly state machines were also on the list. For most hobbyists though speed isn't a major issue with micros as they are on the whole just switching things and much speed control is open loop. I think you need to start your own tutorials on micros online John since you have at least 30 years of design experience.
@johnsim3722
@johnsim3722 7 ай бұрын
@@TJMoir I did apply for a job teaching microcontrollers at Paisley Uni, but they took on a less experienced guy instead.
@TJMoir
@TJMoir 7 ай бұрын
Code is here ----------------------------------------------------------------------------------------------------------------------------- //Deconvolution filter to get rotational speed from rotational digital position //Adafruit SSD1306 0.96-inch 128×64 I2C OLED display to show speed gives bandwidth of 16Hz only volatile int counter = 0; //Quadrature encoder: change these numbers as required #define outputA 35 #define outputB 32 // For Display #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for SSD1306 display connected using I2C #define OLED_RESET -1 // Reset pin #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); /* Vcc is 3.3v SCL is pin 22 SDA is pin 21 Also needs ground pin */ // for sampling freq measurement on scope int sample_pin = 27; float d1, b0, b1, z0, z1, u0, u1, yout; // d is spectral factor coefficient from polynomial void IRAM_ATTR isr_quadencoder() { // quadrature encoder if (digitalRead(outputA) == digitalRead(outputB)) { //Clockwise counter++; } else { //Counter Clockwise counter--; } } boolean running = false; void setup() { d1 = -0.0839; b0 = 0.8392; b1 = -b0; z0 = 0.0; z1 = 0.0; u0 = 0.0; u1 = 0.0; // Serial port for debugging purposes Serial.begin(115200); // initialize the OLED object if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Clear the display buffer. display.clearDisplay(); pinMode(outputA, INPUT); //Encoder input A pinMode(outputB, INPUT); //Encoder input B pinMode(sample_pin, OUTPUT); //Sampling freq measure with scope attachInterrupt(outputA, isr_quadencoder, FALLING); // end setup procedure } //while loop void loop() { // Deconvolution filter z1 = z0; u1 = u0; u0 = counter; //z0=0.0839*z1+0.8392*u0-0.8392*u1; z0 = -d1 * z1 + b0 * u0 + b1 * u1; yout = 100 * z0; /* Serial.print(6000); Serial.print(", "); Serial.print(-6000); Serial.print(", "); Serial.println(yout); */ // Display display.setTextColor(WHITE); // text display.setCursor(0,0); display.setTextSize(2); display.println("Speed(RPM)"); display.setTextSize(3); display.setCursor(0,30); display.println(int(yout)); display.display(); display.clearDisplay(); // Need a time delay delay(4); digitalWrite(sample_pin, running); running = !running; // end of while loop } ---------------------------------------------------------------------------------------------------------------------------------
FPGA Function Generator - Four Waveforms and Variable Frequency
0:32
WLED & ESP32: The Dynamic Duo of DIY LED Projects
26:24
Makers Mashup
Рет қаралды 199 М.
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 35 МЛН
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 8 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 17 МЛН
I hacked Raspberry Pi firmware for the World Record Overclock!
8:19
Jeff Geerling
Рет қаралды 144 М.
Building a $2,000,000 machine in 2 months
46:07
Breaking Taps
Рет қаралды 109 М.
The Clever Way to Count Tanks - Numberphile
16:45
Numberphile
Рет қаралды 273 М.
Can I use an ESC with a bigger amp rating with my motor?
6:18
Painless360
Рет қаралды 33 М.
OLED Displays with Arduino - I2C & SPI OLEDs
41:41
DroneBot Workshop
Рет қаралды 1,1 МЛН
This Is NASA's New Space Station...And It Just Exploded...Again!
10:29
The Space Race
Рет қаралды 108 М.
DIY sonar scanner (practical experiments)
14:30
bitluni
Рет қаралды 1 МЛН
Brushless Motor - How they work BLDC ESC PWM
16:12
The Engineering Mindset
Рет қаралды 4,4 МЛН
Real time Kalman filter on an ESP32 and sensor fusion.
23:40
T.J Moir
Рет қаралды 12 М.
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 35 МЛН