完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试图用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个回答
|
|
由于您没有提供足够的信息,不可能看到您的显示硬件和接口是否很慢,或者您是否编写了无效代码(更新所有的内容而不是只更新相关的位置),但我们假设它非常慢,每个调用都需要。超过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 ? |
|
|
|
你的LCD功能有不必要的延迟。
以上来自于百度翻译 以下为原文 You've got unnecessary delays in your lcd functions. |
|
|
|
请看我的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 |
|
|
|
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 ? |
|
|
|
只有小组成员才能发言,加入小组>>
5234 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3201 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
670浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 13:33 , Processed in 1.454986 second(s), Total 105, Slave 89 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号