Stijn Coenen

Most commented posts

  1. Resistor Decade Box — 10 comments
  2. 3D Printer UV Curing Device — 6 comments
  3. Dust extraction – Part 4: Solid State Relay — 4 comments
  4. 12V 25A PowerSupply — 3 comments
  5. 70V 3A Lab Power Supply Upgrade — 3 comments

Author's posts

Radio flea market Lummen 2013

Monday there was a Radio flea market in Lummen.

What I bought (for 9€ including entrance fee):
-1x partial reel 1R resistors
-1x bag timing belts + pulleys
-1x aluminium sheet
-1x 8*2 LCD

1365180945

Safety transformer V2 – Update

After finishing the dummyload project, I remembered that this project uses the same display pcb’s. Therefore I could reuse most of the code. So I finished this project as well. The pic in the project is now a PIC16F1825 which operates at 32Mhz.

http://image.elektronicastynus.be/58/1367676911.jpg

http://image.elektronicastynus.be/58/1367676912.jpg

The code:

'****************************************************************
'*  Name    : Scheidingstransformator V2                        *
'*  Author  : Stijn Coenen ElektronicaStynus.be                 *
'*  Notice  : Copyright (c) 2013 Stijn Coenen (Stynus)          *
'*          : All Rights Reserved                               *
'*  Date    : 01/05/2013                                        *
'*  Version : 1.3                                               *
'*  Notes   : This code is provided to you as is, without       *
'*          : warranty of any kind.Use at own risk!!            *
'**************************************************************** 
Device = 16F1825
Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_ON, FCMEN_ON
Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, BORV_19, LVP_OFF
Xtal = 8
'****************************************************************    
'EN: Declarations
'NL: Declaraties
    'Displays
        Symbol  Disp_klok       = LATC.5
        Symbol  Spanning_Data   = LATC.4
        Symbol  Spanning_Latch  = LATC.3
        Symbol  Stroom_Data     = LATC.2
        Symbol  Stroom_Latch    = LATC.1
        
    'EN: Measurement values
    'NL: Meetwaardes
        Dim     Spanning        As Word
        Dim     Stroom          As Word      
                  
        Symbol  N_Samp_U        = 15          
        Dim     GemU[N_Samp_U]  As Word          
        Symbol  N_Samp_I        = 15         
        Dim     GemI[N_Samp_I]  As Word
        
    'EN: Display values
    'NL: Display waardes  
        Dim     DispSpanning    As Byte
        Dim     DispStroom      As Byte
    
        Dim     DispArU[3]      As Byte 
        Dim     DispArI[3]      As Byte              
        
        Dim     IntCase         As Byte
        Dim     IntX            As Byte
        Dim     IntDisp         As Byte       
        
        Dim     X               As Byte
        Dim     Temp            As Byte
        
    'EN: Settings AD converter
    'NL: Instellingen AD converter 
        Declare Adin_Res        10 
        Declare Adin_Tad        FRC  
        Declare Adin_Stime      250         
        
    'EN: Connections 7 segment displays on the 74HC595 pcb's
    'NL: Aansluitingen 7 segment displays aan de 74HC595 op de printjes    
                            'dPecgbfa
        Symbol  Nul       = %01001000      '       a        '0         
        Symbol  Een       = %11101011      '     #####      '1
        Symbol  Twee      = %01010010      '     #   #      '2
        Symbol  Drie      = %01100010      '   f # g # b    '3
        Symbol  Vier      = %11100001      '     #####      '4
        Symbol  Vijf      = %01100100      '     #   #      '5
        Symbol  Zes       = %01000100      '   e # d # c    '6
        Symbol  Zeven     = %11101010      '     #####      '7
        Symbol  Acht      = %01000000                       '8
        Symbol  Negen     = %01100000                       '9
        Symbol  Uit       = %11111111                       'Out
        Symbol  Streep    = %11110111                       'Bar
    'EN: Connections of the transistors On the 74HC595 pcb's
    'NL: Aansluitingen Transistoren aan de 74HC595 op de printjes
        Symbol  disp1     = %00001100  
        Symbol  disp2     = %00001010  
        Symbol  disp3     = %00000110             
       
    'EN: Misc
    'NL: Diverse
        Symbol  TMR0IF    = INTCON.2
        
        'Tris registers 
        TRISA             = %11111111
        TRISC             = %00000000
         
        All_Digital       = true        
    
        On_Hardware_Interrupt GoTo Interrupts
