Microchip
直播中

柳杨

8年用户 215经验值
私信 关注
[问答]

读取半波信号的均方根值可以500毫秒扫描模拟值吗

我试图用DSPIC30F3011读取半波信号的均方根值。我在LCD显示器上得到了正确的值,但问题是需要花费太多的时间来更新值。我想每500毫秒扫描模拟值。我用的是10兆赫的晶体。

以上来自于百度翻译


      以下为原文

    I am trying to read RMS value of a half wave signal using dspic30f3011. I am getting correct value at my LCD display, but problem is that It's taking too much time to update value I want to scan analog value at every 500 ms.

I am using 10 MHz crystal.



unsigned char ADC_buffer [5];
unsigned long ADCValue;
unsigned int *ADC16Ptr;
float ADC_float = 0;
double ADC_average[];



// int ii ,jj , kk ;
static int ii = 0, jj = 0, kk = 0;


void ADC_AN2(void)
{
float maxima[1];
float average[10];
float maxima_average;

ADPCFG = 0b0000000000000000; // all PORTB = Digital; RB2 = analog
ADCON1 = 0x00E0; // SSRC bit = 111 implies internal
// counter ends sampling and starts
// converting.
ADCHS = 0x0005; // Connect RB2/AN2 as CH0 input
// in this example RB2/AN2 is the input
ADCSSL = 0;
ADCON3 = 0x0203; // Sample time = 2Tad, Tad = 95.24 ns @ 21 MIPS
// which will give 1 / (14 * 95.24 ns) = 750 ksps
ADCON2 = 0b111111000000100; // Select external VREF+ and VREF- pins
// Interrupt after every 2 samples
ADCON1bits.ADON = 1; // turn ADC ON



ADCValue = 0; // clear value
ADC16Ptr = &ADCBUF0; // initialize ADCBUF pointer
IFS0bits.ADIF = 0; // clear ADC interrupt flag
ADCON1bits.ASAM = 1; // auto start sampling
// for 31Tad then go to conversion
while (!IFS0bits.ADIF); // conversion done?
ADCON1bits.ASAM = 0; // yes then stop sample/convert
//for (ii = 0; ii <15; ii++) // average the 2 ADC value
{
ADCValue = ADCValue+ *ADC16Ptr++;
}
//ADCValue = ADCValue >> 1;

ADC_float = (float)(ADCValue);

//i=0;

dis_cmd(0x80);
   sprintf(ADC_buffer,"%f",ADC_float);
for(ii=0;ii<3;ii++)
{
dis_data(ADC_buffer[ii]);


}
*/

// I1 SHUNT


ADPCFG = 0xFFFB; // all PORTB = Digital; RB2 = analog
ADCON1 = 0x00E0; // SSRC bit = 111 implies internal
// counter ends sampling and starts
// converting.
ADCHS = 0x0002; // Connect RB2/AN2 as CH0 input ..
// in this example RB2/AN2 is the input
ADCSSL = 0;
ADCON3 = 0x0113; // Sample time = 15Tad, Tad = internal Tcy/2
ADCON2 = 0x0004; // Interrupt after every 2 samples
ADCON2bits.SMPI = 15;

//for(kk=0;kk<=10;kk++)
{
for(jj=0;jj<=10;jj++)
{
ADCON1bits.ADON = 1; // turn ADC ON



ADCValue = 0; // clear value
ADC16Ptr = &ADCBUF0; // initialize ADCBUF pointer
IFS0bits.ADIF = 0; // clear ADC interrupt flag
ADCON1bits.ASAM = 1; // auto start sampling
// for 31Tad then go to conversion
while (!IFS0bits.ADIF); // conversion done?
ADCON1bits.ASAM = 0; // yes then stop sample/convert
for (ii = 0; ii < 2; ii++) // average the 2 ADC value
ADCValue = ADCValue + *ADC16Ptr++;
ADCValue = ADCValue >> 1;

dis_cmd(0x80);

ADC_float = (float)((ADCValue)*(5.03/1023)*4);

maxima_average = maxima_average + ADC_float;
}
average[kk] = maxima_average/10;
average[kk] = average[kk]*average[kk];
kk++;
if(kk>=10)
{
kk=0;

for(kk=0;kk<=10;kk++)
average[0] = average[0] + average[kk];

average[0] = average[0]/10;

average[0] = sqrt(average[0]);


//average[kk] = (average[kk]/1.417);
sprintf(ADC_buffer,"%f",average[0]);
kk=0;
average[0]=0;
maxima_average = 0;
for(ii=0;ii<4;ii++)
{
dis_data(ADC_buffer[ii]);
//dis_cmd(0x01);
}


}
//if(average[0]



////dis_cmd(0x01);


}

}

回帖(4)

李雨晨

2018-10-25 17:13:11
由于您没有提供足够的信息,不可能看到您的显示硬件和接口是否很慢,或者您是否编写了无效代码(更新所有的内容而不是只更新相关的位置),但我们假设它非常慢,每个调用都需要。超过125毫秒(总共500毫秒,你在一个循环中调用4次X),你的问题是什么?你的数据采集速率与你的显示速度有什么关系?要么减少显示在LCD上的数据量,要么降低显示更新率。为什么要更新2赫兹速率的显示器?

以上来自于百度翻译


      以下为原文

    Since you do not provide enough information it is not possible to see whether your display hardware and interfacing  is just slow, or whether you have written ineffective code (update everything instead of only updating relevant positions)
 
But let's assume it's just awfully slow and each call takes longer than 125 ms (total 500 ms, you call in in a loop 4 x times)
 

 
And what is your question here ? What has your data acquisition rate to do with your display speed ?
Either reduce the amount of data which you display on your LCD, or lower the display update rate.
Why do you want to update the display with 2 Hz rate ?
 
 
举报

李涛

2018-10-25 17:28:23
你的LCD功能有不必要的延迟。

以上来自于百度翻译


      以下为原文

    You've got unnecessary delays in your lcd functions.
举报

徐依妮

2018-10-25 17:47:48
请看我的LCD代码。我不认为LCD延迟会产生问题,因为数据在4到5分钟后被更新,我的LCD不是那么慢。在采样之后,我去计算平均值、平方、然后再平均,然后平方根,在完成上述循环之后,它开始显示。一个数据,当LCD开始显示数据时,它将在200毫秒内更新,但是需要更新4到5秒的时间来更新新数据。

以上来自于百度翻译


      以下为原文

    Please find my LCD code.
 
I do't think LCD delay will create problem, because data get updated after 4 to 5 min, my LCD is not that slow.
 
after taking samples, I go for calculation of averaging, squaring, then again averring and then square root and after completing of all above cycle it start displaying a data, when LCD start displaying data it will update under 200 ms but it's take time 4 to 5 sec for updating new data. 
   Attachment(s)

New Text Document (4).txt (2.20 KB) - downloaded 90 times
举报

李雨晨

2018-10-25 17:55:58
Gort似乎是一个透视者:-分钟?还是秒?无论如何,我不明白为什么你认为这会解释这不是问题。对于每一个字符,你都会加上10毫秒的延迟(10),如果乘以你所输出的字符数,你的结果是?

以上来自于百度翻译


      以下为原文

     

 
Gort seems to be a clairvoyant :-)
 

minutes ? or seconds ? Anyway, I don't understand why you think this would explain that it is NOT a problem. 
 
For each and every character you add a delay of 10 ms.
delay_ms ( 10 );
If you multiply that be the number of characters which you output, your result is ?
举报

更多回帖

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