DC-Power-Panelmeter

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

DC-Power-Panelmeter

Post by electron »

User avatar
electron
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 225
Joined: 28-02-2009, 19:20
Location: Serbia

Re: DC-Power-Panelmeter

Post by electron »

Evo i koda sa istog sajta koji ima neke greske

Code: Select all

'***********************************************************************
'
'    Filename        :     PPM.Bas		
'    File Version    :     1.0
'    Datum           :     24.05.2008            	
'    Autor           :     Peter Verderber		
'    Funktion        :     Power-Panelmeter		
'    Letzte Revision :     1.0
'    Datum           :     24.05.2008           
'    Ziel PIC        :     16F877  	
'    Compiler        :     iL_BAS16 - Professional  V5.7-10  23.11.2007 
'    
'***********************************************************************
'*****                Definitionen und Konstanten                  *****
'***********************************************************************

Date
Time

$NCALDEF

'$LIST BIN          'erzeugt zusätzlich eine Binärdatei 
'$LIST OBJ2HEX      'das Hexfile bekommt anstatt OBJ die Dateiendung HEX   

define device 16F877, hs_osc, pwrte_off, wdt_off, protect_off, boden_on,{+}
                      psa1, psv7,lvp_off, t0cs_int, adcfg0,R
                     

xtal 4.0 

'$debug 3,ra,4
                      
tris ra,%111111
tris rb,%00000000          
tris rc,%11111111    
tris rd %11111111
tris re %111

output rb,%00000000

define U_limit       = $40  as word    'Spannungslimit in mV
define U_limitL      = $40  as byte    'Zugriff Lowbyte  der 16-Bit-Var
define U_limitH      = $41  as byte    'Zugriff Highbyte der 16-Bit-Var

define I_limit       = $42  as word    'Stromlimit in mA        
define I_limitL      = $42  as byte    'Zugriff Lowbyte  der 16-Bit-Var
define I_limitH      = $43  as byte    'Zugriff Highbyte der 16-Bit-Var 

define TL_trafo      = $44  as byte    'Temperatur Limit Trafo
define TL_sink       = $45  as byte    'Temperatur Limit Kühlkörper 
define TL_fan_min    = $47  as byte    'min. Temperatur Limit Lüfter
define TL_fan_max    = $48  as byte    'max. Temperatur Limit Lüfter
define T_trafo       = $49  as byte    'in °C          
define T_sink        = $4A  as byte    'in °C

define Grad          = auto as byte    'Anzeige ° auf LCD-Display        
define Omega         = auto as byte    'Anzeige Ohmzeichen auf LCD-Display
define menu          = auto as byte    'Menu-auswahl
define aa1           = auto as word    'Hilfsvariablen        
define aa2           = auto as word
define aa3           = auto as word
define ww1           = auto as word
define ww2           = auto as word
define ww3           = auto as word
define ww4           = auto as word
define mm            = auto as byte

define Volt          = auto as word    'in mV
define Ampere        = auto as word    'in mA
define Watt          = auto as word    'in mW 
define Ohm           = auto as word    'in Ohm         
define Temperatur    = auto as word    'in °C

define power_relais  = rb,7       'Ausgangsspannung EIN / Aus
define fan_relais    = rb,6       'Lüfter EIN / AUS 

define t_down        = rc,0       'Taste down
define t_up          = rc,1       'Taste up
define t_enter       = rc,2       'Taste enter
define m_display     = rc,3       'Taste Mode Display
define t_relais_off  = rc,4       'Taste Power-Relais aus                                 
define t_relais_on   = rc,5       'Taste Power-Relais ein 

goto main                         'Start Hauptprogramm

'***********************************************************************
'*****                   Unterprogramme                            *****
'***********************************************************************

