[X] Testprogramm 11 (Watchdog, Vorteiler)

This commit is contained in:
Mike Schwörer 2017-05-16 17:52:02 +02:00
parent 405b82d086
commit d4a9569693
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
7 changed files with 78 additions and 50 deletions

View File

@ -110,8 +110,9 @@
this.btnClockStart = new System.Windows.Forms.Button();
this.edCLockFreq = new System.Windows.Forms.TextBox();
this.WakeUpButton = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.btnWD1 = new System.Windows.Forms.Button();
this.btnWD0 = new System.Windows.Forms.Button();
this.tbWD = new System.Windows.Forms.TextBox();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -835,33 +836,42 @@
this.WakeUpButton.UseVisualStyleBackColor = true;
this.WakeUpButton.Click += new System.EventHandler(this.button1_Click);
//
// button1
// btnWD1
//
this.button1.Location = new System.Drawing.Point(341, 18);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(126, 23);
this.button1.TabIndex = 64;
this.button1.Text = "Watchdog An";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
this.btnWD1.Location = new System.Drawing.Point(341, 18);
this.btnWD1.Name = "btnWD1";
this.btnWD1.Size = new System.Drawing.Size(126, 23);
this.btnWD1.TabIndex = 64;
this.btnWD1.Text = "Watchdog An";
this.btnWD1.UseVisualStyleBackColor = true;
this.btnWD1.Click += new System.EventHandler(this.button1_Click_1);
//
// button2
// btnWD0
//
this.button2.Location = new System.Drawing.Point(341, 48);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(126, 23);
this.button2.TabIndex = 65;
this.button2.Text = "Watchdog Aus";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
this.btnWD0.Location = new System.Drawing.Point(341, 48);
this.btnWD0.Name = "btnWD0";
this.btnWD0.Size = new System.Drawing.Size(126, 23);
this.btnWD0.TabIndex = 65;
this.btnWD0.Text = "Watchdog Aus";
this.btnWD0.UseVisualStyleBackColor = true;
this.btnWD0.Click += new System.EventHandler(this.button2_Click);
//
// tbWD
//
this.tbWD.Location = new System.Drawing.Point(474, 18);
this.tbWD.Name = "tbWD";
this.tbWD.Size = new System.Drawing.Size(58, 20);
this.tbWD.TabIndex = 66;
this.tbWD.Text = "18.0";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1298, 692);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.tbWD);
this.Controls.Add(this.btnWD0);
this.Controls.Add(this.btnWD1);
this.Controls.Add(this.WakeUpButton);
this.Controls.Add(this.edCLockFreq);
this.Controls.Add(this.btnClockStart);
@ -1015,8 +1025,9 @@
private System.Windows.Forms.Button btnClockStart;
private System.Windows.Forms.TextBox edCLockFreq;
private System.Windows.Forms.Button WakeUpButton;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
private System.Windows.Forms.Button btnWD1;
private System.Windows.Forms.Button btnWD0;
private System.Windows.Forms.TextBox tbWD;
}
}

View File

