With this concept, we use DT's Instant Interrupt system with some minor modification.
The attached file has the addition of GPIO change interrupt.
In the program, we simply add what GPIO pin we want to use as the interrupt pin. That is all.
The circuit has the simplicity of getting the zero crossing concept.
The important point with this circuit is that there is one single point at which PinA is High.
Demo code is just to show how the concept works.
Suggestions are accepted

' This code can only be compiled with the file named "DT_INTS-14_MOD.bas".
'The file has some additions to DT's original file for GPIO change interrupt.
'===12F683======
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_ON & _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF
CLEAR
OSCCON =%01110001 ' Internal 8MHz osc.
DEFINE OSC 8
CMCON0 =7 ' Disable analog comparator
TRISIO =%00001000
GPIO =0
ADCON0 =0
ANSEL =0 ' All digital.
CCP1CON=0
'=======================
ZeroLine VAR GPIO.3 ' Input for zero crossing.
Out VAR GPIO.5 ' Output pin.
CountVal VAR WORD ' A variable to count incoming 50Hz pulses.
' Include files for DT's interupt routines.
INCLUDE "DT_INTS-14_MOD.bas" ; Base Interrupt System ; Attention ! Modified file !
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts
PAUSE 20
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler GPIF_INT, _KES, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
IOC.3 = 1 ; Enable interrupt on GP3 change (change this pin to the one you need).
@ INT_ENABLE GPIF_INT ; enable GPIO Change (INT) interrupts
Begin:
CountVal=0
Start:
' Here, lets have a simple program just to test the zero cross pulses.
SELECT CASE CountVal
CASE IS > 200 ' Counter resets.
CountVal=0
CASE IS > 100 ' Output is OFF.
Out=0
CASE IS > 50 ' Output is ON.
Out=1
END SELECT
GOTO Start
KES:
IF ZeroLine THEN CountVal=CountVal + 1 ' Catch zero cross point.
@ INT_RETURN
END


Menu

Re: YHDC current sensor - the theory please
adjust resister to for the mid current used incase of some nonlinearity... shotkey diode has .3 volt drop
amgen - 2nd December 2025, 01:1710016