init:                        'Variablen & LCD initalisieren
  
  wait 1000
  
  lcdinit rb,4,20
  lcdclear    '"12345678901234567890"         
  lcdwrite 1,1," Power-Panel-Meter  "
  lcdwrite 2,1,"    designed by     "
  lcdwrite 3,1,"  Sebastian Glatt   "
  lcdwrite 4,1,"  Peter Verderber   "

  output rb,%00000000
          
  let Grad       = 223       'Grad Zeichen
  let Omega      = 244       'Ohm  Zeichen 
  let menu       = 0
  let Volt       = 0
  let Ampere     = 0
  let Ohm        = 0            
  let Watt       = 0 
  let Temperatur = 0
  let T_trafo    = 0          
  let T_sink     = 0 
  let aa1        = 0
  let aa2        = 0
  let aa3        = 0
  let ww1        = 0
  let ww2        = 0
  let ww3        = 0
  let ww4        = 0
  let mm         = 0        
  
  gosub read_U_limit         'EEPROM Daten auslesen
  gosub read_I_limit 
  read 4,TL_trafo               
  wait 15
  read 5,TL_sink                 
  wait 15
 
  let TL_fan_max = TL_sink - 20
  let TL_fan_min = TL_sink - 30
 
  return        
 
'-----------------------------------------------------------------------
'Grenzwerte im PIC-EEPROM speichern bzw. aus PIC-EEPROM auslesen                           

store_U_limit:                      'abspeichern der 16-Bit-Variable,
  write 0,U_limitL                  'zuerst das Low-Byte 
  wait 15
  write 1,U_limitH                  'dann das High-Byte 
  wait 15
  return       

read_U_limit:                       'lesen der 16-Bit-Variable,
  read 0,U_limitL                   'zuerst das Low-Byte 
  wait 15
  read 1,U_limitH                   'dann das High-Byte 
  wait 15
  return       
    
store_I_limit:                      'abspeichern der 16-Bit-Variable,
  write 2,I_limitL                  'zuerst das Low-Byte 
  wait 15
  write 3,I_limitH                  'dann das High-Byte 
  wait 15
  return       

read_I_limit:                       'lesen der 16-Bit-Variable,
  read 2,I_limitL                   'zuerst das Low-Byte 
  wait 15
  read 3,I_limitH                   'dann das High-Byte 
  wait 15
  return       

'-----------------------------------------------------------------------
'Menü Vorgabe der Grenzwerte

menu_Limits:                 

gosub Uout_off
lcdclear
let menu = 0
let mm   = 1

  loop_menu:    '"12345678901234567890"
    lcdwrite 1,1," VORGABE GRENZWERTE "
    lcdwrite 2,1,"                    "
    if t_up = 0 then wait 10
    if t_up = 0 then let menu = menu + 1         
    if menu > 1 then let menu = 1
    on menu gosub m_disp0, m_disp1 
    
    if t_down = 0 then wait 10 
    if t_down = 0 then let menu = menu - 1
    if menu   > 1 then let menu = 0
    on menu gosub m_disp0, m_disp1
        
    if t_enter = 0 then wait 10     
    if t_enter = 0 then goto exit_loop_menu 
    
  goto loop_menu  
 
  
  m_disp0:      '"12345678901234567890"
    lcdwrite 3,1,"> U & I Limits      "
    lcdwrite 4,1,"  Temperatur Limits "
    return
    
  m_disp1:
    lcdwrite 3,1,"  U & I Limits      "
    lcdwrite 4,1,"> Temperatur Limits "
    return

  exit_loop_menu:      
    on menu goto U_I_Limits, Heat_Limits    
      
    return

'-----------------------------------------------------------------------  
'Eingabe der Grenzwerte für U & I mit Plausibilitätskontrolle

