News:

Let's find out together what makes a PIC Tick!

Main Menu

Zero cross detection

Started by Ivano, Dec 04, 2022, 07:41 PM

Previous topic - Next topic

Ivano

Good evening,
i'm testing the ZCD zero cross detection with a 18F25k83 pic and i ran into a problem.
The program works and uses the interrupt generated by the zero crossing of a 100Hz triangular wave. The interrupt generates a 2 mS pulse on two pins of the pic one on portB.1 and one on portB.2,
the triangular wave input is on portB.0 as per datasheet.
The output on B.2 works very well while B.1 gives a very dirty, indecipherable signal, it seems to be in conflict with the interrupt.
Note that the anomaly occurs only on port B.1 while using any other pin everything works fine.
Even B.1 outside the interrupt works fine, there are no anomalous signals, there is no appreciable capacitance between the tracks on the pcb.
I think it's a hardware problem inside the pic.
Can anyone explain?
I enclose the program and two screens of the waveforms
Thank you

Pepe

Your program works well on pic 16f8856

tumbleweed

Does it make a difference if you change the led symbols from PORTB to LATB?
'Symbol Led = PORTB.1
'Symbol Led_1 = PORTB.2
Symbol Led = LATB.1
Symbol Led_1 = LATB.2

Ivano

With LATB.1 and LATB.2 things have improved in the sense that even in B.1 the impulse is seen, the problem is that in both outputs there is a double impulse as per the attached images.
There must be some interference between the B.0 input and the nearby output because as you bring your hand closer you see the correct pulse. everything works fine on B.2 if I remove the wire connected to B.1.
Probably the wires used for the connections pick up spurious signals that are interpreted by the pic.
Perhaps a low-pass filter makes all the difference.
However, using a pin away from the input no problem.
Thanks for the info everyone.

tumbleweed

What's the actual voltage on the PORTB.0 pin?

It also might be a good idea to set B.0 to analog mode.

Pepe

I could lower the input impedance of portb.0 by adding a 1k resistor to ground

Ivano

Internally, B.0 is connected to an operational amplifier which by default drives the OUT output of the ZCDCON register high when the waveform exceeds 0.75 volts.
In the datasheet there are the formulas to calculate the resistance in series between the source and B.0 based on the voltage of the signal and the input current which must be between 100 and 600 microamperes max.
With 6 volt source a 22 Kohm series R the voltage on B.0 is very small, I don't remember how much.
In the datasheet there is also a formula to calculate the resistance to lower the threshold voltage down to 0 volts.
I put a 150 Kohm one between B.0 and 5 volts of power supply, and we can see that the impulse occurs with the passage through 0 of the waveform. Without this resistance the impulse occurs at 0.75 volts.
I have no other pic models with such device to try.
However everything works perfectly using any other pin away from B.0 as I wrote in the previous post. Probably the internal high impedance op amp is very sensitive and short connections and shielding arrangements have to be used.

keytapper

Ignorance comes with a cost

Ivano

#8
Quote from: keytapper on Dec 06, 2022, 11:32 AMHave you noticed any errata at microchip.com?
I did not go to check the errata corrige.
I'll look into it, although I think the problem is more towards the wiring.
You will need to use the same precautions used for operational amplifiers in audio frequency with capacitor on the input that eliminates spikes.
At the moment I don't need this peripheral, but I'm doing some tests with various pic peripherals. In the future it may be useful to know how it works