'****************************************************************    
Opstarten:     
    'EN: Set clock to 64 Mhz
    'NL: klok instellen op 64 Mhz
    OSCCON  = %11110010

    Clear 'ram

    'EN: Timer0 setup to drive the displays
    'NL: Timer0 instellen om de displays aan te sturen
    OPTION_REG  = %00000111
    
    INTCON      = %10100000
    
    'EN: Settings AD converter
    'NL: Instellingen AD converter     
    ADCON1  = %10110000
    
GoTo Main         
'****************************************************************   
Interrupts:
    Context Save
    If TMR0IF = 1 Then
        TMR0IF = 0      'Reset flag
        TMR0   = 230'   'Preloard timer

        'EN: Loading data for the display that is driven this interrupt
        'NL: Data inladen voor het display dat deze interrupt wordt aangestuurd
        DispSpanning    = DispArU[IntCase]
        DispStroom      = DispArI[IntCase]
        
        'EN: Get the transistor settings and set the decimal point
        'NL: Transistoren info uitlezen en de comma aanzetten
        Select IntCase 
            Case 0
                IntDisp = disp1       
            Case 1          
                IntDisp = disp2 
            Case 2          
                IntDisp = disp3         
                DispStroom.6    = 0 
            Case Else
                IntDisp = 255
                IntCase = 0                
        EndSelect
                           
        'EN: Outputting transistors data 
        'NL: Transistor data inklokken
        For IntX  = 0 To 7
            Spanning_Data   = IntDisp.7
            Stroom_Data     = IntDisp.7
            Disp_klok       = 1           
            IntDisp         = IntDisp * 2             
            Disp_klok       = 0
        Next    
        'EN: Outputting display data 
        'NL: Display data inklokken
        For IntX  = 0 To 7
            Spanning_Data   = DispSpanning.7
            Stroom_Data     = DispStroom.7
            Disp_klok       = 1
            DispSpanning    = DispSpanning << 1
            DispStroom      = DispStroom << 1     
            Disp_klok       = 0
        Next               
             
        'EN: Latch data to the outputs of the 74hc595 ic's
        'NL: Data naar de uitgangen van de 74hc595 ic's latchen
        Spanning_Latch  = 1
        Stroom_Latch    = 1     
        
        'EN: Set counter for next interrupt
        'NL: Teller bijtellen voor volgende interrupt
        Inc IntCase
        If IntCase > 2 Then
            IntCase = 0
        EndIf
        
        Spanning_Latch  = 0
        Stroom_Latch    = 0 
    EndIf
               
    Context Restore
Return
'****************************************************************     
Main:
    While 1 = 1        
        'EN: Voltage measurement
        'NL: Spannings meting
        For X = (N_Samp_U - 1) To 1 Step -1    
            GemU[X]     = GemU[X-1]      
        Next
        Spanning        = ADIn 0
        Spanning        = Spanning /10 
        Spanning        = Spanning - 4.95 
        GemU[0]         = Spanning * 3.25'3.03
        Spanning        = 0
        For X = 0 To (N_Samp_U - 1)    
            Spanning    = Spanning + GemU[X]
        Next 
        Spanning        = Spanning / N_Samp_U
        
        'EN: Current measurement
        'NL: Stroom meting    
        For X = (N_Samp_I - 1) To 1 Step -1    
            GemI[X]     = GemI[X-1]      
        Next
        Stroom          = ADIn 1   
        Stroom          = Stroom - 55 'Offset
        
        GemI[0]         = Stroom /4.28
        Stroom          = 0
        For X = 0 To (N_Samp_I - 1)    
            Stroom      = Stroom + GemI[X]
        Next 
        Stroom          = Stroom / N_Samp_I

        'EN: Calculate value's for on the display
        'NL: Meetwaardes naar display berekenen
        For X = 0 To 2 
            Temp = Dig Spanning, X
            DispArU[X] = LRead Cijfers + Temp       
            Temp = Dig Stroom, X 
            DispArI[X] = LRead Cijfers + Temp
        Next 
        
        'EN: Delay for slower display update
        'NL: Wachten om het display niet te snel te updaten
        DelayMS 75
    Wend