U_I_Limits:                  

  gosub read_U_limit         'PIC-EEPROM Daten auslesen
  gosub read_I_limit 
                
  lcdclear    '"12345678901234567890"
  lcdwrite 1,1,"U & I Limits        "
  lcdwrite 4,1,"  I-Limit          A"
  lcdwrite 4,14,I_limit,:2       
  
  
  loop_U:                    'Grenzwert für U                 
    lcdwrite 3,1,"> U-Limit          V" 
    lcdwrite 3,14,U_limit,:1    
    if t_up = 0 then wait 10
    if t_up = 0 then let U_limit = U_limit + 5
    lcdwrite 3,14,U_limit,:1
    if U_limit > 500 then let U_limit = 500
    lcdwrite 3,14,U_limit,:1
       
    if t_down = 0 then wait 10
    if t_down = 0 then let U_limit = U_limit - 5
    lcdwrite 3,14,U_limit,:1
    if U_limit < 10 then let U_limit = 10
    lcdwrite 3,14,U_limit,:1  
    wait 100
    
    if t_enter = 0 then wait 10
    if t_enter = 0 then goto exit_loop_U        
  goto loop_U
  
  exit_loop_U:
    lcdwrite 3,1,"  U-Limit          V"
    lcdwrite 3,14,U_limit,:1
    
  
  loop_I:                    'Grenzwert für I
    lcdwrite 4,1,"> I-Limit          A"
    lcdwrite 4,14,I_limit,:2
    if t_up = 0 then wait 10
    if t_up = 0 then let I_limit = I_limit + 5
    lcdwrite 4,14,I_limit,:2
    if I_limit > 500 then let I_limit = 500
    lcdwrite 4,14,I_limit,:2
    
    if t_down = 0 then wait 10
    if t_down = 0 then let I_limit = I_limit - 5
    lcdwrite 4,14,I_limit,:2
    if I_limit < 10 then let I_limit = 10
    lcdwrite 4,14,I_limit,:2  
    wait 100
      
    if t_enter = 0 then wait 10
    if t_enter = 0 then goto exit_loop_I        
  goto loop_I
  
  exit_loop_I:
    lcdwrite 4,1,"  I-Limit          A"
    lcdwrite 4,14,I_limit,:2
  
  
  loop_U_I_Limits:
    wait 100        
    if t_enter = 0 then wait 10
    if t_enter = 0 then goto loop_U
    
    if m_display = 0 then wait 10
    if m_display = 0 then goto exit_U_I_Limits 
  goto loop_U_I_Limits 
  
  exit_U_I_Limits:      'Speicherung der Limits für U & I im PIC-EEPROM
    gosub store_U_limit
    gosub store_I_limit
    
    lcdclear
  return
  
'----------------------------------------------------------------------- 
'Eingabe der Grenzwerte für die Temperaturen mit Plausibilitätskontrolle 

