Hello everyone.
I have created a frequency output delay formula from scratch.
I told the Arduino IDE to output a PWM signal from 0 to 500KHz using a STM32 microcontroller.
As you go up higher in frequency the output delay time on the microcontroller output gets higher. For instance if you request 500 KHz you get a delay time and the actual output is 380 KHz etc...
I have attached a picture of my oscilloscope data readings on an Excel graph with a formula to predict this delay time.
This formula matches the output data response from the (real world) oscilloscope readings virtually exactly.
Yes I know my math skills are not the best on the planet in fact I know they are my worst area so I thought I would reach out to get others to double check my formula.
Orange line is oscilloscope readings reading the delay in output.
Green Line is the delay time prediction formula.
Jason ;
This is actually more complicated than that since I would go about it a little differently.
Now there are even more detailed questions but this is the approach that I would use to get started. Just using math functions for a MCU *will NOT* get you accuracy even with some of the best compilers.
Also there are inherent frequency accuracy considerations by just choosing the crystal.
Furthermore there is nothing in stone that says you cannot change out the crystal on the Arduino board for better accuracy.
And if the design on the PCB layout is noisy by EMI or other pickup then everything can be in vain.
Some if this can be looked at on a scope, but probing a crystal will load it down and cause an amplitude and phase shift as well as a minor frequency shift.
Better designs use oscillators for this reason, not crystals and Temperature Compensated (TX-XO) or Oven Controlled (OC-XO) crystal oscillators are stable over frequency with a specific accuracy tolerance.
Hello
Xentec Jason
Your Problem isn’t by the math skills. I think that the Arduino IDE have to much software ballast for easy programming with c. That’s why your PWM are to slow by higher frequency. Change to another c-programmer (maybe GCC) and your STM32 program works.
Yes, I agree.
Unless you are using some form of RTOS its difficult to know exactly what your timing is in regard to clock cycles of the oscillator.
Being able to step thru the code and see where your timing is at is another factor in getting accurate performance.
Also if you are looking for critical timing, then it is best not to use an MCU but rather a FPGA would be better with nanosecond timing control and you can control everything at the logic level.
Oh, also stay away from CPLDs as they are a deprecated technology and are headed for obsolescence. Besides small FPGAs are much less expensive and more powerful and may be packaged much smaller.
Hello Steven,
I should clarify my position on this subject. This is simply a math exercise only. I am currently back to basics studying and reviewing all my foundation electronics skills. I stumbled over this early project from years ago. This was one of my first ever manufactured PCB projects. As a result I abandoned the project realizing my design errors. All these years later looking back I would never even consider going down this design path. I actually facepalm shaking my head laughing thinking back at this. I thought for that early version of myself I would solve the delay time math problem I had back then just as part of my daily study time.
I actually keep this early project and use it from time to time.
It was a prototype project programmable dual PWM output driver.
We all had to start somewhere right ?
Hello Tomasini,
I should clarify my position on this subject. This is simply a math exercise only. I am currently back to basics studying and reviewing all my foundation electronics skills. I stumbled over this early project from years ago. This was one of my first ever manufactured PCB projects. As a result I abandoned the project realizing my design errors. All these years later looking back I would never even consider going down this design path. I actually facepalm shaking my head laughing thinking back at this. I thought for that early version of myself I would solve the delay time math problem I had back then just as part of my daily study time.
I actually keep this early project and use it from time to time.
It was a prototype project programmable dual PWM output driver.
We all had to start somewhere right ?
Jason ;
Okay, now I have context !
Yes, for this dual MOSFET IGBT driver, I would have never gone down this path as well since many power switching issues that SMPS ASICs resolve with tightly coupled sub-circuits to avoid feedback loops and other EMI issues.
But as I mentioned (not for this project) that the considerations for timing start from your clock circuitry and crystal characteristics. This is a tricky analog / RF (LF in your case) problem that has many subtle factors including A/D quantization and scaling factors based upon the clock synthesis circuits within the MCU.
Achieving reliable and very accurate timing for RTOS systems is the foundation to which everything else is dependent on, so this why chapters in the datasheets and other application notes are devoted to this subject.
Anyway have fun, but it seems like given what it is, there's much better ways to use your time exploring many other the really cool SMPS chips out there. A few years ago I came across a transformers-less fly back SMPS ASIC from one of the power conversion leaders and this is worth investigating.
Hello Steven,
This project was my very early days of learning electronics. It brings back some memories.
Yes there is no question. There are much better and much faster ways of doing this. Just off the top of my head I can think of a multiple ways of getting around design issues like this now, however I wouldn't have the heart to upgrade this after all this time as it is a reminder of the journey.
Just an update to the microcontroller frequency decline delay time formula if anyone ever needs it in future.
You might also want to consider a logistic growth which is more realistic, especially when dealing with batteries or charge https://en.wikipedia.org/wiki/Exponential_growth
Hello Steven,
Many thanks. This is the exact kind of thing I have been looking for regarding this subject. Sometimes It is really difficult to find the answers you need because you just don't know how to ask the right question.
I have bookmarked the page for future study.
At the moment I am getting a little overwhelmed with constant study time and the number of different areas I need to work on. Electronics, C++, GUI interfaces, personal projects ect...
I have got a new Amscope microscope on the way so I will have to take a little time off to rearrange the lab and take a breath.
https://www.amazon.co.uk/gp/product/B01H4FOLVM/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1
If you don't receive the email within an hour (and you've checked your Spam folder), email us as confirmation@grabcad.com.