uCGUI示波器软件模拟示波器触发电平

今天早上把代码的结构重新改了一下,将该声明的变量函数等和函数源文件分别放在头文件和点C的源文件里,期间遇到了一些不知原因的错误,最后试了好几种方法才弄好,具体原因也不太清楚,总之以后还是这样做:将变量定义在点C的源文件,将宏定义放在头文件,将函数声明在头文件里,如果需要将变量extern,那么请在头文件里extern。

后来在网上查了查关于头文件的,简述如下:


1,头文件可以定义所用的函数列表,方便查阅你可以调用的函数;
2,头文件可以定义很多宏定义,就是一些全局静态变量的定义,在这样的情况下,只要修改头文件的内容,程序就可以做相应的修改,不用亲自跑到繁琐的代码内去搜索。
3,头文件只是声明,不占内存空间,要知道其执行过程,要看你头文件所申明的函数是在哪个.c文件里定义的,才知道。
4,他并不是C自带的,可以不用。
5,调用了头文件,就等于赋予了调用某些函数的权限,如果你要算一个数的N次方,就要调用Pow()函数,而这个函数是定义在math.c里面的,要用这个函数,就必需调用math.h这个头文件。
	下午又试着做了一下示波器的峰峰值测量,频率测量,触发电平调节,硬件部分还没完,所有还是软件模拟。生成了1500个数据存入内存,在生成数据的时候将其最大值和最小值分别存入max和min,最后两者相减,得到峰峰值VPP。接着是触发电平的调节,设定一个SLIDER,然后将它的值设为0到100,假设为上升沿触发,用一个while()语句找到满足条件的点,然后从这一点开始读数据并开始输出波形。为了模拟真实的示波器因为触发调节不满足,不停地显示很乱的波形,我又设置了一段代码,当找完1500个点还没有满足要求的点,那么分别从第0个点开始读520个数据显示,然后从第5个点读520个在同一个起点显示,再从第10个点开始,再从第15个……
	频率的测量现在还没想到好的解决办法。
	对于没有满足触发条件的点的情况下,这时信号的波形很乱很多波形交织在一起,可以看做是很多脉冲,那么可以测试其上升沿的个数,这样来测得一屏幕数据的脉冲个数,然后得到频率。
 void test(void)
 {
	
	int i=0;
	int j=0;
	int k=0;
	int m=0;

	//这两个数相减用来得到VPP,峰峰值
	float min=0;
	float	max=0;
	float VPP;
	float s=0;

	//测试频率,其实是记录脉冲的个数,还不是具体的频率
	int freq=0;
	I16 * pStart;

	GUI_HMEM hMemtest = GUI_ALLOC_Alloc(1500 * sizeof(I16));
	pStart = GUI_ALLOC_h2p(hMemtest);

//生成1500个数据
	for (i = 0; i < 1500; i++) 
	{
		s = sin(i * 3.141592657 / 180 *4);
		//在这里记录其最大值最小值,由于是sin,max=1,min=-1
		if(s>max) max=s;
		else if(s<min) min=s; 
		pStart[i] = 0.3*s * 520 / 2 ;
   }

	VPP=max-min;
	//下面的这几句话已经测试果,VPP确实为2
	//GUI_DispStringAt("the vpp is ",600,100);
	GUI_GotoXY(720,100);
	GUI_DispFloat(VPP,3);
	
	//BackGround()为自己写的函数,实现了画示波器显示区域的方格线和坐标的标注
   	BackGround();
   	GUI_SetColor(GUI_YELLOW);
	i=0;
//Cv是触发电平,比较相邻的两个数据,当Cv处于它们之间,且为上升沿时触发,即找到满足条件的点是1500个点中的第几个点
//注:因为uCGUI默认是左上角为(0,0)点,所以向下为Y轴增大方向,因此,虽然pStart[k]比pStart[k+1]大,仍为上升沿
	while(!(pStart[k]>=Cv && pStart[k+1]<Cv))
	{k++;}
	i=k;

	//如果没有满足触发调节的点,进入死循环,这里的死循环只是暂时先这么测试而已,实际这么做肯定不行的
	if(k>=1500) 
	{	while(1)
		{
			j=0,k=0;
			//依次从0,5,10,15等开始画点
			for(m=0;m<100;m+=5)
			{
				i=m;
				for(j=0;j<=520;j++)
				{
					
						GUI_DrawPixel(j+19,pStart[i++]+160);
					//这个是矢量绘图,如果没有,画出来的只是一些点,即将这些点连接起来
						if(pStart[i]<=pStart[i+1])
						{
							for(k=pStart[i];k<=pStart[i+1];k++) GUI_DrawPixel(j+19,k+160);
							//频率测试
							freq++;
						
						}
						else if(pStart[i]>pStart[i+1])
						{
							for(k=pStart[i];k>=pStart[i+1];k--) GUI_DrawPixel(j+19,k+160);
						}
						//BackGround();
						
				}

				GUI_DispStringAt("the freq is ",600,100);
				GUI_DispDecAt(freq,700,100,9);
		
				freq=0;
			}
		}
	}

	for(j=0;j<=520;j++)
	{
		GUI_DrawPixel(j+19,pStart[i++]+160);
		
		if(pStart[i]<=pStart[i+1])
		{
			for(k=pStart[i];k<=pStart[i+1];k++) GUI_DrawPixel(j+19,k+160);	
					
		
		}
		else if(pStart[i]>pStart[i+1])
		{
			for(k=pStart[i];k>=pStart[i+1];k--) GUI_DrawPixel(j+19,k+160);
		}
	
	}
		GUI_DispStringAt("the freq(normal) is ",600,200);
			GUI_DispDecAt(freq,700,200,9);

	
	GUI_ALLOC_Free(hMemtest);


 }