'****************************************************************   
Cijfers:-  
LData Nul, Een, Twee, Drie, Vier, Vijf, Zes, Zeven, Acht, Negen, Uit, Streep     
End

Files

Code file: Download

Hex file: Download

PCB file meter pcb: Download

Safety transformer V3 – Update

The electronics of the measuring pcb from this project is exactly the same as that from the safety transformer V2 project. Therefore I could now finish this design too.

The finished result:

http://image.elektronicastynus.be/59/1367683024.jpg

http://image.elektronicastynus.be/59/1367683020.jpg

DC Dummyload – Update

After a long time I decided to start again on this project. Quickly it became clear that there were still a few problems whit this project.

The first problem I encountered was that the transistors started to oscillate and draw to much base current when the voltage started to get to low. The oscillations turned out to be caused by the shutdown circuit I placed on the main pcb. After I removed this circuit the oscillations where gone. But there was still the problem of the too big base current in the transistors. This I solved by added 2 resistors to each step of the output stage.

schema

R4 is added in this circuit. Also there needs to be a 150 Ohm 2W resistor placed between this pcb and the base of the 2N3055.

After these modifications it turned out that the power supply became a bit unstable. Therefore I replaced it by a 16V laptop charger. For the microcontroller and displays I added a voltage regulator pcb to create the required 5V.

The cooling fans need 12V, so I added a second voltage regulator pcb with a 7812 voltage regulator (mounted on the big heat sink).

When I was coding the current measurement I noticed another problem. The base current was also measured. To fix this I added a new pcb based on a ZXCT1086E5TA to measure the current trough the positive lead. This measurement however has the disadvantage to only work above 3V. This I “solved” by adding a few lines in the code which put — on the ampere display when the voltage gets too low.

http://elektronicastynus.be/image/77/Stroommeetprint.png

http://elektronicastynus.be/image/77/1367670001.jpg

http://elektronicastynus.be/image/77/1367670006.jpg

To connect this pcb to the main pcb I had to mod the main pcb a bit:http://elektronicastynus.be/image/77/1367670283.jpg

New circuit:

http://elektronicastynus.be/image/77/Main_schema.png

To get a stable measurement, I take the mean value of a number of samples. For this code, the pic I originally designed into the the project, turned out to be too slow. Therefore I replaced it with a PIC16F25K22 (pin compatible). This pic operates at 64Mhz.

The code:

'****************************************************************
          '*  Name    : Dummyload                                         *
          '*  Author  : Stijn Coenen ElektronicaStynus.be                 *
          '*  Notice  : Copyright (c) 2013 Stijn Coenen (Stynus)          *
          '*          : All Rights Reserved                               *
          '*  Date    : 01/05/2013                                        *
          '*  Version : 1.2                                               *
          '**************************************************************** 
Device = 18F25K22
  Include "Config_Fuses_1_2.bas"    