@ -2,6 +2,7 @@
using PIC_Simulator.Properties;
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows.Forms;
@ -12,8 +13,8 @@ namespace PIC_Simulator
{
private PICProgramm programm;
private Timer quartztimer;
private RS232Verbindung rs232 = new RS232Verbindung();
public Timer quartztimer;
public RS232Verbindung rs232 = new RS232Verbindung();
public Form1()
{
@ -41,6 +42,7 @@ namespace PIC_Simulator
lvSpecial.Items.Add(new ListViewItem(new[] { "Status[DC]", "0" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Status[C]", "0" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Status[Z]", "0" }));
lvSpecial.Items.Add(new ListViewItem(new[] { "Watchdog timer", "0ms" }));
}
private void Form1_Load(object sender, EventArgs e)
@ -49,7 +51,7 @@ namespace PIC_Simulator
box_CodeView.Text = Resources.TPicSim1;
programm = new PICProgramm();
programm = new PICProgramm(this);
programm.Laden(Resources.TPicSim1);
OberflaecheAktualisieren();
@ -76,7 +78,7 @@ namespace PIC_Simulator
box_CodeView.Text = datei;
programm = new PICProgramm();
programm = new PICProgramm(this);
programm.Laden(datei);
OberflaecheAktualisieren();
@ -125,7 +127,7 @@ namespace PIC_Simulator
{
quartztimer.Stop();
programm = new PICProgramm();
programm = new PICProgramm(this);
programm.Laden(box_CodeView.Text);
rs232.Disconnect();
@ -204,6 +206,7 @@ namespace PIC_Simulator
lvSpecial.Items[7].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_C) ? "1" : "0";
lvSpecial.Items[8].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_DC) ? "1" : "0";
lvSpecial.Items[9].SubItems[1].Text = programm.GetRegisterOhneBank(PICProgramm.ADDR_STATUS, PICProgramm.STATUS_BIT_Z) ? "1" : "0";
lvSpecial.Items[10].SubItems[1].Text = string.Format("{0:0.000}ms", programm.WatchDog.time * 1000);
lbStack.Items.Clear();
foreach (var u in programm.Stack) lbStack.Items.Add(u.ToString());
@ -246,6 +249,8 @@ namespace PIC_Simulator
btn_RB_Tris_6.Text = (programm.GetRegisterOhneBank(PICProgramm.ADDR_TRIS_B, 6) ? "i" : "o");
btn_RB_Tris_7.Text = (programm.GetRegisterOhneBank(PICProgramm.ADDR_TRIS_B, 7) ? "i" : "o");
if (btnWD1.Font.Bold != programm.WatchDog.Aktiviert) btnWD1.Font = new Font(btnWD1.Font, programm.WatchDog.Aktiviert ? FontStyle.Bold : FontStyle.Regular);
if (btnWD0.Font.Bold == programm.WatchDog.Aktiviert) btnWD0.Font = new Font(btnWD0.Font, programm.WatchDog.Aktiviert ? FontStyle.Regular : FontStyle.Bold);
}
private void box_CodeView_DoubleClick(object sender, EventArgs e)
@ -508,11 +513,13 @@ namespace PIC_Simulator
private void btnRSConnect_Click(object sender, EventArgs e)
{
rs232.Connect(cbxComPorts.SelectedItem.ToString(), edRS232Log, programm, this);
OberflaecheAktualisieren();
}
private void btnRSDisconnect_Click(object sender, EventArgs e)
{
rs232.Disconnect();
OberflaecheAktualisieren();
}
private void btnClockStart_Click(object sender, EventArgs e)
@ -522,21 +529,26 @@ namespace PIC_Simulator
programm.TaktgeberZahler = 0;
programm.TaktgeberAdresse = Convert.ToUInt32(edClockAddr.Text.Substring(2), 16);
programm.TaktgeberBitnummer = uint.Parse(edClockBit.Text);
OberflaecheAktualisieren();
}
private void button1_Click(object sender, EventArgs e)
{
programm.IsSleeping = false; //Kein WatchdogTimer implementiert, Sleep durch button deaktiviert
}
OberflaecheAktualisieren();
}
private void button1_Click_1(object sender, EventArgs e)
{
programm.WatchDog.TimeOut = double.Parse(tbWD.Text, CultureInfo.InvariantCulture) / 1000d;
programm.WatchDog.Aktiviert = true;
OberflaecheAktualisieren();
}
private void button2_Click(object sender, EventArgs e)
{
programm.WatchDog.Aktiviert = false;
OberflaecheAktualisieren();
}
}
}

View File

@ -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;
}

View File

@ -1,7 +1,7 @@

namespace PIC_Simulator.PIC
{
class PICTimer
public class PICTimer
{
private PICProgramm programm;

View File

@ -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);
}
}
}

View File

@ -6,7 +6,7 @@ using System.Windows.Forms;
namespace PIC_Simulator.PIC
{
class RS232Verbindung
public class RS232Verbindung
{
private SerialPort ComPort;
private PICProgramm Programm;

View File

@ -23,7 +23,7 @@
[ ] Testprogramm 7 (Interrupts)
[ ] Testprogramm 9 (Sleep-Befehl)
[X] Testprogramm 10 (PCL und PCLATH)
[ ] Testprogramm 11 (Watchdog, Vorteiler)
[X] Testprogramm 11 (Watchdog, Vorteiler)
[ ] Testprogramm 12 (EEPROM)
[ ] Zusätzliche eignene Features
[ ] Vorzeitige Abgabe