1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,我正在尝试使用我的DSIC33 FJ128GP802上的ADC来转换4条输入线。我现在想避免DMA。我已经尽可能地建立了ADC系统,而且我被中断了,但是结果并不如预期。这是我的代码:输入线是AN2-4。我用AD1PCFGL将这些线路设置为ADC输入。我需要做点别的吗?提前感谢。
以上来自于百度翻译 以下为原文 Hi, I am trying to use the ADC on my DSPIC33FJ128GP802 to convert 4 input lines. I am trying to avoid DMA for now. I've set up the ADC system as best I can and I am getting interrupts but the results are not as expected. Here is my code: void init_adc() { AD1CON1bits.FORM = 0; // Data Output Format: integer AD1CON1bits.SSRC = 7; // Sample Clock Source: counter starts conversion AD1CON1bits.ASAM = 0; // ADC Sample Control: Sampling begins when samp bit is set AD1CON1bits.AD12B = 1; // 12-bit ADC operation AD1CON1bits.SIMSAM = 0; // Unimplemented in 12 bit mode AD1CON2bits.BUFM = 0; AD1CON2bits.CHPS = 0; // Converts CH0 AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock AD1CON3bits.ADCS = 63; // ADC Conversion Clock //AD1CHS0: A/D Input Select Register adc_chan=2; AD1CHS0bits.CH0SA = adc_chan; // Select the channel to convert AD1CHS0bits.CH0NA = 0; // MUXA -ve input selection (Vref-) for CH0 //AD1PCFGL: Port configuration bits AD1PCFGL = 0xFFE3; // AN2-4 as analog inputs, rest is digital IFS0bits.AD1IF = 0; // Clear the A/D interrupt flag bit IEC0bits.AD1IE = 1; // Enable A/D interrupt AD1CON1bits.ADON = 1; // Turn on the A/D converter // start 1st conversion AD1CON1bits.DONE=0; // Clear Done Flag AD1CON1bits.SAMP=1; // Start sampling } void __attribute__((__interrupt__, no_auto_psv))_ADC1Interrupt(void) { // Deal the results switch(adc_chan) { case 2: fmRaw = ADC1BUF0; break; case 3: voRaw = ADC1BUF0; break; case 4: ofsRaw = ADC1BUF0; break; } // select next channel adc_chan+=1; if(adc_chan>4) adc_chan=2; AD1CHS0bits.CH0SA = adc_chan; // Select the channel to convert //start next conversion IFS0bits.AD1IF = 0; // Clear ADC interrupt flag AD1CON1bits.DONE=0; // Clear Done Flag AD1CON1bits.SAMP=1; // Start sampling } The input lines are AN2-4. I have set up those lines as ADC inputs using AD1PCFGL. Do I need to do something else? Thanks in advance. |
|
相关推荐
2个回答
|
|
嗨,你是说3个输入线(AN2,AN3,AN4)?如果你选择AD1CON1BITS.SSRC=7,那么ADC操作是自动完成的。你不需要开始采样,也不需要开始转换。(采样和转换是两个不同的事情,如果你不知道D,请阅读数据表。但是,你必须(当SSRC=7)指定在AD1CON3.SAMC中的采样时间(SAMC & LT;4:0& G::自动采样时间位),并且可能设置AD1CON1BITS。ASAM=1。另一件事:在每次中断之后,你尝试改变输入线,然后再次开始采样。我不确定这是否能工作W。SSRC= 7正常,你将启用“频道扫描”,在AD1CSL中设置所需的输入,并设置ADAD1CON2.SMPI=(所需输入的数量- 1)结果是什么?
以上来自于百度翻译 以下为原文 Hi, You mean 3 input lines (AN2,AN3,AN4) ? This can be done but will have no effect on conversion. If you select AD1CON1bits.SSRC = 7 then the ADC operation is done automatic. You don't need to start sampling and don't need to start conversion. (Sampling and conversion are two different things, please read the datasheet if you don't know the difference yet) But you must (when SSRC=7) specify the sampling time in AD1CON3.SAMC (SAMC<4:0>: Auto Sample Time bits) and probably set AD1CON1bits.ASAM = 1. The other thing: You try to change the input line after every interrupt and then start sampling again. I'm not sure whether this will work with SSRC=7. Normal you would enable "channel-scanning", set the desired inputs in AD1CSSL and set the AD1CON2.SMPI = (number of desired inputs -1) What are the results? |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
778浏览 1评论
669浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
597浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
679浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 07:01 , Processed in 1.305928 second(s), Total 50, Slave 44 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号