Xtal = 16
'****************************************************************    
  'EN: Declarations
  'NL: Declaraties
  'Displays
  Symbol  Disp_klok       = LATB.7
        Symbol  Temp_Data       = LATB.2   
        Symbol  Temp_Latch      = LATB.1   
        Symbol  Spanning_Data   = LATB.4
        Symbol  Spanning_Latch  = LATB.3
        Symbol  Stroom_Data     = LATB.6
        Symbol  Stroom_Latch    = LATB.5
        
    'EN: Measurement values
      'NL: Meetwaardes
      Dim     Temperatuur     As Word
        Dim     Spanning        As Word
        Dim     Stroom          As Dword  
        Dim     StroomFloat     As Float  
        Dim     StroomPrecies   As Bit            
        
        Symbol  N_Samp_T        = 10    'Number of measuring samples; Aantal meetwaardes       
          Dim     GemT[N_Samp_T]  As Word 'Array that contains the samples; Array die de meetwaardes bevat                  
            Symbol  N_Samp_U        = 15          
        Dim     GemU[N_Samp_U]  As Word          
        Symbol  N_Samp_I        = 15         
        Dim     GemI[N_Samp_I]  As Word
        
    'EN: Display values
      'NL: Display waardes  
      Dim     DispTemp        As Byte
        Dim     DispSpanning    As Byte
        Dim     DispStroom      As Byte
    
        Dim     DispArT[3]      As Byte 
        Dim     DispArU[3]      As Byte 
        Dim     DispArI[3]      As Byte              
        
        Dim     IntCase         As Byte
        Dim     IntX            As Byte
        Dim     IntDisp         As Byte       
        
        Dim     X               As Byte
        Dim     Temp            As Byte
        
    'EN: Settings AD converter
      'NL: Instellingen AD converter 
      Declare Adin_Res        10 
        Declare Adin_Tad        FRC  
        Declare Adin_Stime      250         
        
    'EN: Connections 7 segment displays on the 74HC595 pcb's
      'NL: Aansluitingen 7 segment displays aan de 74HC595 op de printjes    
      'dPecgbfa
      Symbol  Nul       = %01001000      '       a        '0         
        Symbol  Een       = %11101011      '     #####      '1
          Symbol  Twee      = %01010010      '     #   #      '2
            Symbol  Drie      = %01100010      '   f # g # b    '3
              Symbol  Vier      = %11100001      '     #####      '4
                Symbol  Vijf      = %01100100      '     #   #      '5
                  Symbol  Zes       = %01000100      '   e # d # c    '6
                    Symbol  Zeven     = %11101010      '     #####      '7
                      Symbol  Acht      = %01000000                       '8
                        Symbol  Negen     = %01100000                       '9
                          Symbol  Uit       = %11111111                       'Out
                            Symbol  Streep    = %11110111                       'Bar
                              'EN: Connections of the transistors On the 74HC595 pcb's
                              'NL: Aansluitingen Transistoren aan de 74HC595 op de printjes
                              Symbol  disp1     = %00001100  
        Symbol  disp2     = %00001010  
        Symbol  disp3     = %00000110             
       
    'EN: Misc
      'NL: Diverse
      Symbol  TMR0IF    = INTCON.2
        
        'Tris registers
          TRISA             =  %00111011
        TRISB             =  %00000000
        TRISC             =  %11111111  
         
        All_Digital       = true        
    
        On_Hardware_Interrupt GoTo Interrupts
'****************************************************************    
  Opstarten:     
    'EN: Set clock to 64 Mhz
      'NL: klok instellen op 64 Mhz
      OSCCON  = %01110111
    OSCCON2 = %11000111  

    Clear 'ram
      
      'EN: Timer0 setup to drive the displays
      'NL: Timer0 instellen om de displays aan te sturen
      T0CON   = %11000111
    INTCON  = %10100000
    INTCON2 = %00000100
    INTCON3 = %00000000
    IPR1    = %00000000
    IPR2    = %00000000
    IPR3    = %00000000
    IPR4    = %00000000
    IPR5    = %00000000
    
    'EN: Settings AD converter
      'NL: Instellingen AD converter     
      ADCON1  = %00000000
    ADCON2  = %10010111
    
