英飞凌
直播中

史晓明

7年用户 922经验值
私信 关注

在KIT059、PSoC5LP中使用VDAC8和ADC_SAR将模拟信号进行转换遇到的疑问

我在 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)

刘丹

2024-6-3 09:30:01
您需要初始化运算放大器并启用它。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分