Panel Energy meter pulse problem - Page 1
Forum section: electronics / beginners

author: npelov
author_rank: Frequent Contributor
timestamp: July 21, 2022, 09:07:31 am
content: Hi,I made a controller to register the pulses of energy meter. I use PIC16F18855 running at 3.3V. I use the internal pull-up.The energy meterprobably has an optron on its output, but they don't say much in the datasheet (the link to the datasheet is to the wrong model, but it probably has the same output). I have series protection resistor on the input to protect from someone putting voltage on the input.The problem is that the meter pulse drops down the voltage to 0.66V. The mcu input is set to Schmitt trigger, which requires 0.2Vdd which is 0.66 to count as '0'. How can I drop the voltage down to low enough to register on the MCU which minimum components?Shorting the resistor drops the voltage down to 0.58V, but it's too close to the limit. I would prefer a bit larger difference.A mosfet would drop it down low enough, but it needs high value resistor gate-source for protection and a pull up resistor. I might be able to squeeze them on the pcb, but Mostfets are too fragile as input. I much prefer BJT.I also though about series capacitor with a pull up resistor to create a pulse. It'll create double the voltage on the pulse end. The back of the pulse is not as sharp, so it should be easy to gradually dissipate through the MCU protection diode. I don't know what's causing the slow rise at the end. Maybe the optron has high capacitance.P.S. At the time I took the scope image the power supply was messed up - 2.5V. I fixed that and the low voltage of the pulse didn't change - still 0.66V

author: Ian.M
author_rank: Super Contributor
timestamp: July 21, 2022, 10:48:09 am
content: You cant alter the logic low level from its pulsed output without considerable complexity. OTOH your PIC has analog comparators capable of internally taking the FVR output as their reference level and the FVR output feeding the comparators can be set to 2.048V, right in the middle between 0.65V and 3.3V, so run the pulse signal through an analog comparator module, and if possible use its output or interrupt flag in place of the input pin in your code or route its output to the peripheral module your input pin's driving. Worst case you may need to assign a comparator output pin and externally strap it to your existing input pin,

author: npelov
author_rank: Frequent Contributor
timestamp: July 21, 2022, 11:05:57 am
content: I need 4 inputs, the pic has 2 comparators.

author: npelov
author_rank: Frequent Contributor
timestamp: July 21, 2022, 12:57:46 pm
content: I just realized that BJT turns on around 0.6-0.7V the 0.66V might not be enough to turn it off completely. I made a simulation with MOSFET 2n7002. I used a Darlington pair to simulate the 0.66V of the energy meter. In thedatasheetthey state gate threshold voltage of 2.1 (min 0.8V). So 0.66 should be able to turn the transistor off. I don't know about effects of temperature. The device might be in a box under the sunlight which might easily get to 50-60 deg C. What happens to threshold voltage when temperature rises?R2 shows the internal pull up, R1, R4 and the transistor - 3 components per channel. It'll be a bit challenging to fit in the remaining space. I might have to move a lot of things around. I didn't include any kind of protection against high voltage (24V) on the input. I'll just hope that the person who installs it won't try this ... Even though when it didn't work they thought trying connecting the input to 24V. It's good they called me.The pulse is inversed, but that should be fixable in software. Any comments on what could go wrong?Edit: Attaching actual test with 2N7002. I used 680k for gate protection (R4). The rest is as on schematic. It works, but I might have to move a lot of components to make all parts fit. On the back side of the pulse I used the slow changing voltage to track the transistor switching. It looks like the threashold is about 1.66-1.68V ... for this part. It'll vary from part to part. But it's really far from 0.66V so it should be good enough

author: Jeroen3
author_rank: Super Contributor
timestamp: July 21, 2022, 02:13:34 pm
content: I made a rpi hat like this. Works great, why make it difficult.I didnotuse an 74HC14 that's only what fusion had for shape, but an74LVC07A.

author: Ian.M
author_rank: Super Contributor
timestamp: July 21, 2022, 02:55:08 pm
content: A quad comparator IC with push-pull outputs or a quad RRIO OPAMP, (both rated for 3.3V single supply operation) with all their -in pins strapped together and biassed to 2V (two resistor divider + a 10nF decoupling cap if you can find space for it) would probably be more compact than 4x your proposed 2N7002 solution. Also, its non-inverting. If you'd prefer an inverting solution, strap the in+ pins top 2V instead.