GoTo Main         
'****************************************************************   
  Interrupts:
    Context Save
    If TMR0IF = 1 Then
        TMR0IF = 0      'Reset flag
          TMR0L  = 230'   'Preloard timer
            
            'EN: Loading data for the display that is driven this interrupt
            'NL: Data inladen voor het display dat deze interrupt wordt aangestuurd
            DispTemp        = DispArT[IntCase]  
        DispSpanning    = DispArU[IntCase]
        DispStroom      = DispArI[IntCase]
        
        'EN: Get the transistor settings and set the decimal point
          'NL: Transistoren info uitlezen en de comma aanzetten
          Select IntCase 
            Case 0
                IntDisp = disp1       
            Case 1          
                IntDisp = disp2       
                DispTemp.6      = 0          
                DispSpanning.6  = 0
                DispStroom.6    = StroomPrecies
            Case 2          
                IntDisp = disp3   
                DispStroom.6    = StroomPrecies + 1 
            Case Else
                IntDisp = 255
                IntCase = 0                
        EndSelect
                           
        'EN: Outputting transistors data 
          'NL: Transistor data inklokken
          For IntX  = 0 To 7
            Temp_Data       = IntDisp.7 
            Spanning_Data   = IntDisp.7
            Stroom_Data     = IntDisp.7
            Disp_klok       = 1           
            IntDisp         = IntDisp * 2             
            Disp_klok       = 0
        Next    
        'EN: Outputting display data 
          'NL: Display data inklokken
          For IntX  = 0 To 7
            Temp_Data       = DispTemp.7 
            Spanning_Data   = DispSpanning.7
            Stroom_Data     = DispStroom.7
            Disp_klok       = 1
            DispTemp        = DispTemp << 1
            DispSpanning    = DispSpanning << 1
            DispStroom      = DispStroom << 1     
            Disp_klok       = 0
        Next               
             
        'EN: Latch data to the outputs of the 74hc595 ic's
          'NL: Data naar de uitgangen van de 74hc595 ic's latchen
          Temp_Latch      = 1
        Spanning_Latch  = 1
        Stroom_Latch    = 1     
        
        'EN: Set counter for next interrupt
          'NL: Teller bijtellen voor volgende interrupt
          Inc IntCase
        If IntCase > 2 Then
            IntCase = 0
        EndIf
        
        Temp_Latch      = 0
        Spanning_Latch  = 0
        Stroom_Latch    = 0 
    EndIf
               
    Context Restore
Return
'****************************************************************     
  Main:
    While 1 = 1    

        'EN: Temperature measurement
          'NL: Temperatuur meting
          For X = (N_Samp_T - 1) To 1 Step -1    
            GemT[X]     = GemT[X-1]      
        Next
        Temperatuur     = ADIn 1
        Temperatuur     = Temperatuur * 5 
        GemT[0]         = Temperatuur / 9 
        Temperatuur     = 0
        For X = 0 To (N_Samp_T - 1)    
            Temperatuur = Temperatuur + GemT[X]
        Next 
        Temperatuur     = Temperatuur / N_Samp_T
        
        
        'EN: Voltage measurement
          'NL: Spannings meting
          For X = (N_Samp_U - 1) To 1 Step -1    
            GemU[X]     = GemU[X-1]      
        Next
        Spanning        = ADIn 0
        GemU[0]         = Spanning /  1.86
        Spanning        = 0
        For X = 0 To (N_Samp_U - 1)    
            Spanning    = Spanning + GemU[X]
        Next 
        Spanning        = Spanning / N_Samp_U
        
        
        'EN: Current measurement
          'NL: Stroom meting    
          For X = (N_Samp_I - 1) To 1 Step -1    
            GemI[X]     = GemI[X-1]      
        Next
        Stroom          = ADIn 16   
        'EN: Setting the decimal point place
          'NL: Plaats comma bepalen                    
          If Stroom > 500 Then 'X.XX
            StroomPrecies = 0  
            StroomFloat = Stroom * (5/1024) * 10   
        Else                 'XX.X  
          StroomPrecies = 1   
            StroomFloat = Stroom * (5/1024) * 100                 
        EndIf  
        StroomFloat     = StroomFloat / 50
        StroomFloat     = StroomFloat / 0.005
        GemI[0]         = StroomFloat * 1.07
        Stroom          = 0
        For X = 0 To (N_Samp_I - 1)    
            Stroom      = Stroom + GemI[X]
        Next 
        Stroom          = Stroom / N_Samp_I
    
        'EN: Calculate value's for on the display
          'NL: Meetwaardes naar display berekenen
          For X = 0 To 2
            Temp = Dig Temperatuur, X
            DispArT[X] = LRead Cijfers + Temp   
            Temp = Dig Spanning, X
            DispArU[X] = LRead Cijfers + Temp  
            'EN: The ZXCT1086E5TA does Not work below 3V, so display bars when this happens
              'NL: De ZXCT1086E5TA werkt niet onder de 3V, dus als dit gebeurt streepjes weergeven
              If Spanning > 30 Then             
                Temp = Dig Stroom, X
                DispArI[X] = LRead Cijfers + Temp
            Else
                DispArI[X] = Streep
            EndIf
        Next 
        
        'EN: Delay for slower display update
          'NL: Wachten om het display niet te snel te updaten
          DelayMS 75
    Wend
