1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正试图通过PIC32 MM000 64 GPL036获得12频道的ADC。由MCC生成的相关代码是:TyPulfStruts {Unt8It t ItStase};ADCYObjor;静态ADCI对象ADC1OOBJ;/**部分:驱动接口*/Office ADC1x初始化(空隙){//ASAM禁用;完成禁用;形成整型16位;SAMP禁用;SSRC清除采样位结束采样并启动转换。on;SIDL禁用;MODE12=0x8000;//CSCNA禁用;BFFM禁用;SMPI 1;OFFACK禁用;VCFG AVDD/AVSS;BFRIGEN禁用;AD1CON2= 0x0;/SAMC 0;EXRSAM禁用;ADRC FRC;ADC 0;AD1CON3= 0x8000;//CH0SAN AN0;CH0NA AVSS;AD1CHS=0X0;//CSS9禁用;CSS6禁用;CSS3禁用;CSS2禁用;CSS1禁用;CSS13禁用;CSS12禁用;CSS11禁用;CSS10禁用;CSS30禁用;CSS29禁用;CS128禁用;AD1CSS= 0x0;/CHH9禁用;CHH8禁用;CHH7禁用;CHH7;CHH7禁用;CSH28禁用;CSH28禁用;禁用CHH6;CHH3禁用;CHH2禁用;CHH0禁用;CHH10禁用;CHH13禁用;CHH12禁用;AD1CHIT=0x0;ADC1YObj.ItStase= AD1CON2BITS.SMPI;}空隙ADC1SART启动(空隙){AD1CON1BITS。SAMP=1;}空ADC1-停止(VoI)(0);Unt161t ADC1OxFuffelGET(UtiN16*T*缓冲器){INTUC16T*ADC16PTR;ADC16PTR=(UINT16*T*)和(ADC1BUF0);(计数=0;计数=ADC1OOB.int采样;计数+++){缓冲器[CUT] =(UINT16YT)*ADC16PTR;ADC16PTR++;}返回计数;} UINT1616T ADC1L转换d){1}1位SultGET(空){返回ADC1BUF0;}布尔ADC1IIS转换完成(空隙){返回AD1CON1BITS。完成;和/或等待转换完成}空隙ADC1Chhannel选择(ADC1-信道){Ad1CHS=通道;}空ADC1任务(空隙){/ /清除ADC中断标志IFS0ClR=1 & lt;/**文件结束* /我不确定函数需要调用什么顺序来进行转换。我现在使用的主循环是:(1){int回答;int信道=12;ADC1a信道选择(通道);ADC1a启动();Adc1AsExchange完全());Adc1IsStor();回答= ADC1OxExchange结果();}使用调试器,我陷入了while语句中。从阅读数据表,我无法确定我需要做什么来获得转换。来自PIC18,似乎更复杂。任何帮助都非常感谢。谢谢。
以上来自于百度翻译 以下为原文 I'm trying to get the ADC working on channel 12 with the PIC32MM0064GPL036. The pertinent code generated by MCC is: typedef struct { uint8_t intSample; } ADC_OBJECT; static ADC_OBJECT adc1_obj; /** Section: Driver Interface */ void ADC1_Initialize (void) { // ASAM disabled; DONE disabled; FORM Integer 16-bit; SAMP disabled; SSRC Clearing sample bit ends sampling and starts conversion; SIDL disabled; MODE12 10-bit; ON enabled; AD1CON1 = 0x8000; // CSCNA disabled; BUFM disabled; SMPI 1; OFFCAL disabled; VCFG AVDD/AVSS; BUFREGEN disabled; AD1CON2 = 0x0; // SAMC 0; EXTSAM disabled; ADRC FRC; ADCS 0; AD1CON3 = 0x8000; // CH0SA AN0; CH0NA AVSS; AD1CHS = 0x0; // CSS9 disabled; CSS8 disabled; CSS7 disabled; CSS6 disabled; CSS5 disabled; CSS4 disabled; CSS3 disabled; CSS2 disabled; CSS1 disabled; CSS0 disabled; CSS13 disabled; CSS12 disabled; CSS11 disabled; CSS10 disabled; CSS30 disabled; CSS29 disabled; CSS28 disabled; AD1CSS = 0x0; // CHH9 disabled; CHH8 disabled; CHH7 disabled; CHH6 disabled; CHH5 disabled; CHH4 disabled; CHH3 disabled; CHH2 disabled; CHH1 disabled; CHH0 disabled; CHH11 disabled; CHH10 disabled; CHH13 disabled; CHH12 disabled; AD1CHIT = 0x0; adc1_obj.intSample = AD1CON2bits.SMPI; } void ADC1_Start(void) { AD1CON1bits.SAMP = 1; } void ADC1_Stop(void) { AD1CON1bits.SAMP = 0; } uint16_t ADC1_ConversionResultBufferGet(uint16_t *buffer) { int count; uint16_t *ADC16Ptr; ADC16Ptr = (uint16_t *)&(ADC1BUF0); for(count=0;count<=adc1_obj.intSample;count++) { buffer[count] = (uint16_t)*ADC16Ptr; ADC16Ptr++; } return count; } uint16_t ADC1_ConversionResultGet(void) { return ADC1BUF0; } bool ADC1_IsConversionComplete( void ) { return AD1CON1bits.DONE; //Wait for conversion to complete } void ADC1_ChannelSelect( ADC1_CHANNEL channel ) { AD1CHS = channel; } void ADC1_Tasks ( void ) { // clear the ADC interrupt flag IFS0CLR= 1 << _IFS0_AD1IF_POSITION; } /** End of File */ I'm unsure of in what order the functions need to be called in to make a conversion. The main loop I am using now is: while(1) { int answer; int channel = 12; ADC1_ChannelSelect(channel); ADC1_Start(); while(!ADC1_IsConversionComplete()) ; ADC1_Stop(); answer = ADC1_ConversionResultGet(); } using the debugger, I am getting caught up in the while statement. From reading the datasheet I am unable to determine what is needed for me to do to get the conversion. Coming from PIC18, it seems much more complicated. Any help is greatly appreciated. Thanks. |
|
相关推荐
1个回答
|
|
谢谢你的回复。我能让模块按照你的建议工作。我和你有一个相同的问题,但是发现错误是转换时钟被卡在1位(我在1023位或0位被卡在10位模式下)。在我的情况下,它产生了一个可靠的结果。4,我还必须使用PBCK作为源而不是FRC。
以上来自于百度翻译 以下为原文 Thanks for your reply. I was able to get the module working roughly following what you suggested. I had the same issue as you for a bit, but found the error was that the conversion clock was stuck as 1 TCY (I was stuck at either 1023 or 0 in 10 bit mode). In my case, it was > 4 TCY that produced a reliable result. I also had to use the PBCLK as a source instead of FRC. |
|
|
|
只有小组成员才能发言,加入小组>>
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:02 , Processed in 1.573737 second(s), Total 78, Slave 62 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号