REGOLATORE UNIVERSALE

 

Lo schema si riferisce ad un regolatore con CUBLOC CB280 ed alcuni kit di FUTURA ELETTRONICA, secondo lo schema seguente:

 

K8067 è un sensore di temperatura fra -23 e 77’C basato sul componente LM335.

K8064 è un dimmer con carico in alternata max di 375 watt ( ad esempio una lampada da 100 watt) comandato da una tensione continua tarato con tensione minima di 0 e massima di 5 V DC)

 

Il CUBLOC rileva la temperatura attraverso la porta ADC 3, pin 27.

L’uscita PWM0 ,porta 5 è collegata all’ingresso in  tensione di comando del DIMMER

Le porte ADC4,ADC5,ADC6 dei pin 28,29,30 rilevano attraverso potenziometri

 

Per i potenziometri si è fatto ricorso a quelli in dotazione alla studyboard

Le porte p0 e p1 leggono lo stato degli interruttori on-off. Si è fatto ricorso anche in questo caso a quelli in dotazione alla studyboard.

Lo stato degli interruttori determina il tipo di regolazione

Il regolatore all’avvio rileva il tipo di regolazione ed i parametri impostati.

Successivamente esegue un loop ogni  1 secondo di rilevazione della temperatura e di esecuzione della regolazione impostata.

La visualizzazione dei dati(la temperatura, il carico, i valori impostati) può avvenire sul monitor

Output sul monitor

 

 

oppure sul PC. Il cubloc trasmette i dati attraverso la porta seriale al PC ed un programma in DELPHI li legge e visualizza il grafico della temperatura

 

Il grafico sul PC con DELPHI

 

 

 

Lo schema circuitale

 

 

 

 

 

La scatola contenente  i kit k8067 , K8064 ,l’attacco alla lampada e l’uscita del sensore

 

 

 

 

Le prove sono state effettuate semplicemente avvicinando la sonda ad una distanza opportuna dalla lampada

 

 

Il listato nel BASIC del CUBLOC

 

Const Device = CB280

Dim tempo As Single

Dim dw As Single

Dim pwm_out As Single

Dim area As Single

Dim area_t As Single

Dim kp As Single

Dim ki As Single

Dim lux As Integer

Dim intervallo As Integer

Dim setpoint As Single

Dim bandap As Single

Dim tempoint As Single

Dim old As Single

Dim uscita As Byte

Dim Contatore As Integer

Dim tempm As Single

Dim tiporegolazione As Byte

Dim max_uscita As Integer

Dim menouno As Single

Dim tipouscita As Byte

Dim r As Single

Dim scostamento As Single

Set Debug Off

tipouscita =1

intervallo=1000

menouno=-1

tempo=0

max_uscita=1023

Low 5

area_t=0

Debug CLR

Debug "avvio..."

lettura_tipo

Do

uscita=In(4)

If uscita=1 Then Goto fine

lettura_tipo

old=tempm

Debug Goxy,1,6

Debug "SP="

Debug Fp(setpoint,3,1)

tempm=20*inp_analogico(3)-23

 

Out 2,0

Debug " t="

Debug Fp(tempm,3,1)

scostamento=tempm-setpoint

If tempm>setpoint Then

Debug " DT="

Debug Fp(tempm-setpoint,2,2)

End If

If tempm<setpoint Then

Debug " DT=-"

Debug Fp(setpoint-tempm,2,2)

End If

Debug Goxy,1,7

If tempm>=setpoint-bandap/2  And tempm<=setpoint+bandap/2 Then Debug " -- "

If tempm>setpoint+bandap/2 Then Debug " >>"

If tempm<setpoint-bandap/2 Then Debug " <<"

If tiporegolazione=2 Then

Debug Goxy,1,8

If setpoint>tempm Then

r=(setpoint-tempm)*intervallo/1000

area_t=area_t-r

Debug " area=-"

End If

If tempm>setpoint Then

r=(tempm-setpoint)*intervallo/1000

