|
|
View previous topic :: View next topic |
Author |
Message |
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Mon Mar 24, 2014 5:47 am |
|
|
At page 98 from datasheet is specified the 10K maximum input impedance:
http://ww1.microchip.com/downloads/en/DeviceDoc/41585A.pdf
But I can work with the specs from page 184, even without the additional 0.01uF capacitor.
I can do Spice simulation with different programs, but makes no sense for different reasons related with the past experiences.
I have a better approach: the real live circuit with errors spread due to components tolerances, AD of the PIC, mains change, worse case when all are combined. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9271 Location: Greensville,Ontario
|
|
Posted: Mon Mar 24, 2014 6:20 am |
|
|
I've always used the 'real world' for testing as NO simulator can really 'simulate' what's 'out there'!
If possible, I suggest hooking up 10 of your products to the same source and record the data for say a week or two, the longer the better. While it may seem excessive, several years ago, my remote energy control system was 'hit' by a 'noise' problem. It turned out to be crosstalk on the dataline of a bank uploading data between 1Am-2Am on every Sunday night!
There isn't ANY simulator that would have created that problem!
The more data you can acquire with timestamps, the better.
hth
jay |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Mon Mar 24, 2014 6:45 am |
|
|
That is exactly my experience.
Actually I already have done that for more than 20 samples and the error is fine. I will do it in future from time to time for maybe 100, because I do not know if the AD from PIC is stable in the acceptable error when I do not really respect the rules...
In few months we go for full speed with over 20000 products, then I will see the spread very clear for different PIC batch.
Based on experience, I also know that in a big batch of components, the tolerances are very close one to another, therefore we will buy a bigger quantity each time and later is important to check from time to time these different batches.
For who is interested here are few more links with the mains utility frequency in real time in 2 more European countries. The 1st one seems official:
https://www.swissgrid.ch/content/swissgrid/de/home/experts/topics/frequency.html
http://www.dynamicdemand.co.uk/grid.htm
http://www.gridwatch.templar.co.uk/ |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Mon Mar 24, 2014 8:32 am |
|
|
Coming back to the code, I have an additional question.
To generate some oscillations I use the simple code below:
Code: | for ( i = 0 ; i < 100; i++ ) {
output_high(PIN_A0);
delay_us(30);
output_low(PIN_A0);
delay_us(70);
} |
Is it any other code suggestion which takes less ROM (flash) memory, as for instance set-up the PWM or any of the additional Core Independent Peripherals (CLC, NCO...)?
I see for example TB3071:
http://ww1.microchip.com/downloads/en/AppNotes/93071A.pdf |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Mar 24, 2014 5:23 pm |
|
|
the NCO is simpler to program but the choices of duty cycle may bring you no joy. since all i see is a snippet to go by - i have no idea how you would integrate nco control with your main code . |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Tue Mar 25, 2014 1:08 am |
|
|
I tested the idea of choosing the median value after the array is sorted in ascendant order instead of average of middle values.
In my case, the error is always within acceptable limits, but the spread of the end result is higher when we choose the median.
When I choose the average, then there is a higher probability to obtain the same end result. The spread of the error is narrow.
You may choose what you think is better for your application, but my conclusion is to use average as in the initial olympic code written by "asmboy", if that is possible for you.
As for my application, I will try to use the average and also to increase the number of samples to 16 as in the original code.
I will sample the sinus at 3ms and also at 7ms.
I will use 9 bit array instead of 16, because I do not need to sample the signal very fast, but one time at each few ms.
I realized that I can afford the average and the 16 samples, because I can get rid of other subroutines inside the PIC. For example, in order to know precisely the AD result I use bit-banging to serialize the AD samples. That I use only during tests and is not needed for the end program.
I found bit-banging the best method to "see" what the PIC measures.
Using oscilloscope, digital multimeter and probes is hopeless when we work with high-impedance circuits. I tried differential probes and only 50-60M impedance did not affect the circuit and impedance. Unfortunately my differential probes have such high-impedance only for high-voltage range, which does not help to read 1V with high-precision. Instead of investing in better probes or additional high impedance circuits for measuring the low signal with good precision, I found faster and cheaper the bit-banging method.
Regarding the code above, you may consider it independent, as stand-alone, single code in a new main PIC program. |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Mar 29, 2014 3:44 am |
|
|
I've not followed most of your ramblings for choice of components, ADC system etc.
I do not propose to struggle any further so am giving up on that issue.
However, I think it's reasonable to show you a different way to measure RMS values.
The method:-
1) Does not need rectifiers, or a zero cross detector. (So fewer components.)
2) Requires mimimal RAM. (Good for a small PIC.)
The input to the ADC looks like this:- Code: |
RAW AC -----WWWWW------------- PIC ADC Input
|
|
Vref -----WWWWW-----|
|
|
0V GND -----WWWWW----- | Choose resistors so that:-
1) When AC is zero, ADC input is at ~half Vref.
2) Extreme AC voltages give ADC input close to 0V and Vref.
For example take this sequence of values 0,1,2,3,4,5,6,7,9,10 to prove the calculation method.
If these were your readings, you want the RMS value of the deviation from the mean reading.
The conventional (obvious) way to get the RMS value goes like this.
a) Calculate the mean value by adding all the values and dividing by the number of values.
b) Calculate the difference between each value and the mean.
c) Square each difference.
d) Sum all the squares.
e) Calculate the mean square.
d) Take root of mean sqaure. (i.e. the RMS value you want.)
Do the above on the sample values, see what you get.
The problems with this method using a small PIC:-
1) It's a two pass process.
2) You need to store ALL the values in an array.
Now try this:-
A) Create 'sum_of_values' and 'sum_of_squares' variables, reset both to zero.
B) Take each value (as it comes in) add it to 'sum_of_values'.
C) Take each value (as it comes in) square it and add to 'sum_of_squares'.
When you have done that for all the values:-
D) Calculate mean as sum_of_values / number_of_values. (As before)
E) Calculate magic_number = (sum_of_squares - number_of_values * mean ^ 2) / number_of_values
F) Calculate square root of magic_number.
How does square root of magic_number compare to RMS value you got before?
In your case the readings you require are a taken at equally spaced intervals over an integral number of complete mains cycles.
You can model in Excel to determine what should work best for you.
(The readings need to be spread out over the whole of a cycle or several cycles.)
Mike |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Sat Mar 29, 2014 9:31 am |
|
|
Mike,
Thank you so much for the effort in writing all the details.
The rectifiers are not there special for AD. They have another purpose, for another part of the circuit. The AD of the PIC is only a secondary function. Not to mention that are special rectifiers..., in fact everything is a bit special in my circuit, sometimes discussed and developed with the manufacturer engineers, because we use properties of the semiconductors which you will not find in the datasheet.
Somebody proposed Spice. Forget about simulation programs. not that I did not try for several weeks having parameters from semiconductor factory, but is useless for my case.
In a comment earlier you mentioned that you cannot understand how come I cannot use lower impedance than 10M for the AD voltage divider, when for example the other branch of the Zener diode is lower impedance. The branch with Zener is not even providing 5V stabilized voltage for PIC. It is used more like a protection in case of overlarge. But there is a second main function, helping a resonant circuit.
Of course everything can be designed better with few more components, but are some restrictions, I would say many, regarding the circuit, components, PCB and so on. I cannot do what I want, what I would like to do from engineering point of view, functionality and performance.
There are some limitations which forbids development as an engineer would like to do it. Makes no sense to enter into details. Any time I would make my circuit 10 times better if and if and if... certain constrains will not stop me.
With all these limits, I am confident in the design and the product will have 10 years warranty. In fact I am convinced will have a longer than 10 years lifetime.
We have similar products, pure analog, since more than 20 years. We offer 10 years warranty at the analog version and they have longer lifetime.
The present design is only a digital version, in which the AD function is not critical, but may impact a bit the performance parameters. We eliminated the electrolytic capacitors present in the analog version and the circuit was tested in harsh conditions. For the moment the product is tested for the 3rd party test house which will provide the necessary certificates for CE. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19590
|
|
Posted: Sat Mar 29, 2014 9:59 am |
|
|
I suggested modelling the behaviour inside the PIC, using your input circuit.
You may be terrified by just how unlike the incoming signal, the voltage on the cap inside will be (all the data needed for this is in the PIC data sheet), and just how fast the voltage is rising, right at the point where you are sampling, when using 3mSec after the zero point. A change of just a couple of uSec in this timing, gives a dozen counts. Hence my suggestion to sample nearer the peak of the waveform.
Do it, and prepare to see exactly why sampling at this point gives problems... |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Sat Mar 29, 2014 1:55 pm |
|
|
Supposing I understand right your suggestion, if you look on the page 3 of the present topic where I shared the zero-crossing influence Excel file, there is a calculation with what happens around 3ms point:
- measurement tolerance of +/- 10us gives 0 digital error for me.
- measurement tolerance of +/-100us gives +/-1 digit error for me. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Mar 30, 2014 2:22 pm |
|
|
We're living on different planets. I give up.
Mike |
|
|
viki2000
Joined: 08 May 2013 Posts: 233
|
|
Posted: Sun Mar 30, 2014 2:37 pm |
|
|
I am afraid you are right Mike.
My application is not a classical instrumentation measurement.
In fact I asked only help for a piece of code and the olympic code is good for that.
Then a lot of people offered to advise me about the hardware improvement, even I did not ask about it. Still I am thankful for thoughts and suggestions, even if they were not really necessary.
There are nice people around here which make me feel welcome in a friendly enviroment. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Fri May 02, 2014 1:12 pm |
|
|
Mike Walne wrote: | The conventional (obvious) way to get the RMS value goes like this.
a) Calculate the mean value by adding all the values and dividing by the number of values.
b) Calculate the difference between each value and the mean.
c) Square each difference.
d) Sum all the squares.
e) Calculate the mean square.
d) Take root of mean sqaure. (i.e. the RMS value you want.)
Do the above on the sample values, see what you get.
The problems with this method using a small PIC:-
1) It's a two pass process.
2) You need to store ALL the values in an array.
Now try this:-
A) Create 'sum_of_values' and 'sum_of_squares' variables, reset both to zero.
B) Take each value (as it comes in) add it to 'sum_of_values'.
C) Take each value (as it comes in) square it and add to 'sum_of_squares'.
When you have done that for all the values:-
D) Calculate mean as sum_of_values / number_of_values. (As before)
E) Calculate magic_number = (sum_of_squares - number_of_values * mean ^ 2) / number_of_values
F) Calculate square root of magic_number.
How does square root of magic_number compare to RMS value you got before? |
It should be noted that this method only works if the waveform is bipolar. For unipolar waveforms it completely falls apart.
I say this because it struck me as being more efficient than my current (conventional) method of computing RMS values, but the waveforms I'm dealing with are always positive or always negative. I threw together a spreadsheet to test, and with noisy sine waves it works very well. For noisy sine waves with DC offsets, it doesn't work. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Fri May 02, 2014 1:45 pm |
|
|
Is it possible to add/subtract an offset to make them bipolar prior to implementing the algorithm? You'd have to look at how the offset propagates through the calculation, but it might be easy to undo at the end. I haven't taken the time to see if that would work mind you. Just tossing up an idea in case you really did want to use that method. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|