#frequency monitoring

1 messages · Page 1 of 1 (latest)

wanton tangle
#

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?

fervent narwhal
# wanton tangle COuld you describe what you're doing in more detail? Are you monitoring mains po...

"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:

  1. 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.
  2. 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.
  3. 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.

wanton tangle
#

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

fervent narwhal
#

exaclty

#

But i need to know how to detect the zero crossing.

#

ohh

#

I understand you

#

no

wanton tangle
#

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

fervent narwhal
#

I need the all values to know what is the values on that cycle, if has any problem

wanton tangle
#

because it might NOT be sinuisoidal if something is going wrong?

fervent narwhal
#

will be sinuisoidal, but can have pics/harmonics where is possible to etect what kind is the equpaments using that energy from power generator

wanton tangle
#

because 8ms sampling is only going to give you a little info

fervent narwhal
#

resistive/capacitive and so on

wanton tangle
#

if 50Hz, then zero crossings are at 100Hz, so 10ms per zero crossing

fervent narwhal
#

8.33 is semi cycle from 60HZ, so that is enouch

#

8.33ms

wanton tangle
#

is this 50 or 60 Hz mains?

fervent narwhal
#

a complete wanve iin 60HZ has 16,66ms

#

main is 60

wanton tangle
#

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

fervent narwhal
#

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

wanton tangle
#

well, not necessarily, you might be clipping only in the positive cycle

fervent narwhal
#

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?

wanton tangle
#

what about the 120Hz aliasing issue?

fervent narwhal
fervent narwhal
wanton tangle
#

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

fervent narwhal
#

ohh, sure, the first think to do is to detect the zero crossing

#

with that i know the frequency

wanton tangle
#

how fast do you want to detect a frequency change? immediately or after n cycles?

fervent narwhal
#

in each cycle

#

in each zero crossing

wanton tangle
#

what data are you sending over wifi?

#

is this basically a wifi oscilloscope?

fervent narwhal
#

frequency and is is detected someting wrong. but over wifi can be just each 10ms

wanton tangle
#

and what is the wifi receiver going to do?

#

just log it?

fervent narwhal
fervent narwhal
wanton tangle
#

and it has to be wifi, as opposed to say, USB to a host computer?

fervent narwhal
#

need to be wifi becaouse client want to monitor when are installing power generator

#

puting it to operate

wanton tangle
#

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

fervent narwhal
#

I'm already doing 100ms between ESP and APP.

#

it is fine

#

i'm using json-rpc

#

over socket

wanton tangle
#

how busy is the ESP when that is happening?

fervent narwhal
#

my problem is how to detect in smart way the zero crossing

fervent narwhal
#

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?

wanton tangle
#

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?

fervent narwhal
#

both

#

if works, I can to sell it 🙂

#

if not, just to study

wanton tangle
#

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

fervent narwhal
#

your solution for get the zero crossing is putting a hardware interrupt on zero crossing?

wanton tangle
#

if you want to detect it in one cycle, yes

#

but see that repo for a technique

fervent narwhal
#

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)

wanton tangle
#

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

fervent narwhal
#

no

#

i get many samples in 8.33

#

around 400 samples each 8.33ms

wanton tangle
#

well, if the input levels are known, then zero crossing is just a level comparison

fervent narwhal
#

yes, but no perfect, not precise

#

i would like to know if are there a smart way to have better that

wanton tangle
#

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

fervent narwhal
#

problem that if 00 is the zero crosing, never has just ONE 100

#

hasve around 5 or 8 100

#

see?

#

example

wanton tangle
#

well, you need a window of samples, and need to look backwards

fervent narwhal
#

200, 160, 130, 100, 100, 100, 100, 150, 130, 180

wanton tangle
#

or your ADC is not accurate enough

fervent narwhal
#

100 is zero crossing, but what?

#

12 bits

#

adc 12 bits

wanton tangle
#

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)

fervent narwhal
#

yes, that 100 was just a example, following your example about 100

