完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
嗨,我正在研究一个小程序,它从一个引脚读取电压,并将DAC寄存器设置为一个值,以便它应该输出与ADC之前读取的电压大致相同的电压,这是我目前对PIC16F15766的方法:但是这个C代码不起作用:变量“DAC”用CO加下划线。MtMeNo.C:19:错误:(195)表达式SythActudio.C: 19:错误:(314)“;”预期
以上来自于百度翻译 以下为原文 Hi, i am working on a small program which reads voltage from a pin and sets the DAC register to a value so that it should output roughly the same voltage as the ADC read before, this is my current approach for the PIC16F15376: #include #include #pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored) void interrupt __isr_handler(void) { if (PIR0bits.TMR0IF == 1) { //it is a timer0 interrupt ADCON0bits.GO = 1; //Start ADC conversion while(ADCON0bits.GO != 0) //Wait until conversion is done ; short result = (ADRESH << 2) | (ADRESL >> 6); //combine High and low register float measuredV = (3.30 * (float)result) / 1023.0 //calculate measured voltage unsigned char dac = (unsigned char)((measuredV * 31.0) / 3.3); //[0..31] DAC1CON1 = dac; PIR0bits.TMR0IF = 0; //Clear interrupt flag } } // Read from: RD7 void initADC(){ // Configure RD7 TRISDbits.TRISD7 = 1; //Disable output driver ANSELDbits.ANSD7 = 1; //Analog input ADCON0bits.CHS = 0b011111; //Read from pin RD7 ADCON1bits.ADFM = 0; //Left justified ADCON1bits.ADCS = 0b010; //Fosc / 32 ADCON1bits.ADPREF = 0b00; //Vref is connected to Vdd ADCON0bits.ADON = 1; //Enable ADC } void initTimer0(){ T0CON1bits.T0CS = 0b011; //HFINTOSC (32MHz) T0CON1bits.T0CKPS = 0b0111; //128 Prescaler T0CON0bits.T016BIT = 0; //8bit Timer PIR0bits.TMR0IF = 0; //Clear overflow interrupt bit PIE0bits.TMR0IE = 1; //Enable overflow interrupt INTCONbits.GIE = 1; //Enable global interrupts T0CON0bits.T0EN = 1; //Enable Timer 0 } void initDAC(){ DAC1CON0bits.DAC1EN = 1; //Enable DAC DAC1CON0bits.DAC1OE1 = 1; //Tie voltage level to DAC1OUT1 pin (RA2) DAC1CON0bits.PSS = 0b00; } void initOscillator(){ OSCCON1bits.NOSC = 0b110; //Select HFINTOSC OSCCON1bits.NDIV = 0b0000; OSCFRQbits.HFFRQ = 0b110; //32 MHz } void main(void) { initOscillator(); initDAC(); initADC(); initTimer0(); while(1){ } } But this C code isn't working: short result = (ADRESH << 2) | (ADRESL >> 6); //combine High and low register float measuredV = (3.30 * (float)result) / 1023.0 //calculate measured voltage unsigned char dac = (unsigned char)((measuredV * 31.0) / 3.3); DAC1CON1 = dac; The variable "dac" is underlined with the comment main.c:19: error: (195) expression syntax |
|
相关推荐
15个回答
|
|
上面显示错误的那条线不完整。
以上来自于百度翻译 以下为原文 The line above the one that shows the error is not complete. (; is missing ;-) |
|
|
|
是的,我也避免在上面的情况下使用中断,因为你开始了ADC转换和轮询……你可能想要使用一种不同的、更优化的方法,稍后,但是现在我将在主循环中完成所有这些操作。
以上来自于百度翻译 以下为原文 Yeah I'd also avoid using interrupt in the above case, since you're starting ADC conversion and polling for it... You may want to use a different, more optimized approach, later, but right now I'd do it all in the main loop. |
|
|
|
哦,这太难堪了,因为前面我的评论,我找不到那个错误:(这个PIC只有一个“全局”中断功能吗?”我习惯于为每个中断定义不同的中断例程(例如,完成ADC转换的一个功能,一个用于定时器溢出中断等),但我不知道在这种情况下这是否可能?如果不是这样的话,我想用我所做的if语句过滤适当的中断原因,我猜?
以上来自于百度翻译 以下为原文 Oh that's so embarrassing, i couldn't find that error because of my comment in front of it :( Is there only one "global" interrupt function for this PIC? I am used to defining different interrupt routines for each interrupt (for example, one function for ADC conversion completed, one for Timer overflow interrupt, etc.), but i don't know if this is possible in this case? If not: I have to filter the appropriate interrupt cause with if-statements like i did, i guess? |
|
|
|
你基本上是正确的。只有一个中断向量,并且该向量上的中断服务例程必须检查中断标志(并且中断使所有中断都不能启用)能够确定需要中断什么中断。当然,每个中断都有它自己的主ISR调用函数,但我不喜欢在ISROF过程中执行函数调用,如果只有一个中断启用,如果需要更快的服务,可以跳过标志检查。在新的K42部件之前的PIC18部件具有两个中断向量,允许时间关键中断具有更快和一致的定时,而不排除对较低优先级任务的中断。
以上来自于百度翻译 以下为原文 You are essentially correct. There is only one interrupt vector, and the interrupt service routine at that vector must check interrupt flags (and interrupt enables for any interrupts that aren't always enabled) to determine what interrupt needs to be serviced. Each interrupt can of course have it's own function called by the main ISR, but I prefer not to do function calls in the ISR Of course if there's only one interrupt enabled, you can skip the flag check if you need faster servicing. PIC18 parts prior to the new K42 parts have two interrupt vectors allowing a time critical interrupt to have faster and consistent timing without precluding interrupts for lower priority tasks. |
|
|
|
ISR不是等待ADC或使用浮点计算的好地方,例如乘以3.3,然后在下一行上除以3.3。
以上来自于百度翻译 以下为原文 ISR is not a good place to wait for ADC or to do useless floating point calculations, such as multiplying by 3.3 and then dividing by 3.3 on the next line. |
|
|
|
哦,这是一个很好的观点,谢谢。我有一件事我不明白,如果我定义了我的模拟通道,用这个代码读取电压:由于这个代码,3.6V被应用到这个引脚(RD7),我不知道这是为什么,因为ADC测量3.6V,当然。不是我施加在引脚上的电压吗?
以上来自于百度翻译 以下为原文 Oh, that's a good point, thank you. I have one more thing which i don't understand, if i define my analog channel from which the voltage is read with this code: ADCON0bits.CHS = 0b011111; //ADC Value is read from RD7 As a result of that codeline, 3.6V are applied to this Pin (RD7), i don't know why that is because then the ADC measures 3.6v of course and not the voltage i am applying to the pin? |
|
|
|
如果你的参考电压是3.3V(看你的公式),那么ADC就不能测量到3.3V以上。你在AdRESX寄存器中得到了什么?
以上来自于百度翻译 以下为原文 If your reference voltage is 3.3V (looking at your formulae) then the ADC cannot possibly measure above 3.3V. What do you get in your ADRESx registers? |
|
|
|
你想在这里做什么?如果你只需要8位的结果,使用左对齐。&编辑;GT;看起来你想使用ADC结果的四个最重要的位,但是通过所有这些浮动的数学。?
以上来自于百度翻译 以下为原文 What are you trying to do here? |
|
|
|
代替所有这些数学,设置ADC以给出左对齐结果,并将5个最有效位输出到DAC。
以上来自于百度翻译 以下为原文 Instead of all these math, set the ADC to give left-justified results and output the 5 most significant bits to the DAC. |
|
|
|
代替所有这些数学,设置ADC以给出左对齐结果,并输出5个最有效位到DAC.ThanksSmile:
以上来自于百度翻译 以下为原文 Instead of all these math, set the ADC to give left-justified results and output the 5 most significant bits to the DAC. Thanks Smile: |
|
|
|
现在一切都很好,我听到同样的音乐,我应用到ADC输入引脚从DAC输出引脚(然后被放大)。我想把我正在读的音乐转换成ADC(例如:低通或高通滤波器)。遗憾的是,我不太了解我必须使用的数学,你有什么信息可以告诉我怎么做吗?
以上来自于百度翻译 以下为原文 Everything is working fine now, i hear the same music I am applying to the ADC input pin from the DAC output pin (which then is amplified). I would like to transform the music i am reading from the ADC (for example: low or high pass filter). Sadly I don't know very much about the math i have to use for this, do you have any information for me how I could do this? |
|
|
|
这可能是有用的HTTP//www. McCHIP.COM/FUMMS/M9844 18.ASPX。
以上来自于百度翻译 以下为原文 This may be useful http://www.microchip.com/forums/m984418.aspx |
|
|
|
我无法从你的帖子中得到尽可能多的信息,我现在正在搜索FFT C代码,它有一个变换和一个反变换“函数”,在那里我可以给我的ADC样本数组,这样的东西存在吗?
以上来自于百度翻译 以下为原文 I couldn't get as much information out of your post as i would like to, currently i am searching for FFT C code which has a transform and a back-transform "function" where i can just feed my array of ADC samples, does something like this exist? |
|
|
|
在这个线程中,我建议使用低通、高通等过滤代替FFT。我相信它们可能对你想要达到的目标有好处。
以上来自于百度翻译 以下为原文 In that thread I was suggested about using low-pass, high-pass etc filtering instead of FFT. I believe that they may be good for what you want to achieve... |
|
|
|
我仍然不知道如何在C上用C语言实现它们:
以上来自于百度翻译 以下为原文 I still have no idea how i could implement them in C on my controller pink: |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
734浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
506浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 19:01 , Processed in 1.485762 second(s), Total 105, Slave 89 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号