Drawing realtime graph

Simbad

New Member
Iam trying to draw rpm realtime graph in c#, but I have strange line drop sometimes. I just noticed it happens when I spin it high and i little bit drop rpm, then it shows like huge drop

Capture.JPG



Can someone c# guru check if this programm error or picaxe ?

Code:
main: 
count B.3,1000, w1
sertxd(#w1)
goto main
C# 2010 project View attachment RPM.zip

Code:
namespace RPM
{
    public partial class Form1 : Form
    {
        private const int CHART_SECONDS = 60;
        private Series mySerie;    

        public delegate void AddDataDelegate();
        public AddDataDelegate addDataDel;
    
        public Form1()
        {
            InitializeComponent();
          
            addDataDel += new AddDataDelegate(AddData);

            DateTime minValue = DateTime.Now;
            DateTime maxValue = minValue.AddSeconds(CHART_SECONDS);
            chart1.ChartAreas[0].AxisX.Minimum = minValue.ToOADate();
            chart1.ChartAreas[0].AxisX.Maximum = maxValue.ToOADate();
            chart1.ChartAreas[0].AxisX.LabelStyle.Format = "T";
            chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Minutes;
            chart1.ChartAreas[0].AxisX.Interval = 1;
            chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.DarkGray;
            chart1.ChartAreas[0].AxisX.MinorGrid.IntervalType = DateTimeIntervalType.Seconds;
            chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 10;
            chart1.ChartAreas[0].AxisX.MinorGrid.LineColor = Color.LightGray;
            chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;

            chart1.ChartAreas[0].AxisY.Minimum = 0;
            chart1.ChartAreas[0].AxisY.Maximum = 1000;
            chart1.ChartAreas[0].AxisY.IntervalType = DateTimeIntervalType.Number;
            chart1.ChartAreas[0].AxisY.Interval = 50;
            chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.DarkGray;
            chart1.ChartAreas[0].AxisY.MinorGrid.IntervalType = DateTimeIntervalType.Number;
            chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 50;
            chart1.ChartAreas[0].AxisY.MinorGrid.LineColor = Color.LightGray;
            chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = true;

            chart1.Series.Clear();
            mySerie = new Series("RPM");
            mySerie.ChartType = SeriesChartType.FastLine;
            mySerie.BorderWidth = 1;
            mySerie.Color = Color.Red;
            mySerie.XValueType = ChartValueType.DateTime;
            chart1.Series.Add(mySerie);

            DateTime timeStamp = DateTime.Now;
            chart1.Series[0].Points.AddXY(timeStamp, 0);    
        }

        private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
        chart1.Invoke(addDataDel);           
        }
        
        
        public void AddData()
        {
            DateTime timeStamp = DateTime.Now;
            string stringValue = serialPort1.ReadExisting();
            chart1.Series[0].Points.AddXY(timeStamp, (int.Parse(stringValue)*20)/2);

            double removeBefore = timeStamp.AddSeconds(-CHART_SECONDS).ToOADate();
            while (mySerie.Points[0].XValue < removeBefore)
            {
                mySerie.Points.RemoveAt(0);
            }
            chart1.ChartAreas[0].AxisX.Minimum = mySerie.Points[0].XValue;
            chart1.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(mySerie.Points[0].XValue).AddSeconds(CHART_SECONDS).ToOADate();
            chart1.Invalidate();  

          
        }

        private void button1_Click(object sender, EventArgs e)
        {
          serialPort1.PortName = "COM7";
          serialPort1.BaudRate = 4800;  
          serialPort1.Open();
          if (serialPort1.IsOpen)
          {
              buttonStart.Enabled = false;
              buttonStop.Enabled = true;
        
          }
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
        if (serialPort1.IsOpen)
           {
               serialPort1.Close();
               buttonStart.Enabled = true;
               buttonStop.Enabled = false;
              
           }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen) serialPort1.Close();
        }

    }
}
 
Last edited:

Simbad

New Member
At count time <=500 it works fine, bet when 1-2-3 seconds on high rpms it sometimes counts wrong value. Is it my interrupterer,disk problem?
 

inglewoodpete

Senior Member
While I program microcontrollers in C, I am not familiar with the nuances of C# in PCs.

Would it help if you put a non-numeric character between the numbers being sent by the PICAXE?

Eg sertxd(#w1, CR)

From my experience with Visual Basic 2008 (VB.Net), you need to set the port's data interpretation correctly to get numbers to be understood properly.

I use the following encryption command in VB2008, when opening the serial port:
SerialPort.Encoding = System.Text.Encoding.GetEncoding(28591)

I hope this may be of some help.

Peter
 

Bill.b

Senior Member
hi I used PLX-DAQ serial to excel freeby to generate real time graphs.
this application was for a radar scanner using a SFR005 ultrasonic unit.

hope this may help

picaxe 18m2
servo connected to b.0 (pin 6)
SFR005 output connected to b.3 (pin 9)

Code:
Code:
#picaxe 18m2
#No_Data
pause 1000
setfreq m8

symbol servoCount		= b0
symbol counter1 		= b1			'counter
symbol asciihd		= b2
symbol asciiten		= b3
symbol asciiunit		= b4
Symbol range            = w10			'front range sensor register
Symbol trig 		= b.3			'front range sensor ADC input	
Symbol SERVO1           = b.0			'Pan servo output


Symbol SERVO1_MIDDLE    = 145 
servo servo1,SERVO1_MIDDLE 
main:
	gosub scan1
goto main
scan1:
for counter1 = 1 to 80
	servoCount = counter1+40
	ServoPos SERVO1,servoCount
	pulsout trig,2        		' produces about 20uS pulse (must be minimum of 10uS)
 	pulsin trig,1,range  		' measures the range in 10uS steps
   	pause 10               		' SRF005 mandatory 10mS recharge period after ranging completes
    	let range = range * 10 /29 	' multiply by 10 then divide by 29  (8meg) 
    	bintoascii range,asciihd,asciiten,asciiunit
	sertxd ("DATA,",asciihd,asciiten,asciiunit,13,10)
	pause 200
next counter1
sertxd ("CLEARDATA,",13,10)
return
this is the excel screen

scan.jpg

regards Bill
 
Top