author: npelov
author_rank: Frequent Contributor
timestamp: July 21, 2022, 04:12:58 pm
content: I was considering internal comparators because of the built in hysteresis option. External comparator would require a lot of components to implement hysteresis. The MOS transistors are controlled by voltage which means that will have somewhat of transfer characteristics in the middle (won't switch immediately) which should help use the Schmitt inputs hysteresis. If you know how to easily improve noise resistance and hopefully parts are available, the quad comparator is a better fit indeed.@Jeroen3 How does this help to drop the voltage down from 0.66V. I can see you have 5V power supply which probably rises the requirements for logical zero voltage.

author: npelov
author_rank: Frequent Contributor
timestamp: July 21, 2022, 07:56:37 pm
content: @Jeroen3 Oh, the 74LVC07 has 0.8V low level. But I think 74LVC14 will be even better for noise immunity. I wander if 74HC14 will do the same job. In thedatasheetthey give negative-going voltage to be 0.5-1.45V at Vcc=3.0V. 0.5V is not enough, but There is a threshold graph that shows minimum value ov V(T-) of around 0.75V @Vcc=3V. Not very consistent... NXP only give values at 2.0V and 4.5V - 0.3 and 0.9 resp. This means @Vcc=3.3V it should be somewhere in the middle 0.6V min - not enough. Even though the typical value is a lot higher..I think I'll go with the transistors. It's harder to fit them, but minimum 0.8V input threshold sounds it'll do the job

author: Jeroen3
author_rank: Super Contributor
timestamp: July 25, 2022, 07:31:31 am
content: Stop using 3.3V as pull-up value. Use 5V.62053-31 says the voltage has to be even higher iirc.It's german, but germans do like their standards a bit too much.https://de.wikipedia.org/wiki/S0-Schnittstelle

author: Ian.M
author_rank: Super Contributor
timestamp: July 25, 2022, 09:40:11 am
content: ConsiderLTC1445quad comparator with internal voltage reference and programmable hysteresis. Its got an internal 1.2V reference, and a hysteresis control pin for the whole chip. The hysteresis (max. 100mV band) can be set by a potential divider from Ref to Gnd.Assuming 1.2V is an acceptable threshold, that gets it down to one IC, your optocouplers and pullups, and a pair of resistors to set the hysteresis.However the fly in the ointment is availability - I would be reluctant to design it in for production at the moment as it adds another single source part with longish lead times. Digikey and Mouser appear to have a couple left in stock, so if its a one-off or very small run project, and you have time to order them so you have stock in hand before committing to the PCB design, it may be viable. Beware: the related LTC1443 doesn't have programmable hysteresis and LTC1444 has open drain outputs so would require pullups on the PIC side.

author: npelov
author_rank: Frequent Contributor
timestamp: July 25, 2022, 12:57:57 pm
content: @Jeroen3 Thanks! Why didn't they include the pulse out schematic or some specifications. It would save me a lot of troubles. Even if it's a standard it should be in the datasheet.Now about the 5V - The schematic in wiki includes driving LED on the receiving side. I don't use optron since there is one already in the meter. The diode will limit the pull down voltage regardless if the pull up is 5V or 3.3V.@Ian.M I really think comparators are overkill for the purpose. Schmitt triggers are a better match if I decide to use a IC. Also I don't find this in JLC library. 74LVC07 should do the job, but I like the transistor approach for following reasons:1. I have a lot of them - I can test right away - no surprises.2. Higher threshold voltage3. Availability is not a problem - since I made the first prototype a few parts went out of stock even though I chose parts with minimum availability of 400-500. 2N7002 is not going to be out of stock soon.

author: Jeroen3
author_rank: Super Contributor
timestamp: July 25, 2022, 02:09:08 pm
content: I don't know why it's not in the datasheet. In almost every case you're looking at an optocoupler in the meter.The "receiver" can also use an optocoupler to provide a completely isolated circuit, including noise immunity and skipping any level translation issues.There could also be some regulation about safety when dealing with the signaling wiring in a low voltage distribution box.This manual has it:https://www.kwhmeter.nl/Files/2/26000/26485/Attachments/Product/Rp70l9b93R6646A4C5vW0Tk7W0R9806W.pdf5-27 Vdc max 27mA

author: npelov
author_rank: Frequent Contributor
timestamp: July 25, 2022, 11:17:35 pm
content: It's not the optocoupler which causes the problem. You can safely assume there is optocoupler in a device that monitors the power line. The diode in series is is causing the voltage drop about 0.6-0.7V. Now that I know there is a diode, I know there is nothing I can do to rise the voltage - not changing the pull-up current, nor pulling up to higher voltage - 5 or 24V. It'll always be about 0.7V.The manual also doesn't say there is a diode in series. Optocoupler should be able top drop down to 0.2-0.3V when the pull-up is weak enough.

author: MikeK
author_rank: Super Contributor
timestamp: July 25, 2022, 11:39:51 pm
content: Do you need a dedicated comparator for each input? Can't you cycle through each of the inputs to a single comparator module? I presume the state of each input is going to be stable for some time that you won't miss one.

author: npelov
author_rank: Frequent Contributor
timestamp: August 19, 2022, 09:06:20 pm
content: Well, what do you know the MCU is out of stock. I had to change it. The new one doesn't have a Schmitt trigger. The TTL levels are more forgiving, but I still used transistors on the input.I had another problem - I decided to put an RC filter with really high capacitance - 4uF (well the R is the internal pull up) on the button inputs. And it made things worse. The front edge was ok because of the button's low resistance. The back edge was clean, but really slow, and somewhere in the middle it double-, sometimes tripple-triggered the interrupt on change. Then I realized I don't have Schmitt triggers and staying too long in the uncertainty region will produce unexpected results. I returned the 100nF caps on the button inputs and now they work fine.I never thought putting much capacitance on the input will increase the noise.@MikeK Theoretically you can always sample fast enough and not miss pulses - they are big enough and maximum one or two per second. But that's not great - you have to constantly think about it in the software. I have UART communication at 9600b a bit longer transmission and you can start missing pulses. Why cause more problems when there are interrupts. I especially chose those pins because of the interrupts.