All Activityhttps://www.microforum.cc/discover/microforum.cc - All ActivityenWhat every embedded programmer should know about ADC measurementYes that is correct.Thu, 20 Feb 2020 22:39:18 +0000PIC32MZ Random Software ResetI am glad to provide some ideas. Let us know what you find. Learning from others is generally cheaper and less painful than learning from my own mistakes.Wed, 19 Feb 2020 20:14:12 +0000Declarative programming with minizincI think the C libraries can make linear optimization problems much easier to solve in a system. But they are a general purpose solution intended for the general class of optimization problems. There is a good chance that the code you wrote was far simpler and sufficiently optimal for the task at hand due to task specific optimizations.
This story is often the case for embedded systems. A general purpose solution is nice and easy but too big/slow for an embedded microcontroller. As the microcontrollers get larger/faster for low costs then these generic or more complete solutions become available. Interestingly this does not always create a "better" performing solution but it often produces a more reliable, faster to market solution by leveraging more widely developed software that has more hours of operation/debugging on it.Wed, 19 Feb 2020 20:13:03 +0000PIC32MZ Random Software ResetThanks N9WXU. That helps. I know where to look now.Wed, 19 Feb 2020 16:15:03 +0000What every embedded programmer should know about ADC measurementThis is great, thanks for summing that up!
So if I wanted to calculate the number of bits that are lost from your example above:
Source impedance = 100k; LSb Error = 5LSb; log(5)/log(2) = 2.32
This means that the last 2.32 bits are lost and my ENOB = 9.68?Tue, 18 Feb 2020 19:14:33 +0000Declarative programming with minizincI used to do a fair amount of optimization using linear programming, it was a bit of a pain to code up so I had hoped this would make that easier ...Tue, 18 Feb 2020 17:45:54 +0000Declarative programming with minizincThis tool does three things.
Solve the problem
helps you learn to think declaratively
Helps you develop constraints.
To add code to your project, look at the google OR-Tools. In those tools you will provide constraints and data sets. The tools will then do the solving. I would expect some solutions to take quite a bit of CPU time.
Currently I am taking basic modeling in discrete optimization in Coursera to learn more about this topic. Training my mind to describe a problem instead of solving it is actually quite hard.Mon, 17 Feb 2020 03:37:02 +0000PIC32MZ Random Software ResetProvided nothing went wrong in your analysis that bit being set means that somewhere something did a software reset, you just have to figure out where this happened. N9WXU gave some possible causes of the RESET instruction being used, but it could really be anywhere. I have even seen this happen with a bad function pointer jumping to a location which contained const data.
As a last resort you can search through the program memory for the RESET instruction (you can do this in MPLAB using the memory views) and set a breakpoint at every location containing the reset instruction. That way you should be able to catch it in the debugger and figure out where the reset is coming from.Sun, 16 Feb 2020 21:00:01 +0000Declarative programming with minizincThis is really cool! Can this tool generate C code that I can use in my applications or does it just solve the problem for me?Sun, 16 Feb 2020 20:53:36 +0000What every embedded programmer should know about ADC measurementGlad you found it helpful JG2018,
Let me try and answer your questions.
This part is just math and the magic of logarithms. The important identity here is that logx(y) = log10(x)/log10(y), and we know that log2(x) will give us how many bits we need to represent x, but our calculators do not do log2 instead they do log10 , which means we have to take log10(x) / log10(2) to get the number of bits we need to represent the number.
The short answer is yes because the leakage contributes to a measurement error, and we measure the ADC error as a proportion of LSB size as we described above.
How the leakage contributes is a lot more involved and depends on the construction of the ADC and the methods it uses for sampling. Section 7 above shows the simplified circuit diagram of the ADC input path and you can see where Microchip places the leakage current specified in the datasheet. If you calculate the network currents when this circuit is attached to your circuit under measurement you can determine how much of an effect the leakage will have to your measurements.
If the source impedance is small the bulk of the current you feed into the pin will end up going into the sampling capacitor and the leakage will have a small effect, but of course the higher your source impedance is the lower the current into the sampling capacitor and the more of an effect the leakage current will have.
We can use the PIC18F47K40 example above since the leakage current is indicated in the simplified diagram in section 7 above.
If we have 10k of source impedance and we have an additional 1k of internal impedance on the ADC charge path we have at 3V approx 272uA charging the capacitor. The pin leakage is specified at max to be 125nA, which means that 125nA/272uA is the proportion of the charge current lost to our measurement. In this example it contributes 0.0459% error. For a 10-bit ADC this would mean roughly 0.45 LSB of error (calculated as 0.0459% of the full range which is 2^10).
That explains the comment in the device datasheet that if your source impedance is more than 10k this will result in an additional error of more than 0.5 LSB which means it will start contributing to your measurement error.
To see how this turns into a larger error we can do the same math with a source impedance of 100k instead. This divides the current by 10 and consequently increases the error to 4.59 LSB of error. This means you can still take the measurements but you will potentially have almost 5 LSB of additional error to contend with. And you cannot calibrate out the leakage as it varies with voltage and temperature and the spec already has it varying from 5nA to 125nA depending on these parameters and also the process variation.Sun, 16 Feb 2020 20:50:33 +0000What every embedded programmer should know about ADC measurementHello, the information in this post is by far one of the best I've seen for ADCs! Thank you for passing this information along to others!
I have a few questions I hope you could answer..
1. How did you get the equation to calculate the fractional number of bits [Log(# LSb error)/Log(2)]?
2. For a high impedance input, does the voltage offset due to leakage current contribute to the LSb error?
Thanks!Thu, 13 Feb 2020 20:13:10 +0000Declarative programming with minizincI am doing some work with combinatorial optimizers. It is amazing what happens when you turn over one more rock and see what scurries out.
There is a whole class of programming called declarative programming and I have worked with Haskel enough to be slightly familiar with the concepts. I just learned about flat zinc and an easier environment called MiniZinc which are completely declarative and can be used to solve optimization problems by describing the constraints a valid solution fits inside.
So here is a quick example of a program to find the smallest area rectangle where the area is 10 times the circumference.
var 1..1000: side1;
var 1..1000: side2;
var float: area;
var float: circumference;
constraint area = side1 * side2;
constraint circumference = 2 * side1 + 2 * side2;
constraint area = 10*circumference;
solve minimize area;
output ["side1 = \(side1)\nside2 = \(side2)\narea = \(area)\ncircumference = \(circumference)\n"];
and here is the output showing every iteration.
side1 = 420
side2 = 21
area = 8820.0
circumference = 882.0
----------
side1 = 220
side2 = 22
area = 4840.0
circumference = 484.0
----------
side1 = 120
side2 = 24
area = 2880.0
circumference = 288.0
----------
side1 = 100
side2 = 25
area = 2500.0
circumference = 250.0
----------
side1 = 70
side2 = 28
area = 1960.0
circumference = 196.0
----------
side1 = 60
side2 = 30
area = 1800.0
circumference = 180.0
----------
side1 = 45
side2 = 36
area = 1620.0
circumference = 162.0
----------
side1 = 40
side2 = 40
area = 1600.0
circumference = 160.0
----------
==========
Finished in 82msec
Obviously this is a trivial example but it turns out there is quite a bit of research and libraries in this field. For example the google OR-Tools which could be incorporated in your C code. If you need to optimize something and you can describe what the answer looks like (the constraints) then these tools are pretty good. Of course these problems are NP-Complete, so solutions can take some time.
Good Luck.Wed, 12 Feb 2020 13:48:45 +0000PIC32MZ Random Software ResetI have not used harmony or web net server so I have not run into this directly. But there may be a few other places to check that cause resets on other systems.
Often the assert() functions will end in a software reset, so your code may not call the reset directly, but if you use assert in your error checks you will reset
Some malloc libraries will fail with a reset if there is a heap failure.i.e. the stack runs into the heap. This is often detected with a no-mans land between the stack and the heap. The no-mans land is filled with a magic number. If the magic number changed, the stack ran into the no-mans land and may have corrupted the heap.Wed, 12 Feb 2020 13:32:01 +0000PIC32MZ Random Software ResetI'm seeing some random resets with the PIC32MZ1024EFE100 running the Web Net Server project from Harmony 2.06. The RCON register is 0x00000040 which is the SWR (Software Reset Flag) bit.
I'm thinking there is a bug in my code but the SYS_RESET_SoftwareReset() function is not being called.
What else would cause the SWR bit to be set?
Has anyone experienced a simmilar problem?
-DevinTue, 11 Feb 2020 01:12:36 +0000Comparing raw pin toggling speed between Arduino platforms.Hey, I just noticed that there are some over-clock options.
Here is the result when clocked at 960MHz. I could not get it to run at 1GHz. They did warn that cooling was required.Mon, 20 Jan 2020 00:40:00 +0000Comparing raw pin toggling speed between Arduino platforms.More Data!
I just got a Teensy 4 and it is pretty fast.
Compiling it in "fastest" and 600Mhz provides the following results.
Strangely compiling it in "faster" provides the slightly better results. (6ns)
This is pretty fast but I was expecting a bit more performance since it is 6x faster than the Teensy 3.2 tested before.
There is undoubtedly a good reason for this performance, and I expect pin toggling to be limited by wait states in writing to the GPIO peripherals. In any case this is still a fast result.Mon, 20 Jan 2020 00:35:23 +0000Initializing Strings in CLooks like it gave the segfault upon running? And yes that is what I would expect because on a PC your code is trying to write to memory which should not permit writes. On an embedded system the behavior will depend a lot on the underlying system. Some systems will actually crash in some way, others, like XC8 based PIC microcontrollers, actually copy the read-only section into RAM so the code will actually work. This is why this is so dangerous, the behavior depends on the target and the toolchain and when this is one day tried on another system it could be a real challenge to figure out the mistake because it is so easily masked.Sat, 04 Jan 2020 21:42:49 +0000Initializing Strings in CThanks for pointing out the mistake, we have updated the text accordingly.Sat, 04 Jan 2020 21:39:56 +0000Initializing Strings in Cstring1[3] = 'a';
This gave a segmentation fault on compilationSat, 04 Jan 2020 09:03:27 +0000Initializing Strings in CIt is also permissible to do this:
string1[3] = 'a';
Which will change the original string into "striag1".
I believe the original string will change to "strang1"Sat, 04 Jan 2020 08:30:07 +0000How to struct - lessons on Structures in C@zakaster - I have posted a more comprehensive answer to the blog here https://www.microforum.cc/blogs/entry/49-a-question-about-structures-strings-and-pointers/Thu, 02 Jan 2020 20:59:21 +0000A question about structures, strings and pointershttps://www.microforum.cc/blogs/entry/49-a-question-about-structures-strings-and-pointers/Wed, 01 Jan 2020 07:24:00 +0000How to struct - lessons on Structures in CTue, 31 Dec 2019 05:23:37 +0000How to struct - lessons on Structures in Csorry i used a duplicated name, for example if i input another name,
input new name for person:hello
address of new_name = 000000000061FD90
p name = hello
address of dummy = 000000000061FDE0
p name = helloMon, 30 Dec 2019 11:11:41 +0000How to struct - lessons on Structures in CMon, 30 Dec 2019 11:03:35 +0000