'****************************************************************   
  Cijfers:-  
LData Nul, Een, Twee, Drie, Vier, Vijf, Zes, Zeven, Acht, Negen, Uit, Streep     
End

The dummyload working:

http://elektronicastynus.be/image/77/1367670980.jpg

http://elektronicastynus.be/image/77/1367670974.jpg

Files

Code file: Download

Hex file: Download

Radio flea market Eksel 2013

Today there was a Radio flea market in Eksel.

What I bought (for 37€ including entrance fee):

-4x bag wire
-1x bag timing belts + pulleys
-1x 8*2 LCD
-1x partial reel 3V3 zener diode’s
-1x reel resistors
-5x wheel
-1x 24V 300W power supply
-1x 48V 500W power supply

1367766689

Radio flea market Bladel 2013

Today there was a Radio flea market in Bladel. What I bought (for 28€ including entrance fee):

2x voltage regulator pcb
4x power cable
1x parallel port cable
1x wire strippers
1x bag rubber enclosure feet
1x bag timing belts + pulleys
2x lcd
2x bag brown wire

1387715013

Radio flea market Lummen 2014

Today there was a Radio flea market in Lummen. What I bought (for 45,30€ including entrance fee):

16x bag print connectors
2x bag wire
1x bag knobs
1x bag relays
1x 230V relay
1x relay socket
2x female connector strip
1x Motor
1x hard disk 80GB IDE

1398081715

Radio flea market Eksel 2014

Today there was a Radio flea market in Eksel.

What I bought (for 33,50€ including entrance fee):
5x    Bag fuse holders
2x    Bag spacers
3x    bag print connectors
1x    Big bearing
1x    Bag washers
1x    Compressor / air pump
1x    50 cd’s

1400408576

Resistor Decade Box

I was thinking about making a resistor decade box, but I found the rotary switches that are used in these most of the time rather expensive and a bit old fashioned. That’s why I decided to use a rotary encoder and select the resistors with a microcontroller.

Now I only had to find a way to “make” the resistance. Switching resistors with transistors or mosfets gives a high switch resistance and can’t handle AC voltages. That’s why I opted to use relays. The currents that need to be switched are rather small, therefore a small relay is sufficient. The relay board is used 2 times with different resistor values.

Relay PCB:

http://image.elektronicastynus.be/83/1307108369.jpg

Part list:
PCB low resistance:

3 1K R22, R23, R24
1 1K8 R26
3 1R R1, R2, R3
1 1R8 R5
1 2K2 R25
1 2R2 R4
1 3K3 R28
1 3R3 R7
1 4K7 R27
1 4R7 R6
3 10R R8, R9, R10
1 18R R12
1 22R R11
1 33R R14
1 47R R13
3 100R R15, R16, R17
1 180R R19
1 220R R18
1 330R R21
1 470R R20
2 100nF C1, C2
2 74HCT595 IC1, IC3
2 ULN2803 IC2, IC4
16 TQ2-24V K1, K2, K3, K4, K5, K6, K7, K8, K9,
K10, K11, K12, K13, K14, K15, K16