Heat_Limits:       

  read 4,TL_trafo  'PIC-EEPROM Daten auslesen             
  wait 15
  read 5,TL_sink                 
  wait 15
  
              '"12345678901234567890"  
  lcdwrite 1,1," Temperatur Limits  "
  lcdwrite 3,1,"  Transistor       C"
  lcdwrite 3,19,Grad,#
  lcdwrite 3,16,TL_sink      
  lcdwrite 4,1,"  Ventilator       C"
  lcdwrite 4,19,Grad,#
  lcdwrite 4,16,TL_fan_max

  
  loop_trafo:                'Grenzwert für Temperatur Trafo
    lcdwrite 2,1,"> Trafo            C"
    lcdwrite 2,16,TL_trafo
    lcdwrite 2,19,Grad,#
    if t_up = 0 then wait 10
    if t_up = 0 then let TL_trafo = TL_trafo + 1
    lcdwrite 2,16,TL_trafo
    if 	TL_trafo > 100 then let TL_trafo = 100
    lcdwrite 2,16,TL_trafo
    
    if t_down = 0 then wait 10
    if t_down = 0 then let TL_trafo = TL_trafo - 1
    lcdwrite 2,16,TL_trafo
    if TL_trafo < 40 then let TL_trafo = 40
    lcdwrite 2,16,TL_trafo  
    wait 100
     
    if t_enter = 0 then wait 10
    if t_enter = 0 then goto exit_loop_trafo      
  goto loop_trafo
  
  exit_loop_trafo:
    lcdwrite 2,1,"  Trafo            C"
    lcdwrite 2,19,Grad,#
    lcdwrite 2,16,TL_trafo

  
  loop_sink:                 'Grenzwert für Temperatur Kühlkörper
    lcdwrite 3,1,"> Transistor       C"
    lcdwrite 3,19,Grad,#
    lcdwrite 3,16,TL_sink
    if t_up = 0 then wait 10
    if t_up = 0 then let TL_sink = TL_sink + 1
    lcdwrite 3,16,TL_sink
    if TL_sink > 120 then let TL_sink = 120
    lcdwrite 3,16,TL_sink
    
    if t_down = 0 then wait 10
    if t_down = 0 then let TL_sink = TL_sink - 1
    lcdwrite 3,16,TL_sink
    if TL_sink < 40 then let TL_sink = 40
    lcdwrite 3,16,TL_sink  
    wait 100
    
    if t_enter = 0 then wait 10
    if t_enter = 0 then goto exit_loop_sink        
  goto loop_sink
  
  exit_loop_sink:
    lcdwrite 3,1,"  Transistor       C"
    lcdwrite 3,19,Grad,#
    lcdwrite 3,16,TL_sink
      
  
  loop_fan:                  'Grenzwert für Temperatur Lüfter
    
    let TL_fan_max = TL_sink - 20
         
    lcdwrite 4,1,"> Ventilator       C"
    lcdwrite 4,19,Grad,#
    lcdwrite 4,16,TL_fan_max
    
    if t_enter = 0 then wait 10
    if t_enter = 0 then goto exit_loop_fan        
  goto loop_fan
  
  exit_loop_fan:
    lcdwrite 4,1,"  Ventilator       C"
    lcdwrite 4,19,Grad,#
    lcdwrite 4,16,TL_fan_max
  
   
  loop_TL_Limits:
    wait 100  
    if t_enter = 0 then wait 10
    if t_enter = 0 then goto loop_trafo
    
    if m_display = 0 then wait 10
    if m_display = 0 then goto exit_Heat_Limit 
  goto loop_TL_Limits 
  
   
  exit_Heat_Limit:
    write 4,TL_trafo  'Speicherung der Temperaturen im PIC-EEPROM            
    wait 15
    write 5,TL_sink                 
    wait 15
        
    lcdclear
  return
  
'-----------------------------------------------------------------------  
'Messen-Routine für U, I und alle Temperaturen
'Berechnun von P und R 
'Anzeige der Messwerte und Grenzwertüberschreitungen

messen:            
                             
  addelay 250                          'Messung Spannung in V
  adinp 1, Volt
  let aa1  = Volt * 48
  let aa2  = Volt * 8 / 10
  let aa3  = Volt * 3 / 100
  let Volt = aa1 + aa2 +aa3
  let Volt = Volt / 100
  lcdwrite 1,3,Volt,:1
  if Volt  > U_limit then gosub error_Uout else gosub clear_line3
    
  addelay 250                          'Messung Strom in A
  adinp 0, Ampere
  let aa1    = Ampere * 48
  let aa2    = Ampere * 8 / 10
  let aa3    = Ampere * 3 / 100 
  Let Ampere = aa1 + aa2 +aa3
  let Ampere = Ampere / 100
  lcdwrite 1,14,Ampere,:2
  if Ampere  > I_limit then gosub error_Iout else gosub clear_line3
  
  Let ww1  = Ampere / 100              'Leistung = U * I in Watt
  let ww2  = Ampere mod 100
  let ww3  = Volt * ww1    
  let ww4  = Volt * ww2 / 100
  Let Watt = ww3  + ww4
  lcdwrite 2,3,Watt,:1
 
  let aa1 = Volt * 100                 'Widerstand = U / I in Ohm
  let Ohm = aa1 / Ampere
  lcdwrite 2,14,Ohm,:1
  if Ohm > 6000 then lcdwrite 2,14,"   -.-"
 
  addelay 250                          'Messung Kühlkörper-Temperatur 
  adinp 2, Temperatur                   
  gosub calc_Temp
  let T_sink = Temperatur
  if T_sink > TL_sink then gosub error_T_sink else gosub clear_line3
  
  addelay 250                          'Messung Trafo-Temperatur
  adinp 3, Temperatur                  
  gosub calc_Temp
  let T_trafo = Temperatur 
  if T_trafo > TL_trafo then gosub error_T_trafo else gosub clear_line3
  
  
  let TL_fan_max = T_sink - 20         'Ein- und Ausschaltschwelle 
  let TL_fan_min = T_sink - 30         'für den Lüfter
  
  if T_sink > TL_fan_max then set fan_relais 
  if T_sink < TL_fan_min then res fan_relais
  
  return

