完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我在 KIT059、PSoC5LP 中使用 VDAC8 和 ADC_SAR 将模拟信号转换为数字信号,然后再将其转换为数字信号。
一个 for 循环将数字值分配给 DtoA,DtoA 的输出由运算放大器跟随器缓冲。 输出被送回另一个缓冲运算放大器,然后再送入 A-D 转换器 ADC_SAR。 和计划: #include"rtc.h"#include"rtc.h"#include"rtc.h"#include"rtc.h" uint8 i, ii, j, jj, k, kk; //index variables uint8 temp = 0, startflag = 0; //0 = wait 1 = start //声明线性回归变量 uint8 n = 0; double x, y = 0; double xsum, ysum = 0; double xy, xysum = 0; double x2, x2sum = 0; double num, den, slope, intercept; double zero = 0; double kkk; char8 res[16u]; double value, fracpart, intpart ; //value 为实数,frac 为小数部分,decim 为整数部分 uint8 intfrac, intdecim, decim, frac; // function: void lma_clear_display(void) { //clear dispaly for(j = 0; j<=3; j++) { LCD_Position(j,0); LCD_PrintString(" "); } }//end clear display for(j = 0; j<=3; j++) // function: void lma_print_real(double value) { intpart = (int) value; fracpart = (value - intpart)*1000; LCD_PrintNumber(intpart); LCD_PrintString("."); if(fracpart < 10) LCD_PrintString("0"); if(fracpart < 100) LCD_PrintString("0"); //if(fracpart < 1000) LCD_PrintString("0"); //if(fracpart < 10000) LCD_PrintString("0"); LCD_PrintNumber(fracpart); }//end lma_print_real int main(void) { //initialize display LCD_Start(); CyGlobalIntEnable; /* Enable global interrupts. */ lma_clear_display(); LCD_Position(0,0); LCD_PrintString("initialize"); CyDelay(500); //initialize variables n = 0; x = 0; y = 0; xy = 0; x2 = 0; xsum = 0; ysum = 0; xysum = 0; x2sum = 0; zero = 0; //set op A2D and D2A D2A_Vout_Start(); D2A_Vout_SetSpeed(D2A_Vout_LOWSPEED); D2A_Vout_SetRange(D2A_Vout_RANGE_4V); lma_clear_display(); LCD_Position(0,0); LCD_PrintString("D to A started"); CyDelay(500); A2D_wht_pot_Start(); A2D_wht_pot_SetPower(A2D_wht_pot__MEDPOWER); A2D_wht_pot_SetResolution(A2D_wht_pot__BITS_8); A2D_wht_pot_StartConvert(); A2D_grn_snsr_Start(); A2D_grn_snsr_SetPower(A2D_grn_snsr__MEDPOWER); A2D_grn_snsr_SetResolution(A2D_grn_snsr__BITS_8); A2D_grn_snsr_StartConvert(); // 步进输出电压从 0.75 至 3.23 V //数字范围 47 至 202 或 0.75 V 至 3.32 V lma_clear_display(); LCD_Position(0,0); LCD_PrintString("for loop"); CyDelay(500); for(k = 47; k<=202; k = k + 5) { D2A_Vout_SetValue(k); CyDelay(500); //x = 4.08/255.0 * k; CyDelay(500); //get pot value A2D_wht_pot_StartConvert(); //wait for end of conversion do {temp = A2D_wht_pot_IsEndConversion(A2D_wht_pot_RETURN_STATUS);} while (temp == 0); CyDelay(200); x = A2D_wht_pot_CountsTo_Volts(A2D_wht_pot_GetResult8()); //get sensor value A2D_grn_snsr_StartConvert(); //wait for end of conversion do {temp = A2D_grn_snsr_IsEndConversion(A2D_grn_snsr_RETURN_STATUS);} while (temp == 0); CyDelay(200); lma_clear_display(); LCD_Position(0,0); LCD_PrintString("convert finished"); CyDelay(500); //A2D_grn_snsr_SetScaledGain(1); y = A2D_grn_snsr_CountsTo_Volts(A2D_grn_snsr_GetResult8()); // 线性回归计算 n = n + 1; xsum = xsum + x; ysum = ysum + y; xysum = xysum + (x * y); x2sum = x2sum + (x * x); lma_clear_display(); LCD_Position(0,0); LCD_PrintString("k ="); LCD_PrintNumber(k); LCD_PrintString(" " ); lma_print_real((double) (k * 4.08/255.0)); LCD_Position(1,0); LCD_PrintString("x ="); lma_print_real(x);; LCD_Position(2,0); LCD_PrintString("y ="); lma_print_real(y); CyDelay(5000); }//end for(k = 47; k<=202; k = k + 5) //find slope and intercept num = n * xysum - xsum * ysum; den = n * x2sum - (xsum * xsum); 斜率 = num/den; num = ysum * x2sum - xsum * xysum; 截距 = num/den; zero = (-1 * intercept / slope) - 2.5 ; // 显示结果 lma_clear_display(); LCD_Position(0,0); LCD_PrintString("传感器数据"); LCD_Position(1,0); LCD_PrintString("slope ="); lma_print_real(slope); LCD_Position(2,0); LCD_PrintString("int ="); lma_print_real(intercept); LCD_Position(3,0); LCD_PrintString("zero ="); lma_print_real(zero); CyDelay(5000); /5 秒暂停 }// 主程序结束 /* 文件结束 */ A 到 D 转换器的结果没有发生预期的变化。 它们的行为就像没有连接一样(我断开了它们的连接,得到的结果是一样的) P0(4) 和 P3(6) 是在软件构建时选择的运算放大器输出和输入引脚。 我错过了什么/做错了什么? 谢谢 |
|
相关推荐
1个回答
|
|
您需要初始化运算放大器并启用它。
|
|
|
|
只有小组成员才能发言,加入小组>>
TLE9879_BLDC电机启动需要用手拨一下才能转动,怎么解决?
5303 浏览 2 评论
4069 浏览 9 评论
请问TLE5012B_E1000 启动后为什么位置不能正确获取
3584 浏览 9 评论
1202 浏览 8 评论
3488 浏览 7 评论
402浏览 2评论
239浏览 2评论
349浏览 2评论
TLE9879_BLDC电机启动需要用手拨一下才能转动,怎么解决?
5304浏览 2评论
如果是打开已有的dave工程,怎么查看这个工程选择的mcu型号?
406浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 10:31 , Processed in 0.495954 second(s), Total 49, Slave 43 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号