PCB high resistance:

3 10K R1, R2, R3
1 18K R5
1 22K R4
1 33K R7
1 47K R6
3 100K R8, R9, R10
1 180K R12
1 220K R11
1 330K R14
1 470K R13
3 1M R15, R16, R17
1 1M8 R19
1 2M2 R18
1 3M3 R21
1 4M7 R20
2 100nF C1, C2
2 74HCT595 IC1, IC3
2 ULN2803 IC2, IC4
12 TQ2-24V K1, K2, K3, K4, K5, K6, K7, K8, K9,
K10, K11, K12

 

Control PCB:

Part list:

2 1uF C3, C4
1 10K R2
1 10K R1
1 16F648A (Programmed) IC1
2 100nF C1, C2
1 Push button S1
1 Rotary encoder S1
1 REG1117-5V IC2

 

With frontpanel:

Power supply

This part is made on experiment board, therefore there are no circuit drawings available. The pcb exists of a 18V transformer; a rectifier and a capacitor.

Everything mounted in the enclosure:

Ready:

Code in the microcontroller:

Device = 16F648A
Config FOSC_INTOSCIO, WDTE_OFF, PWRTE_ON, MCLRE_OFF, BOREN_OFF, LVP_OFF, CPD_OFF, CP_OFF

All_Digital           = true
Xtal                  = 4

Declare PortB_Pullups   On

Declare LCD_DTPin       PORTB.4  
Declare LCD_ENPin       PORTB.2
Declare LCD_RSPin       PORTB.3
Declare LCD_Interface   4
Declare LCD_Lines       2

Symbol  RotEncoderA   = PORTB.1  
Symbol  RotEncoderB   = PORTB.0 
Symbol  RotSwitch     = PORTA.2

Symbol  PushSwitch    = PORTA.4
Dim     PushSwitchBit As Bit

TRISB                 = %00000011
TRISA                 = %01111100

OPTION_REG            = %01000000 
INTCON                = %10010000
Symbol  INTF          = INTCON.1     

Symbol  klok          = PORTA.0
Symbol  Data_Pin      = PORTA.7
Symbol  ZetVast       = PORTA.1

Dim  DispWaarde[7]    As Byte
Dim  SetWaarde[7]     As Byte
Dim  DispTeller       As Byte
Dim  CursorTeller     As Byte
Dim  UitHex           As Byte 
Dim  UitDig           As Byte
Dim  UitCount         As Byte
Dim  ArrayTeller      As Byte
Dim  Warning          As Bit
'dim teller as byte
       
On_Hardware_Interrupt GoTo IrInterrupt  
    
GoTo Init     
'****************************************************************
IrInterrupt:
    Context Save       
       If INTF = 1 Then
          'Flaggen resetten
          INTF = 0
          If RotEncoderA = 1 Then
             'Aftellen
             If DispWaarde[6 - DispTeller] > 0 Then
                Dec DispWaarde[6 - DispTeller]
             EndIf
          Else
             'Optellen  
             If DispWaarde[6 - DispTeller] < 9 Then
                Inc DispWaarde[6 - DispTeller]
             EndIf                       
          EndIf   
       EndIf 
    Context Restore         
'****************************************************************
Init:
    Cls
      
    UitDig = DispWaarde[3] 
    UitHex = UitDig << 4
    UitDig = DispWaarde[2]
    UitHex = UitHex + UitDig   
    UitHex = ~UitHex    
    SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]
    
    UitDig = DispWaarde[1]  
    UitHex = UitDig << 4
    UitDig = DispWaarde[0]
    UitHex = UitHex + UitDig   
    UitHex = ~UitHex   
    SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]   
    
    UitHex = 0
    UitDig = DispWaarde[6]
    UitHex = UitHex + UitDig         
    UitHex = ~UitHex  
    SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]   
    
    UitDig = DispWaarde[5] 
    UitHex = UitDig << 4
    UitDig = DispWaarde[4]
    UitHex = UitHex + UitDig    
    UitHex = ~UitHex   
    SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]   
    
    High ZetVast
    DelayUS 20
    Low ZetVast
                   '12345678
    Print At 1, 1, "E-Stynus"
    Print At 2, 1, "  2014  "
    DelayMS 750
    Cls  

    Print At 1,1, "Set:"   
    DispTeller = 0
    
    'Ohm teken in lcd steken
    Print $FE,$40,$00,$0E,$11,$11,$11,$0A,$1B,$00
