新手入门
- 积分
- 11
- 金钱
- 11
- 注册时间
- 2022-10-11
- 在线时间
- 2 小时
|
1金钱
ZYNQ7020。PS端通过DMA发送DA数据到异步FIFO,然后读取数据给10位双路DA模块。写了个生成三角波的函数,可是出来的是锯齿波,
- /*
- * Get Triangle Wave value
- *
- *[url=home.php?mod=space&uid=271674]@param[/url] point is points in one wave period
- *@param max_amp is maximum amplitude value
- *@param amp_val is current amplitude value
- *@param Triangle_tab is Triangle wave buffer pointer
- */
- void GetTriangleWave(int point, int max_amp, int amp_val, u16 *Triangle_tab)
- {
- int i ;
- double tap_val ;
- tap_val = (double)amp_val/(double)point;//2*256/512=1
- for(i = 0; i < point; i++)
- {
- if (i < point/2)//512
- Triangle_tab[i] = (u16)(i*tap_val + (max_amp-amp_val)/2) ; //127*1+(1024-256)/2=
- else
- Triangle_tab[i] = (u16)(amp_val - 1 - (i-point/2)*tap_val + (max_amp-amp_val)/2 ) ;
- }
- }
复制代码 但是将if (i < point/2)处的2改成4就是三角波了,函数参数如下
- /*
- * Wave Parameter definitions
- */
- #define DA0_MAX_PKT_LEN 1024 /* must be bigger than 1024, or FIFO will be empty */
- #define DA0_MAX_AMP_VAL 1024 /* 2^10, do not change */
- #define DA0_AMP_VAL 1024 /* must be less than 2^10 */
- #define DA1_MAX_PKT_LEN 40950 /* must be bigger than 1024, or FIFO will be empty */
- #define DA1_MAX_AMP_VAL 1024 /* 2^10, do not change */
- #define DA1_AMP_VAL 1024 /* must be less than 2^10 */
复制代码 ,还有就是DMA每次发送的数据小于1024时(即DA0_MAX_PKT_LEN参数),出来的波形就有一部分是没有值的,下面是数据发送的代码- // GetTriangleWave(DA0_MAX_PKT_LEN, DA0_MAX_AMP_VAL, DA0_AMP_VAL, Wave_0_Buffer) ;
- // GetTriangleWave(DA1_MAX_PKT_LEN, DA1_MAX_AMP_VAL, DA1_AMP_VAL, Wave_1_Buffer) ;
- // memcpy(Dma_0_TxBuffer, Wave_0_Buffer, x_scan_space_num) ;
- // memcpy(Dma_1_TxBuffer, Wave_1_Buffer, y_scan_space_num) ;
- // Xil_DCacheFlushRange((UINTPTR)Dma_0_TxBuffer, x_scan_space_num);
- // Xil_DCacheFlushRange((UINTPTR)Dma_1_TxBuffer, y_scan_space_num);
- // //数据转运
- // XAxiDma_SimpleTransfer(&AxiDma_0,(UINTPTR) x_scan_space_num,
- // x_scan_space_num, XAXIDMA_DMA_TO_DEVICE);
- // XAxiDma_SimpleTransfer(&AxiDma_1,(UINTPTR) y_scan_space_num,
- // y_scan_space_num, XAXIDMA_DMA_TO_DEVICE);
- //
复制代码 因为设计要求,需要每次发送一个DAC的数据,代码如下:怎么解决小于1024就没有数据的问题- //从底到顶扫描,y轴逐渐增大,每一个y值对应一个x轴序列,之字形路线,y轴序列要为偶数
- void scan_bottom_to_top(void)
- {
- int i=0;
- int j=0;
- u16 flag_x=0; //0:x从小到大扫描;1:x从大到小扫描。
- for(j=0;j<y_scan_space_num;j++)
- {
- //DAC_SetChannel2Data(DAC_Align_12b_R,y_scan_dac_value[j]); //DAC第2个通道(y通道)数值设定。
- Wave_1_Buffer[j] = y_scan_dac_value[j];
- Dma_1_TxBuffer[j] = Wave_1_Buffer[j];
- Xil_DCacheFlushRange((UINTPTR)Dma_1_TxBuffer[j], 1);
- XAxiDma_SimpleTransfer(&AxiDma_1,(UINTPTR) Dma_1_TxBuffer[j],
- 1, XAXIDMA_DMA_TO_DEVICE);
- if(flag_x==0) //0:x从小到大扫描;
- for(i=0;i<x_scan_space_num;i++)
- {
- //DAC_SetChannel1Data(DAC_Align_12b_R,x_scan_dac_value[i]); //DAC第1个通道(x通道)数值设定。
- Wave_0_Buffer[i] = x_scan_dac_value[i];
- Dma_0_TxBuffer[i] = Wave_0_Buffer[i];
- Xil_DCacheFlushRange((UINTPTR)Dma_0_TxBuffer[i], 1);
- XAxiDma_SimpleTransfer(&AxiDma_0,(UINTPTR) Dma_0_TxBuffer[i],
- 1, XAXIDMA_DMA_TO_DEVICE);
- Get_picture_data(i,j,one_spot_ADC_times);
- if (i==x_scan_space_num-1) //x轴扫描到头,标志赋值
- {
- flag_x=1;
- }
- }
- else //1:x从大到小扫描。
- for(i=(x_scan_space_num-1);i>-1;i--)
- {
- //DAC_SetChannel1Data(DAC_Align_12b_R,x_scan_dac_value[i]); //DAC第1个通道(x通道)数值设定。
- Wave_0_Buffer[i] = x_scan_dac_value[i];
- Dma_0_TxBuffer[i] = Wave_0_Buffer[i];
- Xil_DCacheFlushRange((UINTPTR)Dma_0_TxBuffer[i], 1);
- XAxiDma_SimpleTransfer(&AxiDma_0,(UINTPTR) Dma_0_TxBuffer[i],
- 1, XAXIDMA_DMA_TO_DEVICE);
- // Get_picture_data(i,j,one_spot_ADC_times);
- if (i==0) //x轴扫描到头,标志赋值
- {
- flag_x=0;
- }
- }
- }
- }
复制代码
|
-
|