Hi all. Has anyone done any work on sampling a 50Hz signal such as an ouput from a CT to capture the peak voltage? Also, if i use an interrupt to capture this, how many separate interrupts can i use that won't affect the performance of the circuit? I already use one interrupt and IOC. Is there a limit?
PIC16f18877 (if you have been following my posts you'll figure out I'm trying to buld a resonably accurate energy monitor)
N
Optimal frequency to capture a 50Hz peak signal
-
- Posts: 254
- http://meble-kuchenne.info.pl
- Joined: Tue Jul 13, 2021 1:53 pm
- Has thanked: 33 times
- Been thanked: 23 times
-
- Matrix Staff
- Posts: 1760
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 447 times
- Been thanked: 607 times
Re: Optimal frequency to capture a 50Hz peak signal
Hello,
Yes there will be a limit, it all boils down to how long you spend inside each interrupt and the frequency of your microcontroller. Ideally you want to be in and out as quickly as possible and also clocking the micro as fast as possible.
Theoretically a sample rate of at least 12X the max frequency of a signal would allow you to fairly nicely approximation of a signal. So anything you can do above this will give you more accurate peak detection at a cost of smaller accuracy gains.
Maybe aim for 12X (12 x 50Hz = 600Hz which is very acheivable) and then try and push it harder and harder until your main program is starting to become sluggish, i.e. you're spending most of the CPU runtime inside the interrupt macros. Then you can back off again knowing what the real limit is and making a nice balance between sampling and processing.
For our electrical machines range there was a definite point where the comms commands as part of the main loop would start to fail due to the high interrupt driven sample rate which gave me a really nicely defined maximum allowable throughput.
As a further improvement you can implement a nice averaging filter, maybe a combination of a median and a mean.
Yes there will be a limit, it all boils down to how long you spend inside each interrupt and the frequency of your microcontroller. Ideally you want to be in and out as quickly as possible and also clocking the micro as fast as possible.
Theoretically a sample rate of at least 12X the max frequency of a signal would allow you to fairly nicely approximation of a signal. So anything you can do above this will give you more accurate peak detection at a cost of smaller accuracy gains.
Maybe aim for 12X (12 x 50Hz = 600Hz which is very acheivable) and then try and push it harder and harder until your main program is starting to become sluggish, i.e. you're spending most of the CPU runtime inside the interrupt macros. Then you can back off again knowing what the real limit is and making a nice balance between sampling and processing.
For our electrical machines range there was a definite point where the comms commands as part of the main loop would start to fail due to the high interrupt driven sample rate which gave me a really nicely defined maximum allowable throughput.
As a further improvement you can implement a nice averaging filter, maybe a combination of a median and a mean.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Valued Contributor
- Posts: 185
- Joined: Wed Jan 13, 2021 7:15 pm
- Has thanked: 81 times
- Been thanked: 30 times
Re: Optimal frequency to capture a 50Hz peak signal
Hi Wingnut
The output is current that is in relation to the ratio i.e 100:1 so at 100 Amps Primary current you would get 1 Amp in the secondary
Please note, open circuit CT's can have a very high open circuit voltage, and this condition can stress the insulation and cause them to fail.
CT's should always have a load connected to them.
Steve
Just read your post, the output from a CT is not a voltage unless you have a special CT that dose this for you, or a Hall Sensor Type device
The output is current that is in relation to the ratio i.e 100:1 so at 100 Amps Primary current you would get 1 Amp in the secondary
Please note, open circuit CT's can have a very high open circuit voltage, and this condition can stress the insulation and cause them to fail.
CT's should always have a load connected to them.
Martin has also done one on the app developer page, that might give you some ideas
Steve
Re: Optimal frequency to capture a 50Hz peak signal
Thanks Steve. Yeah Im familiar with transformer theory. The ct im using has a 10 ohm load resistor connected across the terminals. I'm trying to figure out the most accurate way of sampling the waveform presented to the analogue input of the micro. I currently have 3 different methods non inverting op amp, differential op amp and voltage divider (resistor network). They currently produce vwery different results but until I can get the sampling right I won't have a stable input on any of them.
I'll take a look for Martins
Thanks again
I'll take a look for Martins
Thanks again
-
- Valued Contributor
- Posts: 185
- Joined: Wed Jan 13, 2021 7:15 pm
- Has thanked: 81 times
- Been thanked: 30 times
Re: Optimal frequency to capture a 50Hz peak signal
Hi Wing Nut,
Martins is here
viewtopic.php?f=9&t=513
&
https://www.flowcode.co.uk/app-developer/free-apps/
Steve
Martins is here
viewtopic.php?f=9&t=513
&
https://www.flowcode.co.uk/app-developer/free-apps/
Steve
Re: Optimal frequency to capture a 50Hz peak signal
Hi Steve. Yes thats interesting. I had to purchase 2 more modules - app developer and comms c to examine that correctly . But the work is being done by a third party device and i want to do it all on as small a circuit as possible and on a PIC micro so I'll park app developer for a bit but i do plan to use wireless comms for a future project with similar features
-
- Matrix Staff
- Posts: 1467
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 516 times
- Been thanked: 474 times
Re: Optimal frequency to capture a 50Hz peak signal
Thanks, Steve for posting the link.
WingNut, all you need is a tiny micro e.g PIC12F1840, the Power monitor PZEM-004T and if you want a display, use an I2C or SPI version.
E.g 20x4 LCD with I2C backpack.
It does not have to be used with App developer, but it's great for monitoring.
For example, the data can be logged within a CSV file showing AC voltage, current power, power factor, frequency etc.
I have been using the ESP32 to send all the data to the internet, so I can access the data from my mobile, live from all over the world. This is using a Raspberry pi as a broker.
The only thing is there has been an update with the latest PI operating system to make it more difficult to do.
WingNut, all you need is a tiny micro e.g PIC12F1840, the Power monitor PZEM-004T and if you want a display, use an I2C or SPI version.
E.g 20x4 LCD with I2C backpack.
It does not have to be used with App developer, but it's great for monitoring.
For example, the data can be logged within a CSV file showing AC voltage, current power, power factor, frequency etc.
I have been using the ESP32 to send all the data to the internet, so I can access the data from my mobile, live from all over the world. This is using a Raspberry pi as a broker.
The only thing is there has been an update with the latest PI operating system to make it more difficult to do.
Martin
-
- Matrix Staff
- Posts: 1467
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 516 times
- Been thanked: 474 times
Re: Optimal frequency to capture a 50Hz peak signal
No, I don't believe it is as true RMS will not be required to measure low impedance AC mains.
However I do have a true RMS meter and when compared the mains voltage, there was 0% difference in the readings
However I do have a true RMS meter and when compared the mains voltage, there was 0% difference in the readings
Martin