'****************************************************************
Main:
While 1 = 1      
   'Relais aansturen bij rotary encoder button druk
   If RotSwitch = 0 Then
      For ArrayTeller = 0 To 6  
          SetWaarde[ArrayTeller]     = DispWaarde[ArrayTeller] 
          If SetWaarde[ArrayTeller]  > 9 Then
             SetWaarde[ArrayTeller]  = 0     
             DispWaarde[ArrayTeller] = 0
          EndIf    
      Next
      
      UitDig = DispWaarde[3] 
      UitHex = UitDig << 4
      UitDig = DispWaarde[2]
      UitHex = UitHex + UitDig   
      UitHex = ~UitHex    
      SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]
      
      UitDig = DispWaarde[1]  
      UitHex = UitDig << 4
      UitDig = DispWaarde[0]
      UitHex = UitHex + UitDig   
      UitHex = ~UitHex   
      SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]   
      
      UitHex = 0
      UitDig = DispWaarde[6]
      UitHex = UitHex + UitDig         
      UitHex = ~UitHex  
      SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]   
      
      UitDig = DispWaarde[5] 
      UitHex = UitDig << 4
      UitDig = DispWaarde[4]
      UitHex = UitHex + UitDig    
      UitHex = ~UitHex   
      SHOut Data_Pin, klok, MsbFirst, [UitHex \ 8]   
  
      High ZetVast
      DelayUS 20
      Low ZetVast
      
      DelayMS 100  
      While RotSwitch = 0   
            DelayMS 100  
      Wend
        
   EndIf 
    
   'Warning teken                               
   Warning = 0
   For ArrayTeller = 0 To 6  
       If DispWaarde[ArrayTeller] <> SetWaarde[ArrayTeller] Then
          Warning = 1
       EndIf   
   Next
   If Warning = 1 Then
      Print At 1, 8, "!"
   Else      
      Print At 1, 8, " "
   EndIf
    
   'Decade positie
   If PushSwitch = 0 And PushSwitchBit = 0 Then
      PushSwitchBit = 1
      DelayMS 100
      If DispTeller < 6 Then
         Inc DispTeller
      Else
         DispTeller = 0
      EndIf
   EndIf
   If PushSwitch = 1 Then
      PushSwitchBit = 0
   EndIf
   For ArrayTeller = 0 To 6  
       If DispWaarde[ArrayTeller] > 9 Then
          DispWaarde[ArrayTeller] = 0
       EndIf    
       Print At 2, 7 - ArrayTeller, Dec1 DispWaarde[ArrayTeller]
   Next
   Print At 2,8, 0
   '(Print At 1,4, Dec DispTeller          
   Print $FE, $0E           'Underline cursor on
   Print $FE, $C0           'Move cursor to beginning of second line 
   CursorTeller = 0
   While CursorTeller < DispTeller
       Print $FE, $14      'Move cursor right one position
       Inc CursorTeller
   Wend
   
   
   DelayMS 100                   
   
Wend
End

Hex file: link

Files:

Order boards:

Safety transformer V3 – Update

After a few months of using this project it turned out that the solid state relays where not as reliable as first thought. One time the power relay stayed stuck close, but the resistors where not shorted by the other relay. This caused the resistors to get too hot (they are not calculated for continuous load).

The burned pcb:

After this I decided to build a new version of this pcb. This time with mechanical relays:

Circuit diagram:

PCB:

Picture:

The firmware in the microcontroller stays the same.