Measuing AC line frequency

GopherT

Joined Nov 23, 2012
8,009
BTW, the circuit gives pulses which are positive and negative, and microcontrollers dont like the negative ones! You need to limit it to the supply rails of the microcontroller!
Are you sure this is true? I thought PICs could handle some negative current draw on input. Microchip had an Application Note about zero-crossing detector too.
 

Alec_t

Joined Sep 17, 2013
14,312
PICs have internal diodes which offer only limited protection against input voltages above V+ and below V-. Safer to use external Schottky diodes to clamp input voltages.
 

Thread Starter

kriscpm

Joined Oct 5, 2013
7
So i should remove the negative voltage at V- and just connect it to ground instead? After simulation, it does not have negative voltage anymore. Is that ok?
 

Alec_t

Joined Sep 17, 2013
14,312
The negative-going pulse can be removed by passing the comparator/opamp output via a resistor (e.g. a few k) to the cathode of a Scottky diode which has its anode grounded.
 

THE_RB

Joined Feb 11, 2008
5,438
I take a different approach to Alec_T on that.

As the output of the little transformer is "safe", (ie it is a known voltage and waveshape) you can just connect it through a series resistor direct to a PIC digital input pin.

The PIC internal pin diodes are safe for 20mA, and the resistor can be sized to only allow 1mA (or 0.1mA) max, giving safe operation. There are a huge amount of designs, even commercial ones, using a signal through a series resistor and relying on the internal port pin diodes to limit the pin voltage to approx 0-5v.
 

RamaD

Joined Dec 4, 2009
328
Are you sure this is true? I thought PICs could handle some negative current draw on input. Microchip had an Application Note about zero-crossing detector too.
Most inputs have internal protection diodes connected to the supply and ground, and that is what is offered as Vdd+0.3 and Vss-0.3, beyond which they conduct and bypass the current to the supply or ground, and if excessive, these are destroyed. It is likely that the current could have been limited in the AN about the zero crossing detector.
 

Alec_t

Joined Sep 17, 2013
14,312
and the resistor can be sized to only allow 1mA (or 0.1mA) max, giving safe operation.
.... but if the input pin is for an ADC then too high a resistance could lead to inaccuracy of the conversion.
 

THE_RB

Joined Feb 11, 2008
5,438
Sure, you are right there can be issues with using such a simple system.

But it works fine for a lot of digital sensing, especially for simple tests etc where you don't want to add too much hardware.

For example in my tests I just connected a 12v AC plugpack into a connector, then through a 12k resistor to the PIC digital input (CCP1) pin. The only other addition was a 0.1uF cap from that input pin to gnd;



The 12k resistor limited the + current into the PIC pin to about 0.6mA, and the - current into the pin to about 1mA.

In this other circuit I used a pot, which adjusted the full wave rectified DC to a waveform that went from 0-5v. The PIC's internal comparator and Vref were used to detect the mains timing;

 
Top