wanton tangle
#

but with a sinusoid, I would expect to see a clean crossing: 108, 102, 96, 90, etc

fervent narwhal
#

me too

#

but that ADC do not show that, in that precission

#

is always zero crossign the lower number, repeat around 5 times

wanton tangle
#

the ESP ADC is not very good

fervent narwhal
#

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

wanton tangle
#

that is not a zero, why is it not going below 80?

#

that is a minimum

fervent narwhal
#

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

wanton tangle
#

but if 10 is "zero", why is it not going below 10?

fervent narwhal
#

may be i need more samples than 400 per 8,33ms

wanton tangle
#

it sounds like you have the wrong ground reference

fervent narwhal
#

hmm

wanton tangle
#

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

fervent narwhal
#

Ohh, wave are desclocated to not have negative values

#

just positive

wanton tangle
#

what is the input circuitry now?

fervent narwhal
#

input is AC from network energy

wanton tangle
#

but you have to bias it, how do you bias it?

fervent narwhal
#

0 -4096, where 0 crossing is half that 4086, becaouse wave was deslocated to not hasve negative values

wanton tangle
#

so 2048 is the zero crossing

fervent narwhal
wanton tangle
#

what is "deslocated"?

fervent narwhal
#

if i get another ahardware where has negative and positive, the problem is the same

fervent narwhal
wanton tangle
#

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

fervent narwhal
#

i not sure about that, how the circuit is done, sorry

wanton tangle
#

did someone else do the circuit? It sounds like the circuit is wrong

fervent narwhal
#

not, just that

wanton tangle
#

the low point is not the zero crossing, it is the most negative, it sounds like

fervent narwhal
#

get AC, pass do a divier to send to ADC 0 to 3.3v

#

*divisor

wanton tangle
#

do you have a schematic?

fervent narwhal
#

not, sorry 😦

wanton tangle
#

either something is wrong with the circuit, or you are measuring the most negative voltage, not the zero crossing

fervent narwhal
#

i think there a confusion about wave is deslocatd to positive

#

never will have negative vlues on adc

#

that is understood for you?

wanton tangle
#

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

fervent narwhal
#

yes

#

exacty

wanton tangle
#

so there is both a multiplicative and a additive bias

fervent narwhal
#

so a good example, is that zero crossing is 1.65, right?

wanton tangle
#

right, so suppose 1.65V is 2048, then I would expect to see values below 2048 and values above 2048

fervent narwhal
#

yes

#

so

#

what happen is this:

#

2090, 2070, 2050, 2050, 2050, 2080, 2100

#

that is not perfectnumbers

wanton tangle
#

that indicates to me that the circuitry is wrong

fervent narwhal
#

but the zero crossing the lower number repeat some times

#

hmmm

fervent narwhal
#

well, good to know

wanton tangle
#

it has to go below 2050 to measure voltages below 0v

fervent narwhal
#

2048?

wanton tangle
#

or 2048

#

but the point is you're throwing away half your range

fervent narwhal
#

or, maybe it goes to 2048, but 400 sampels pwe 8.33 was no capable to get the 2048

wanton tangle
#

I think it is the coupling circuitry. Did you design it?

fervent narwhal
#

no

#

i get it ready

wanton tangle
#

did you build it?

fervent narwhal
#

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

wanton tangle
#

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

fervent narwhal
#

yes, i see that is 0 to 65535, so will be 32767,5 when wil lbe zero crossing

wanton tangle
#

yes, and maybe it's not completely centered, who knows how the circuit is

#

the EE person needs to talk to you about this

fervent narwhal
#

but wiht a scope genrating the sinoidal wave i need to get 32767,5 right on zero crossing?

fervent narwhal
wanton tangle
#

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

fervent narwhal
#

ok

wanton tangle
#

ok, I need to sleep, sri

fervent narwhal
#

ok

#

hey

#

thank you so much for your time

#

you help me so much

#

thank you!!!!

wanton tangle
#

yw!