area_t=area_t-r

Debug " area="

End If

If tempm<setpoint-bandap/2 Then area_t=0

If tempm>setpoint+bandap/2 Then area_t=0

Debug Fp(r,6,1)

Debug " area t="

Debug Fp(area_t,6,1)

Debug " interv ="

Debug Fp(intervallo/1000,6,1)

End If

If tiporegolazione=1 Or tiporegolazione=2 Then

                                                Debug Goxy,1,9

             Debug " azione prop="

                                                            r=azione_prop()

             Debug Fp(r,5,1)

                                                lux=r

             End If

         If tiporegolazione=2 Then

                                    Debug Goxy,1,10

             Debug " azione int ="

                                                r=azione_int()

                                                lux=r

             Debug Fp(r,5,1)

             End If

 

If tiporegolazione=0 Then pwm_out=reg_onoff()

If tiporegolazione=1 Then pwm_out=azione_prop()

If tiporegolazione=2 Then pwm_out=azione_prop()+azione_int()

If tiporegolazione=3 Then pwm_out=azione_flottante()

If pwm_out>max_uscita Then pwm_out=max_uscita

If pwm_out<10 Then pwm_out=10

lux=pwm_out

Pwm 0,lux,1023

If tipouscita=1 Then seriale

Debug Goxy,1,11

Debug "potenza totale="

Debug Fp(lux,4,0)

Debug "    tempo[sec]="

Debug Fp(tempo,7,1)

Delay intervallo

Out 2,1

Delay 100

tempo=tempo+intervallo/1000

Debug Goxy,1,15

 

Loop

fine:

lampeggio 3,2

Debug clr

Debug "fine programma"

End

Sub lampeggio(quanti As Byte,porta As Byte)

Dim i As Byte

For i=1 To quanti

Out porta,1

Delay 500

Out porta,0

Delay 500

Next

Out 2,0

End Sub

Function leggo_setpoint() As Single

Dim voltage As Single

voltage=inp_analogico(4)

leggo_setpoint=20+9*voltage

End Function

Function leggo_bandap() As Single

Dim voltage As Single

voltage=inp_analogico(5)

leggo_bandap=0.5+1.9*voltage

End Function

Function leggo_tempoint() As Single

Dim voltage As Single

voltage=inp_analogico(6)

leggo_tempoint=30+354*voltage

End Function

Sub lettura_tipo()

Dim a As Byte

Dim b As Byte

Dim c As Byte

a=In(0)

b=In(1)

c=In(3)

 

'tiporegolazione =0 on-off

'tiporegolazione =1 P

'tiporegolazione =2 PI

'tiporegolazione =3 flottante

If a=0 And b=0 Then tiporegolazione=0

If a=0 And b=1 Then tiporegolazione=1

If a=1 And b=0 Then tiporegolazione=2

If a=1 And b=1 Then tiporegolazione=3

setpoint=leggo_setpoint()

Debug Goxy,1,1

Select  Case tiporegolazione

Case 0

Debug "regolazione =On-Off"

Case 1

Debug "regolazione =P"

Case 2

Debug "regolazione =PI"

Case 3

Debug "regolazione =flottante"

End Select

bandap=leggo_bandap()

Debug Goxy,1,2

If tiporegolazione=0 Then

Debug "   differenz="

   Debug Fp(bandap,6,3) 

End If

If tiporegolazione=1 Or tiporegolazione=2 Then

            Debug "banda proporzionale="

   Debug Fp(bandap,6,3)           

       kp=menouno*1023/bandap

                        Debug Goxy,1,3

       Debug "kp="

      Debug Fp(kp,6,3)

                         End If

If tiporegolazione>1 Then

tempoint=leggo_tempoint()

Debug Goxy,1,4

End If

If tiporegolazione=2 Then

Debug "tempo integrale="

Debug Fp(tempoint,10,3)

End If

 

r=1023/tempoint

 

If tiporegolazione=3 Then