calc_Temp:                             'Temperatur in °C                          
  let Temperatur = Temperatur * 63 / 100
  let Temperatur = Temperatur - 150
  if  Temperatur > 1000 then let Temperatur = 20
     
  return

'-----------------------------------------------------------------------

Dimension:                   'Anzeige der Dimensionen der Messwerte

               '"12345678901234567890"               
  lcdwrite 1,1,"U:      V  I:      A"
  lcdwrite 2,1,"P:      W  R:      "
  lcdwrite 2,20,Omega,#  

  return 

clear_line3:
              '"12345678901234567890"               
  lcdwrite 3,1,"                    "
  return

'----------------------------------------------------------------------- 
' Anzeigeroutinen für Grenzwertüberschreitungen und Stautsmeldungen

error_T_trafo:               'Trafo-Temperatur überschritten
  gosub Uout_off
  lcdwrite 3,1,"Trafo >>           C"
  lcdwrite 3,19,Grad,#
  lcdwrite 3,16,T_trafo
  wait 2000
  return
  
error_T_sink:                'Kühlkörper-Temperatur überschritten
  gosub Uout_off
  lcdwrite 3,1,"Transistor >>      C"
  lcdwrite 3,19,Grad,#
  lcdwrite 3,16,T_sink      
  wait 2000
  return
  
error_Uout:                  'Ausgangsspannung überschritten
  gosub Uout_off
  lcdwrite 3,1,"Uout >> Limit      V" 
  lcdwrite 3,14,U_limit,:1    
  wait 2000
  return
  
error_Iout:                  'Ausgangsstrom überschritten
  gosub Uout_off
  lcdwrite 3,1,"Iout >> Limit      A" 
  lcdwrite 3,14,I_limit,:2    
  wait 2000
  return

Uout_on:                     'Ausgangsspannung eingeschaltet
  set power_relais
  gosub clear_line3 
  lcdwrite 4,1,"Uout EIN -o-o-      " 
  return
  
Uout_off:                    'Ausgangsspannung ausgeschaltet             
  res power_relais
  gosub clear_line3
  lcdwrite 4,1,"Uout AUS -o/o-      "
  return

'***********************************************************************
'*****                     Hauptprogramm                           *****
'***********************************************************************

main:
  gosub init                 'Variablen initialisieren
  wait 2000
   
  lcdclear                   'LCD-Anzeige der Dimensionen und des Status 
  gosub Uout_off
  gosub Dimension 
     
  loop:
  
    gosub messen                                 'Messen-Routine
      
    if t_relais_on  = 0 then wait 10             'Ausgangsspannung EIN
    if t_relais_on  = 0 then gosub Uout_on
    
    if t_relais_off = 0 then wait 10             'Ausgangspannung AUS
    if t_relais_off = 0 then gosub Uout_off
    
    if m_display = 0 then wait 10                'Menü-Routine Limits
    if m_display = 0 then gosub menu_Limits
    
    if  mm = 1 then gosub Dimension              'Anzeige der Dimensionen 
    if  mm = 1 then gosub Uout_off
    let mm = 0
    
    wait 100
     
  goto loop
  
  goto main       
  end                        'Ende gut, alles gut       
        
       
Post Reply