#frequency monitoring
1 messages · Page 1 of 1 (latest)
COuld you describe what you're doing in more detail? Are you monitoring mains power to make sure it stays at 50Hz or 60Hz? Is it always sinusoidal? Why do you want values in between the zero-crossings?
"COuld you describe what you're doing in more detail?"
Yes, sure.
I'm just doing a intermediary equipament that is a requiriment for another. It need:
- To capture many samples on the semi cycle (negative or positive). So with zero crossing detected, I know when start to read from ADC (first zero crossing), and when stop (second zero crossing) and so on.
- With that many samples I will to do a Calc for each semi cycle, and will send to that another equipament via UART or CAN - send via Wifi will be a PLUS.
- As if is possible to detect the zero crossing, I can to calc what is the exactly frequency, and send this value to that another equipament too.
"Are you monitoring mains power to make sure it stays at 50Hz or 60Hz?"
Both, but when running on 50 or 60Hz, it can go (somethins) until ~80HZ.
"Is it always sinusoidal? Why do you want values in between the zero-crossings?"
Yes, Always sinusoidal, because is AC, not CC.
if it's always sinusoidal, then would the zero crossings not be all you need? between any two zeros is half of a sinusoidal cycle
exaclty
But i need to know how to detect the zero crossing.
ohh
I understand you
no
so all you need is zero crossings. So you can use a Schmitt trigger or similar to square up the waveforms and detect rising or falling edges
I need the all values to know what is the values on that cycle, if has any problem
because it might NOT be sinuisoidal if something is going wrong?
will be sinuisoidal, but can have pics/harmonics where is possible to etect what kind is the equpaments using that energy from power generator
because 8ms sampling is only going to give you a little info
resistive/capacitive and so on
if 50Hz, then zero crossings are at 100Hz, so 10ms per zero crossing
is this 50 or 60 Hz mains?
right, so if there are spikes between zero and peak, you will not see them
or if you sample at 8.33, you will not be synchronized with the zero crossings.
if for instance, it went to 120Hz, you would not know that, unless you detected zeros separately
well, if are spikes in negative semi cycle for example, and I reading in positive semi cycle,, that problem will be repetead in the next positive semi cycle, that I will get
well, not necessarily, you might be clipping only in the positive cycle
well, in general that not happen, but for this is possible just to alternate to get some times in positive and some times in negative
see?
what about the 120Hz aliasing issue?
yes, if i detect zero cross in smart way, all that ill be better
sorry, why 120HZ?
if you don't count zero-crossings explicitly, then your sampling might miss a change from 60Hz to 120Hz, because the sampling frequency is too slow (I am just giving an example of what happens when you sample too slowly)
Nyquist and all that
you will not see harmonics, etc
ohh, sure, the first think to do is to detect the zero crossing
with that i know the frequency
how fast do you want to detect a frequency change? immediately or after n cycles?
frequency and is is detected someting wrong. but over wifi can be just each 10ms
no, because is 100ms, but over uart/can need to be in each semi cycle
show in real time in a APP and save too
and it has to be wifi, as opposed to say, USB to a host computer?
need to be wifi becaouse client want to monitor when are installing power generator
puting it to operate
HTTP 100ms hammering on a webserver is a little intense. You may want to use a websocket and keep the connection open, or use UDP
I'm already doing 100ms between ESP and APP.
it is fine
i'm using json-rpc
over socket
how busy is the ESP when that is happening?
my problem is how to detect in smart way the zero crossing
i not checked
but i tryed until each 30ms and was fine
but i do not need more speed than 100ms
Do you have a smart way example to detect the zero crossing?
i am not sure CircuitPython or MicroPython is the right choice for this. You may want to do it in C instead, to guarantee timings. You can square up the waveforms like I said and then toggle a pin and get an interrupt on that pin, and check the time. And there are peripherals on ESP32 to help, e.g. https://github.com/DavidAntliff/esp32-freqcount
is this commercial or a student project?
C would be more suitable for the strict real-time requirements you have, I believe. if you use two ESP's, yes, perhaps one could be Python
but if you are looking for narrow spikes, you really need a much higher sampling rate
the signal could be 60 Hz but still very noisy or distorted
your solution for get the zero crossing is putting a hardware interrupt on zero crossing?
but i already doing this without interruption, using while true and analizing each dat, as i told you before
what i would like to know if are there a smart way, but using just osftware
yes, with hardwware i can to use a operational and get irq pin on each semi cycle ero crossing
but actually to detect zero crossing is not precise, of course,. because that i would like to know if are there a sart way (in sofware)
if you are just looking at ADC values and only sampling at 8.33 ms, then you can't do precise zero-finding
the information is just not htere
well, if the input levels are known, then zero crossing is just a level comparison
yes, but no perfect, not precise
i would like to know if are there a smart way to have better that
i don't think so, because between two samples you have no information. you can only interpolate
e.g. if 100 is the zero crossing point, then if value at time i is >100, and at time i+delta is < 100, then you can figure out at what fration of delta the zero was crossed
but that assumes a smooth crossing
problem that if 00 is the zero crosing, never has just ONE 100
hasve around 5 or 8 100
see?
example
well, you need a window of samples, and need to look backwards
200, 160, 130, 100, 100, 100, 100, 150, 130, 180
or your ADC is not accurate enough
i would not expect to see that flatness. I meant the value would go below 100. so if 12 bit, you bias it so zero is in the middle of 4096, at 2048,
so 0 is the most negative and 4095 is the most positive (or leave some margin)
yes, that 100 was just a example, following your example about 100
but with a sinusoid, I would expect to see a clean crossing: 108, 102, 96, 90, etc
me too
but that ADC do not show that, in that precission
is always zero crossign the lower number, repeat around 5 times
the ESP ADC is not very good
108, 102, 96, 90, 80, 80, 80, 80, 90, 100, 120
I tested with RP2040 too, the same
same results
it is 12 bits too
ohh, was just a example, sorry
in a real example
near this:
40, 30, 10, 10, 10, 10, 20, 30, 50
or 30, 10, 4, 4, 4, 7, 10, 20
but if 10 is "zero", why is it not going below 10?
may be i need more samples than 400 per 8,33ms
it sounds like you have the wrong ground reference
hmm
0 should be the most negative voltage, 4095 or so should be the most positive, and 2048 should be in the middle, as "zero"
except you should narrow it to allow for spikes
what is the input circuitry now?
input is AC from network energy
right, but 0 on the ADC, should be -120V in real life
but you have to bias it, how do you bias it?
0 -4096, where 0 crossing is half that 4086, becaouse wave was deslocated to not hasve negative values
so 2048 is the zero crossing
i do not know, in a ready hardware that i get. but that is not important for this case, becuse wave is just deslocated
what is "deslocated"?
if i get another ahardware where has negative and positive, the problem is the same
is have just 4096 positive
you have to bias it electrically before it gets to the pin
like AC-coupling through a capacitor to the middle of a voltage divider
i not sure about that, how the circuit is done, sorry
did someone else do the circuit? It sounds like the circuit is wrong
not, just that
the low point is not the zero crossing, it is the most negative, it sounds like
do you have a schematic?
not, sorry 😦
either something is wrong with the circuit, or you are measuring the most negative voltage, not the zero crossing
i think there a confusion about wave is deslocatd to positive
never will have negative vlues on adc
that is understood for you?
I understand that, but you are measuring -120V to 120V, and scaling that to 0-3.3V, so 1.65V corresponds to the 0v on the input
so there is both a multiplicative and a additive bias
so a good example, is that zero crossing is 1.65, right?
right, so suppose 1.65V is 2048, then I would expect to see values below 2048 and values above 2048
yes
so
what happen is this:
2090, 2070, 2050, 2050, 2050, 2080, 2100
that is not perfectnumbers
that indicates to me that the circuitry is wrong
really?
well, good to know
it has to go below 2050 to measure voltages below 0v
2048?
or, maybe it goes to 2048, but 400 sampels pwe 8.33 was no capable to get the 2048
I think it is the coupling circuitry. Did you design it?
did you build it?
not, the hardware person that want this equiapment as requiriment to that another give me
and i started working on it
but i know how to check
I will use a scipe (option function generator) and send a real sinoida wave fto check
if the python get 2048, problem is the hardware
right?
*scope
if it goes no lower than 2048, something is wrong. I would expect to see complete excursions between 0-4095. In CircuitPython, we actually scale it to 0-65535.
but actually, the designer would have made it not go to the extremes, because you want to be able to detect voltages >120v and < -120V
so say 120V is 40000, 0v is 30000, and -120V is 20000
please talk to your EE person about this
yes, i see that is 0 to 65535, so will be 32767,5 when wil lbe zero crossing
yes, and maybe it's not completely centered, who knows how the circuit is
the EE person needs to talk to you about this
but wiht a scope genrating the sinoidal wave i need to get 32767,5 right on zero crossing?
ok
it can be done with two voltage dividers (each are two reisstors), and a capacitor in between, but for safety and linearity, there may be more circuitry, like an op-amp
and if you are measuring line voltage, there definitely needs to be safety circuitry
ok
yw!