触发电平为0,从sin函数为0的点开始显示


触发电平升高,具体多少也不清楚,没有设个edit框显示它,可以看到波形显示的起点变了

没有满足触发调节的点,波形重叠,很乱,显示频率的值在变(下面的那个the freq(normal) 的还没想好怎么测量)





Scope 1.0 for Linux ELF ======================= This is an oscilloscope program written in c using the XForms library. It uses the PC's parallel port for data input. The way it's done is as follows: first data bit 1 is set to 1 then to 0 to enable the a-to-d converter ( ADC0801 ), then we read 4 bits of data from the multiplexer ( 74LS157 ) placed after the a-to-d, then a 1 is sent to the second data bit and the other four bits of data are read. The circuit is setup as follows: ---------------------------------------------------------<---- Data bit 1 | | ---------------- -------------- | | D0|-------->----------| Select|----<---- Data bit 2 |---|Enable D1|-------->----------| | From | D2|-------->----------| O0|---->---- Status bit 4 Circuit->--|Ain D3|-------->----------| O1|---->---- Status bit 5 | D4|-------->----------| O2|---->---- Status bit 6 From | D5|-------->----------| O3|---->---- Status bit 7 555 timer->|CLK D6|-------->----------| | | D7|-------->----------| | ---------------- -------------- ADC0801 74LS157 The parallel port used as default is 0x378 but it can be changed within the program. Other options such as number of points per screen update and a few more can also be set from the options dialog. The 555 timer is an easy chip to configure. Set it to between 70 and 100kHz. You will need the data-sheets for these 3 chips; these can be found at www.national.com in pdf format. One thing I haven't been able to figure out yet is the frequency response of this setup. If anyone can help me with that it would be greatly appreciated. Amplitude sensitivity is approximately 0.04 volts per bit change. Also, because this program accesses the hardware directly, you will need to run it as root ( pretty obvious ). If you have any questions regarding the circuit setup or operation just let me know through e-mail and I'll write back with the solution.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值