Posts 上位机-VisualScope的使用
Post
Cancel

上位机-VisualScope的使用

VisualScope使用说明(基于stm32)

VisualScope可以通过串口显示波形,方便调节pid参数。

1.添加文件(Visual_Scope.h/.c)

1
2
3
4
5
6
7
8
9
10
11
//.h
#ifndef __VISUAL_SCOPE__
#define __VISUAL_SCOPE__
		 
#include "usart.h"


unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT);
void display(float ch1, float ch2, float ch3, float ch4);

#endif    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//.c
#include "Visual_Scope.h"
void VisualScope_Output(float data1 ,float data2 ,float data3 ,float data4)
{
  int temp[4] = {0};
  unsigned int temp1[4] = {0};
  unsigned char databuf[10] = {0};
  int i;
  unsigned short CRC16 = 0;

  temp[0] = (int)data1;
  temp[1] = (int)data2;
  temp[2] = (int)data3;
  temp[3] = (int)data4;

  temp1[0] = (unsigned int)temp[0];
  temp1[1] = (unsigned int)temp[1];
  temp1[2] = (unsigned int)temp[2];
  temp1[3] = (unsigned int)temp[3];
  
  for(i=0;i<4;i++) 
  {
    databuf[i*2]   = (unsigned char)(temp1[i]%256);
    databuf[i*2+1] = (unsigned char)(temp1[i]/256);
  }
  
	
  CRC16 = CRC_CHECK(databuf, 8);
  databuf[8] = CRC16%256;
  databuf[9] = CRC16/256; 
  for(i=0; i<10; i++)
  {
		while((huart1.Instance->SR & 0x40)==0);
		HAL_UART_Transmit(&huart1, &databuf[i], 1, 0xffff);
		
  }
}

void display(float ch1, float ch2, float ch3, float ch4)
{
	float OutData[4];
	OutData[0] = ch1;
	OutData[1] = ch2;
	OutData[2] = ch3;
	OutData[3] =ch4;
	VisualScope_Output(OutData[0],OutData[1] ,OutData[2] ,OutData[3]);
	//delay_ms(1000);
}


//-------------------------------------------------------------------------------------------
//The following is the function of CRC16,please refer
//-------------------------------------------------------------------------------------------
unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT)
{
    unsigned short CRC_Temp;
    unsigned char i,j;
    CRC_Temp = 0xffff;

    for (i=0;i<CRC_CNT; i++){      
        CRC_Temp ^= Buf[i];
        for (j=0;j<8;j++) {
            if (CRC_Temp & 0x01)
                CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
            else
                CRC_Temp = CRC_Temp >> 1;
        }
    }
    return(CRC_Temp);
}
//-------------------------------------------------------------------------------------------
//The above is the function of CRC16,please refer
//-------------------------------------------------------------------------------------------

2. 软件设置

  • 设置波特率

    0FrwZD.png

  • 选择CRC16校验

    0FroJs.png

  • 在程序调用display(float ch1, float ch2, float ch3, float ch4),显示想要输出波形的数字。

0FyPhj.png

This post is licensed under CC BY 4.0 by the author.