'**************************************************************** '* Name : P1 dongle * '* Date : 17-06-2026 * '* Version : 1.0 op 29-06-2026 * '* Notes : Uitlezing P1dongle, actie TRIAC Boiler 2kW * '* : Triac gaat aan en stuurt energie naar Boiler * '**************************************************************** ; PIC16F690 +--v--+ ; V+ >[ ] - GND ; 20MHz Crystal to A4 A5 <[ ]< A0 ; 20MHz Crystal To A5 A4 <[ ]< A1 ; MCLR A3 >[ ]< A2 TRIAC out ; HPWM OUT C5 <[ ] C0 LCD display ; C4 <[ ]> C1 LCD display ; LCD display C3 <[ ]< C2 LCD display ; LCD display C6 <[ ]> B4 ; LCD display C7 <[ ]> B5 RS232 in ; B7 <[ ]> B6 ; +-----+ Device 16F690 Config HS_OSC, WDT_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, CPD_OFF, BOD_OFF, IESO_OFF, FCMEN_OFF XTAL = 20 Declare LCD_DTPIN = PORTC.0 Declare LCD_ENPIN = PORTC.6 Declare LCD_RSPIN = PORTC.7 ; 76543210 PORTA = %11100000 TRISA = %10100011 ' RA5 is input voor Kristal (Correct!) PORTB = %00000000 TRISB = %01100000 ' RB5 = RX, moet een INgang zijn. (Staat correct op 1) PORTC = %00000010 TRISC = %00000010 ANSEL = %00000000 ' Alle analoge poorten UIT (Cruciaal voor LCD en RX!) ANSELH = %00000000 ' AN11 (RB5/RX) staat hierdoor ook UIT (Correct!) T1CON = %00000001 ' Timer1 aan ; Interrupt registers UITzetten om crashes te voorkomen PIE1 = %00000001 'interrupts Timer1 inschakelen OPTION_REG = %10000000 ' Geen pull-ups CM1CON0 = %00000000 'Comparator 1-module is UIT CM2CON0 = %00000000 'Comparator 2-module is UIT INTCON = %00000000 'Interruptscontrole (TMR0 AAN) ALL_DIGITAL TRUE ; Calculated Baudrate = 115200 @ Xtal 20MHz, Error = 0,16% HSERIAL_RCSTA = 144 ' %10010000 -> SPEN active, CREN (Continuous Receive) active HSERIAL_TXSTA = 36 ' %00100100 -> TXEN active, BRGH = 1 HSERIAL_SPBRG = 10 ' 115200 Baud HSERIAL_CLEAR = On Dim PT_Info[10] As Byte ; Tijd en Datum Dim P1_Info[9] As Byte Dim P0_Info[9] As Byte Dim MY As Word ; Power van het NET Dim Pnet As Word ; Power van het NET Dim Pzon As Word ; Power van de ZON Dim Ptime As byte ; Datum YYMMDDhhmmss ;MY = ValPzon Dim Duty As Byte Dim Duty4 As Byte Dim Duty2 As Byte Dim Duty3 As Byte Dim DutyF As Byte Dim Teller As Byte ; Aftellen van de tijd dat de boiler actief is Dim TIMER1 As TMR1L.Word ; Timer1 woord symbol RCIDLE = BAUDCTL.6 ; High voor Idle, low voor startbit received symbol TMR1F = PIR1.0 Symbol TRIAC = PORTA.2 Clear Print At 2, 1, "P1_poort" DelayMS 500 Cls ;----------- Main Application ----------- Main: ' Preventieve controle op Overrun Fout (OERR). ' Als de buffer overloopt bij 115200 baud, resetten we hem hier direct. If RCSTA.1 = 1 Then RCSTA.4 = 0 ' CREN uit RCSTA.4 = 1 ' CREN aan (wist OERR vlag) EndIf ' We wachten maximaal 1000ms op de header en vullen direct de 9 bytes array. HRSin { 1000 , TimeOutLabel },Wait("0-0:1.0.0("),Str PT_Info\12 ; Time from grid HRSin { 1000 , TimeOutLabel },Wait("1-0:1.7.0("),Str P1_Info\9 ; Power from grid HRSin { 1000 , TimeOutLabel },Wait("1-0:2.7.0("),Str P0_Info\9 ; power from sun Cls Pnet = ( P1_Info[1] - 48) *1000 + ( P1_Info[3] -48 ) * 100 +( P1_Info[4] -48 ) *10 + P1_Info[5] -48 Pzon =( P0_Info[1] - 48) *1000 + ( P0_Info[3] -48 ) * 100 +( P0_Info[4] -48 ) *10 + P0_Info[5] -48 Print at 2,1, "NET ", DEC Pnet ," W" print at 1,1, "ZON ", DEC Pzon ,"W" If Pzon > Pnet then Print At 1 ,10," +", DEC (Pzon - Pnet ),"W" Print At 2, 12, DEC (PT_Info[6] -48) , dec (PT_Info[7]- 48 ),":" ,DEC( PT_Info[8] - 48) ,DEC ( PT_Info[9] -48 ) ;---------------------------------------------------------------------------------------- ;START VOORWAARDEN TRIAC CONTROL BOILER ;------------------------------------------------------------------------------------------- If ( Pzon - Pnet) > 2000 then ; Altijd aan want de ZON wil leveren TRIAC = 1 Goto Main endif ;---------------------------------------------------------------------------------------- ; REGELING TRIAC CONTROL BOILER ;------------------------------------------------------------------------------------------- If (Pnet - Pzon) >= 5 then Duty3 = ((Pnet - Pzon) /20 ) Print At 2 ,12, dec Duty3 goto DutyCAL endif If (Pzon - Pnet) < 2000 then Duty2 = (Pzon - Pnet) /20 ; Maximum voor 2kWatt DutyCAL: Duty = Duty2 + Duty4 - Duty3 ; Als de boiler aanstaat dan zakt de power in. Duty4 = Duty ; De meting geeft dan aan dat de boiler ; PWM informatie moet krijgen. Dat kan dus fout zijn If Duty <= 50 then TRIAC = 1 DutyF = Duty endif If Duty > 50 then DutyF = 100 - Duty TRIAC = 0 endif If Duty >= 100 then Duty = 99 Teller = 0 ;---------------------------------------------------------------------------------------- ; TIEN MILLISECONDEN TIMER ;------------------------------------------------------------------------------------------- Cycle: IF PIR1.0 =1 then ; Timer1 Flag at 65536 - 15536 = 50000 ; PIR1.0 = 0 ; Clock van 20 MHz is .2 usec tic INC Teller ; tijd is dan 50.000 x .2 usec = 10 msec TIMER1 = TIMER1 + 15536 ; Iedere 10 millisec loopt de teller op endif ; max teller in 1 sec is dus 100 If Teller > DutyF then TRIAC =~ TRIAC GoTo Main endif goto Cycle GoTo Main TimeOutLabel: ' Er is binnen 1 seconde geen ("1-0:1.7.0(") of onvolledige data binnengekomen ; Print At 1, 1, "Wachten op data" Print At 2, 1, "Timeout!" ; delayms 1000 ; cls GoTo Main End