Debug "tempo corsa="

Debug Fp(tempoint,10,3)

Debug Goxy,1,5

Debug "velocita' incremento potenza="

dw=max_uscita*intervallo/tempoint

Debug Fp(dw,10,3)

End If

ki=1023/(bandap*tempoint)

If tiporegolazione=2  Then

Debug Goxy,1,5

Debug "Ki="

Debug Fp(ki,10,3)

End If

 

End Sub

Function reg_onoff()

Dim vt As Single

If tempm>old Then vt=max_uscita

If tempm<old Then vt=10

If tempm>setpoint+bandap/2 Then vt=10

If tempm<setpoint-bandap/2 Then vt=max_uscita

reg_onoff=vt

End Function

Function azione_prop()

Dim vt As Single

vt=512-max_uscita*(tempm-setpoint)/bandap

If vt<0 Then vt=0

If vt>max_uscita Then vt=max_uscita

azione_prop=vt

End Function

Function  azione_int()

azione_int=-ki*area_t

If tempm>setpoint+bandap/2 Then azione_int=0

If tempm<setpoint-bandap/2 Then azione_int=0

End Function

Function azione_flottante()

Dim vt As Single

If tempm>setpoint Then vt=pwm_out-dw

If tempm<setpoint Then vt=pwm_out+dw

azione_flottante=vt

End Function

Function inp_analogico(port As Integer) As Single

Dim s As Single

Dim rr As Single

Input 24+port

s=Adin(port)

rr=s*5

rr=rr/1024

inp_analogico=rr

End Function

Function lm335(porta As Byte) As Single

Dim voltage As Single

voltage=inp_analogico(porta)

End Function

Sub seriale()

Bclr 0,2

Opencom 0,2400,3,10,60

Dim sinvio As String

sinvio=Fp(tempm,6,3)

Putstr 0,sinvio

sinvio=Fp(setpoint,6,3)

Putstr 0,sinvio

sinvio=Fp(bandap,6,3)

Putstr 0,sinvio

sinvio=Fp(tempoint,6,3)

Putstr 0,sinvio

r=tiporegolazione

sinvio=Fp(r,6,3)

Putstr 0,sinvio

r=100*lux/1023

sinvio=Fp(r,6,3)

Putstr 0,sinvio

lampeggio 3,6

End Sub

 

IL LISTATO IN DELPHI

 

unit cubloc_reg;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, Buttons, XComDrv, ExtCtrls;

 

