[X] Testprogramm 11 (Watchdog, Vorteiler)
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace PIC_Simulator.PIC
|
||||
{
|
||||
class PICBefehl
|
||||
public class PICBefehl
|
||||
{
|
||||
public string befehl;
|
||||
public uint parameter_d;
|
||||
@@ -19,7 +19,7 @@ namespace PIC_Simulator.PIC
|
||||
public int zeilennummer;
|
||||
}
|
||||
|
||||
class PICProgramm
|
||||
public class PICProgramm
|
||||
{
|
||||
public const uint ADDR_INDF = 0x00;
|
||||
public const uint ADDR_TMR0 = 0x01;
|
||||
@@ -132,10 +132,10 @@ namespace PIC_Simulator.PIC
|
||||
public PICTimer Zaehler;
|
||||
public PICWatchDog WatchDog;
|
||||
|
||||
public PICProgramm()
|
||||
public PICProgramm(Form1 f)
|
||||
{
|
||||
Zaehler = new PICTimer(this);
|
||||
WatchDog = new PICWatchDog(this);
|
||||
WatchDog = new PICWatchDog(this, f);
|
||||
|
||||
// Anfangswerte
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace PIC_Simulator.PIC
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSleeping) { WatchDog.Aktualisieren(1, frequenz); return false;}
|
||||
if (IsSleeping) { WatchDog.Aktualisieren(1); return false;}
|
||||
|
||||
uint cycleCount = 1;
|
||||
|
||||
@@ -357,6 +357,7 @@ namespace PIC_Simulator.PIC
|
||||
if (Cond)
|
||||
{
|
||||
PCCounter++; // skip next
|
||||
cycleCount = 2;
|
||||
}
|
||||
}
|
||||
else if (aktueller_befehl.befehl == INCF)
|
||||
@@ -406,6 +407,7 @@ namespace PIC_Simulator.PIC
|
||||
if (Cond)
|
||||
{
|
||||
PCCounter++; // skip next
|
||||
cycleCount = 2;
|
||||
}
|
||||
}
|
||||
else if (aktueller_befehl.befehl == IORWF)
|
||||
@@ -594,6 +596,7 @@ namespace PIC_Simulator.PIC
|
||||
if (!GetBit(GetRegister(aktueller_befehl.parameter_f), aktueller_befehl.parameter_b))
|
||||
{
|
||||
PCCounter++;
|
||||
cycleCount = 2;
|
||||
}
|
||||
}
|
||||
else if (aktueller_befehl.befehl == BTFSS)
|
||||
@@ -607,6 +610,7 @@ namespace PIC_Simulator.PIC
|
||||
if (GetBit(GetRegister(aktueller_befehl.parameter_f), aktueller_befehl.parameter_b))
|
||||
{
|
||||
PCCounter++;
|
||||
cycleCount = 2;
|
||||
}
|
||||
}
|
||||
else if (aktueller_befehl.befehl == ADDLW)
|
||||
@@ -806,7 +810,7 @@ namespace PIC_Simulator.PIC
|
||||
|
||||
Zaehler.TimerBerechnen(cycleCount);
|
||||
|
||||
WatchDog.Aktualisieren(cycleCount, frequenz);
|
||||
WatchDog.Aktualisieren(cycleCount);
|
||||
|
||||
return PCCounter >= befehle.Count;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace PIC_Simulator.PIC
|
||||
{
|
||||
class PICTimer
|
||||
public class PICTimer
|
||||
{
|
||||
private PICProgramm programm;
|
||||
|
||||
|
@@ -1,31 +1,36 @@
|
||||
|
||||
namespace PIC_Simulator.PIC
|
||||
{
|
||||
class PICWatchDog
|
||||
public class PICWatchDog
|
||||
{
|
||||
private PICProgramm programm;
|
||||
|
||||
private const double TIME_OUT = 0.018; // 18ms;
|
||||
public double TimeOut = 0.018; // ms;
|
||||
|
||||
private const double FREQUENCY = 4000000d; // 4 MHz
|
||||
|
||||
public uint Prescale = 1;
|
||||
|
||||
private double time; // in s
|
||||
public double time; // in s
|
||||
|
||||
public bool Aktiviert = false;
|
||||
|
||||
public PICWatchDog(PICProgramm p)
|
||||
private Form1 form;
|
||||
|
||||
public PICWatchDog(PICProgramm p, Form1 frm)
|
||||
{
|
||||
programm = p;
|
||||
time = 0;
|
||||
form = frm;
|
||||
}
|
||||
|
||||
public void Aktualisieren(uint cycles, float frequenz)
|
||||
public void Aktualisieren(uint cycles)
|
||||
{
|
||||
if (Aktiviert)
|
||||
{
|
||||
time += (1.0 / frequenz) * cycles;
|
||||
time += (1.0 / FREQUENCY) * cycles;
|
||||
|
||||
if (time > TIME_OUT * GetPreScale())
|
||||
if (time > TimeOut * GetPreScale())
|
||||
{
|
||||
WDReset();
|
||||
}
|
||||
@@ -46,6 +51,7 @@ namespace PIC_Simulator.PIC
|
||||
|
||||
programm.Reset();
|
||||
programm.SetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_TO, false);
|
||||
form.quartztimer.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -77,10 +83,5 @@ namespace PIC_Simulator.PIC
|
||||
{
|
||||
time = 0;
|
||||
}
|
||||
|
||||
public double GetPerc()
|
||||
{
|
||||
return time / (TIME_OUT * Prescale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ using System.Windows.Forms;
|
||||
|
||||
namespace PIC_Simulator.PIC
|
||||
{
|
||||
class RS232Verbindung
|
||||
public class RS232Verbindung
|
||||
{
|
||||
private SerialPort ComPort;
|
||||
private PICProgramm Programm;
|
||||
|
Reference in New Issue
Block a user