type

  Tmiocubloc = class(TForm)

    XComm: TXComm;

    BitBtn1: TBitBtn;

    Memo1: TMemo;

    Timer1: TTimer;

    procedure vai(Sender: TObject);

  

    procedure inizia(Sender: TObject);

    procedure rileva_temp(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

type

string10=string[10];

 var

  miocubloc: Tmiocubloc;

  simula,hofatto:boolean;

  tempo:longint;

tempodif,tempocr1,tempocr2:longint;

var Hour, Min, Sec, MSec: Word;

 datetime:tdatetime;

 tempoint,bandap,lux,temperatura_letta,setpoint:real;

 tiporegolazione:byte;

 implementation

 

uses wgraf1g,wgen,wgraf2g,grafgen;

 

{$R *.dfm}

var xCOM:tXComm; { oggetto comunicazione seriale }

procedure grafico_temperatura;

    var n:integer;

s1,S2,s:string;

i:integer;

miny,maxy,minx,maxx:real;

x,y:real;

begin

NUMRIGHE:=0;  num_piani:=1;

iniziagrafico;

periferica:=video;

PIANO_XY(0,15,600,45,'t[sec]','Temp[C]',blu);

utente:=true;    colore(rosso);

end;

procedure proc_grafico;

begin

vfunzdis:=grafico_temperatura;

form8.visualizza;

end;

procedure AttendiRispostaECR(x:tXComm);

  label fine;

  var b:byte;i,j,l:integer;   n:dword;

s1,sc,s2,s3,s:string  ;

sn1,sn2,sn3,sn4,sn5,sn6:string10;

numero:boolean;

temper,tipo:real;cod:integer;

  begin

tempo:=tempo+1;

      x.Paused:=True;

   b:=0;

   s3:='';

     sn1:='';sn2:='';sn3:='';sn4:='';sn5:='';sn6:='';

  for i:=1 to 6 do begin

    for j:=1 to 10 do begin

    x.ReadByte(b);s3:=chr(b);

 if i=1 then sn1:=sn1+s3;

 if i=2 then sn2:=sn2+s3;

 if i=3 then sn3:=sn3+s3;

 if i=4 then sn4:=sn4+s3;

 if i=5 then sn5:=sn5+s3;

 if i=6 then sn6:=sn6+s3;

    end;

          end ;

          str(tempo:5,s3);

 

utente:=false;

 val(sn1,temper,cod);

 val(sn2,setpoint,cod);

      val(sn3,bandap,cod);

       val(sn4,tempoint,cod);

          val(sn6,lux,cod);

           val(sn5,tipo,cod);

           str(temper:5:2,sn1);

  str(temper:5:2,sn1); str(setpoint:5:2,sn2);

  str(bandap:5:2,sn3); str(tempoint:6:0,sn4);

   str(tipo:1:0,sn5); str(lux:4:0,sn6);

s:='t='+s3+' Tm='+sn1+' SP='+sn2+' BP='+sn3+' TI='+sn4+' tipo='+sn5+' PWM='+sn6+'                         ';

miocubloc.memo1.lines.add(s);

commento(s);

x.Paused:=False;

utente:=true;

colore(rosso);

mark(tempo,temper,1);

utente:=true;

hofatto:=true;

colore(blu);       utente:=true;

linea(0,setpoint,600,setpoint);

colore(verde);

linea(0,setpoint+bandap/2,600,setpoint+bandap/2);

linea(0,setpoint-bandap/2,600,setpoint-bandap/2);

 

end;

 

 

 

  procedure InviaComandiECR(x:tXComm;s:string);

  var i,j:integer;

      b:byte;

  begin

    { passo la stringa byte per byte }

    j:=length(s);

    for i:=1 to j do begin

        b:=ord(s[i]);

        x.SendByTe(b);

    end;

    { la stringa deve terminare con un chr(13) }

    b:=13;

    x.sendByTe(b);

  end;

 

  function ControllaCollegamentoECR:boolean;

  var b:byte;

      j:integer;

  begin

    result:=False;

    InviaComandiECR(xCOM,'KXCL');

    try

      xCOM.Paused:=True;

      b:=0;

      j:=0;

      { attendo fino a 5 cicli.... poi timeout... }

      while (b<>4) and (j<5) do begin

            xCOM.ReadByte(b);

            if b=4 then result:=True;

            inc(j);

      end;

    finally

      xCOM.Paused:=False;

    end;

  end;

 

procedure Tmiocubloc.vai(Sender: TObject);

begin

hofatto:=false;timer1.interval:=1000;

timer1.enabled:=true;

proc_grafico;

end;

 

 

procedure Tmiocubloc.inizia(Sender: TObject);

begin

tempo:=0;

       left:=0;top:=0;width:=screen.width;

        height:=screen.height;

end;

 

procedure Tmiocubloc.rileva_temp(Sender: TObject);

begin

 

   xCOM:=tXComm.Create(nil);

   xCOM.BaudRate:=br2400;

   xCOM.DataControl.DataBits:=db7;

   xCOM.DeviceName:='com2';

   xCOM.DataControl.StopBits:=sb1;

   xCOM.DataControl.Parity:=paEven;

   xCOM.OpenDevice;

   InviaComandiECR(xCOM,'nulla');

 AttendiRispostaECR(xCOM);

     xCOM.CloseDevice;

   xCOM.Free;

 

end;

end.

 

 

 


 

 taraschi_nicola@libero.it