完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
IM试图在PIC32 MZ2048 EFM064上进行AN12(RG8)的单个ADC测量(在启动时)。我已经通过例子22.3工作了,但我还没有任何运气,我还没有找到任何MZ具体的例子。我的记忆力很强。(这是在Bootloader中使用的)所以我不想真正包含Orthor或PiBi,不需要做一个特别的累积读取(+/- 10%就可以了)。这个代码是基于示例22-3的东西卡在ADCI读()中,它从来没有完成。虽然(ADCDSTAT1BITS ARDY0=0),但我确信我的触发设置错误。关于什么需要修理的任何建议。
以上来自于百度翻译 以下为原文 Im attempting to make a single ADC measurement ( at startup ) of AN12 ( RG8 ) on a PIC32MZ2048EFM064. I've been workign through Example 22.3 but as yet i'm not having any luck, and i've not been able to find any MZ specific examples. I'm quite memory constrained. ( this is for use in a bootloader ) so i dont' really want to have to include hARMony or plib I'm not needing to make a particaully accruate reading ( +/- 10% will be fine ). This code is based on Example 22-3 things get stuck in adc_read() its never finishing.. while(ADCDSTAT1bits.ARDY0 == 0); Im pretty sure i've got my triggering set up wrong. Any suggestions as to what needs fixing. void initADC() { /* Configure ADCCON1 */ ADCCON1 = 0; // No ADCCON1 features are enabled including: Stop-in-Idle, turbo, // CVD mode, Fractional mode and scan trigger source. ADCCON1bits.SELRES = 3; // ADC7 resolution is 12 bits ADCCON1bits.STRGSRC = 1; // Select scan trigger. /* Configure ADCCON2 */ ADCCON2bits.SAMC = 5; // ADC7 sampling time = 5 * TAD7 ADCCON2bits.ADCDIV = 1; // ADC7 clock freq is half of control clock = TAD7 /* Initialize warm up time register */ ADCANCON = 0; ADCANCONbits.WKUPCLKCNT = 5; // Wakeup exponent = 32 * TADx /* Clock setting */ ADCCON3bits.ADCSEL = 0; // Select input clock source ADCCON3bits.CONCLKDIV = 1; // Control clock frequency is half of input clock ADCCON3bits.VREFSEL = 0; // Select AVDD and AVSS as reference source ADC0TIMEbits.ADCDIV = 1; // ADC0 clock frequency is half of control clock = TAD0 ADC0TIMEbits.SAMC = 5; // ADC0 sampling time = 5 * TAD0 ADC0TIMEbits.SELRES = 3; // ADC0 resolution is 12 bits /* Select analog input for ADC modules, no presync trigger, not sync sampling */ ADCTRGMODEbits.SH0ALT = 0; // ADC0 = AN0 /* Select ADC input mode */ ADCIMCON1bits.SIGN0 = 0; // unsigned data format ADCIMCON1bits.DIFF0 = 0; // Single ended mode ADCIMCON1bits.SIGN8 = 0; // unsigned data format ADCIMCON1bits.DIFF8 = 0; // Single ended mode /* Configure ADCGIRQENx */ ADCGIRQEN1 = 0; // No interrupts are used. ADCGIRQEN2 = 0; /* Configure ADCCSSx */ ADCCSS1 = 0; // Clear all bits ADCCSS2 = 0; ADCCSS1bits.CSS12 = 1; // AN12 (Class 2) set for scan /* Configure ADCCMPCONx */ ADCCMPCON1 = 0; // No digital comparators are used. Setting the ADCCMPCONx ADCCMPCON2 = 0; // register to '0' ensures that the comparator is disabled. ADCCMPCON3 = 0; // Other registers are ‘don't care’. ADCCMPCON4 = 0; ADCCMPCON5 = 0; ADCCMPCON6 = 0; /* Configure ADCFLTRx */ ADCFLTR1 = 0; // No oversampling filters are used. ADCFLTR2 = 0; ADCFLTR3 = 0; ADCFLTR4 = 0; ADCFLTR5 = 0; ADCFLTR6 = 0; /* Set up the trigger sources */ ADCTRG3bits.TRGSRC8 = 3; // Set AN12 (Class 2) to trigger from scan source /* Early interrupt */ ADCEIEN1 = 0; // No early interrupt ADCEIEN2 = 0; /* Turn the ADC on */ ADCCON1bits.ON = 1; /* Wait for voltage reference to be stable */ while(!ADCCON2bits.BGVRRDY); // Wait until the reference voltage is ready while(ADCCON2bits.REFFLT); // Wait if there is a fault with the reference voltage /* Enable clock to analog circuit */ ADCANCONbits.ANEN0 = 1; // Enable the clock to analog bias ADC0 ADCANCONbits.ANEN7 = 1; // Enable, ADC7 /* Wait for ADC to be ready */ while(!ADCANCONbits.WKRDY7); // Wait until ADC7 is ready /* Enable the ADC module */ ADCCON3bits.DIGEN7 = 1; // Enable ADC7 } uint32_t adc_read() { ADCCON3bits.GSWTRG = 1; // Start software trigger while(ADCDSTAT1bits.ARDY0 == 0); // Wait until the measurement run return ADCDATA12; // Return with measured data } |
|
相关推荐
7个回答
|
|
我想检查一下ADCDSTAT1BIT.ARDY12不是ADCDSTAT1BIT.ARDY0。
以上来自于百度翻译 以下为原文 I think you want to check ADCDSTAT1bits.ARDY12 not ADCDSTAT1bits.ARDY0. |
|
|
|
很好的捕捉,但不可原谅的是解决问题。
以上来自于百度翻译 以下为原文 Good catch, but unforuantly doe'snt solve the problem. |
|
|
|
发现了一个我不知道如何解决的问题,不需要设置AN12的触发源。从文档(CHAP 22)..你这样做,通过设置ADCTRG4寄存器。一切都好。然而,令人遗憾的是,ADCTRG4寄存器不在这个微处理器的定义中!我需要设置ADCTRG4BIT.TrGRC12,所以它的扫描源被设置。
以上来自于百度翻译 以下为原文 Have found a problem that i dont' know how to resolve. Im needing to set up the trigger source for AN12. From the documentation ( chap 22 ).. you do this by setting the ADCTRG4 register. All good. However sadly, the ADCTRG4 register is not in the definations for this microprocessor! I need to set ADCTRG4bits.TRGRC12 so its scan source is set. Attached Image(s) |
|
|
|
AM目前使用XC1.42,但在XC1.43和XC1.44中有一个外观,它们都有相同的问题,ADCtRG4寄存器是不存在的。
以上来自于百度翻译 以下为原文 am currently using XC1.42, but have had a look in XC1.43 and XC1.44 and they all have the same issue, the ADCTRG4 register is non-existent. |
|
|
|
嗨,你的通知是对的。你提到的Reggister没有出现在你的照片上。AN12到AN45的输入只有一个触发源,并且只能作为扫描选项的一部分使用,因此结论是它们属于3类输入,即使REF手册没有具体说明。看看这个帖子,我想它对你有帮助。
以上来自于百度翻译 以下为原文 Hi, Your notice is correct. Reggister you mentioned doesnt exist on your pic. AN12 to AN45 inputs only have one trigger source and can be used only as a part of scan option, so conclusion is that they belong to class 3 inputs even though ref manual doesnt go specific about it. Check this post, I think it can help you. |
|
|
|
感谢这是有益的,我意识到,我不需要设置这些输入的扫描模式,因为它们将永远是相同的。(这些是横跨AD7的扫描的)。它在数据表中很明显。然而,这个代码仍然没有实现。InAdAcd()运行OK,然后当我调用READADC时,它会卡在这里。(ADCDSTAT1BITS ARDY12=0);/ /等到测量运行有某种重置,我需要做什么?在ADC可以取样之前?
以上来自于百度翻译 以下为原文 Thanks that was helpful, i now realise that i dont' need to set the scan mode for these inputs as they are always going to be the same.. ( these are the scanned ones across the AD7 ).. It was'nt at all obvious in the datasheet. This code however still does'nt run.. initADC() runs ok, then when i call readADC, it gets stuck here. while(ADCDSTAT1bits.ARDY12 == 0); // Wait until the measurement run Is there some kind of reset that i need to do? before the ADC can sample? void initADC() { ADC0CFG = DEVADC0; ADC1CFG = DEVADC1; ADC2CFG = DEVADC2; ADC3CFG = DEVADC3; ADC4CFG = DEVADC4; ADC7CFG = DEVADC7; /* Configure ADCCON1 */ ADCCON1 = 0; // No ADCCON1 features are enabled including: Stop-in-Idle, turbo, // CVD mode, Fractional mode and scan trigger source. ADCCON1bits.SELRES = 3; // ADC7 resolution is 12 bits ADCCON1bits.STRGSRC = 1; // Select scan trigger, GLSWTRG global software edge trigger /* Configure ADCCON2 */ ADCCON2bits.SAMC = 5; // ADC7 sampling time = 5 * TAD7 ADCCON2bits.ADCDIV = 1; // ADC7 clock freq is half of control clock = TAD7 /* Initialize warm up time register */ ADCANCON = 0; ADCANCONbits.WKUPCLKCNT = 5; // Wakeup exponent = 32 * TADx /* Clock setting */ ADCCON3 = 0; ADCCON3bits.ADCSEL = 0; // Select input clock source ADCCON3bits.CONCLKDIV = 1; // Control clock frequency is half of input clock ADCCON3bits.VREFSEL = 0; // Select AVDD and AVSS as reference source ADC0TIMEbits.ADCDIV = 1; ADC0TIMEbits.SAMC = 5; ADC0TIMEbits.SELRES = 3; ADCTRGMODEbits.SH0ALT = 0; /* Select ADC input mode */ ADCIMCON1bits.SIGN12 = 0; // unsigned data format ADCIMCON1bits.DIFF12= 0; // Single ended mode /* Configure ADCGIRQENx */ ADCGIRQEN1 = 0; // No interrupts are used. ADCGIRQEN2 = 0; /* Configure ADCCSSx */ ADCCSS1 = 0; // Clear all bits ADCCSS2 = 0; // clear all bits ADCCSS1bits.CSS12 = 1; // AN12 (Class set for scan /* Configure ADCCMPCONx */ ADCCMPCON1 = 0; // No digital comparators are used. Setting the ADCCMPCONx ADCCMPCON2 = 0; // register to '0' ensures that the comparator is disabled. ADCCMPCON3 = 0; // Other registers are ‘don't care’. ADCCMPCON4 = 0; ADCCMPCON5 = 0; ADCCMPCON6 = 0; /* Configure ADCFLTRx */ ADCFLTR1 = 0; // No oversampling filters are used. ADCFLTR2 = 0; ADCFLTR3 = 0; ADCFLTR4 = 0; ADCFLTR5 = 0; ADCFLTR6 = 0; // AN12 Always uses scan trigger soruce /* Early interrupt */ ADCEIEN1 = 0; // No early interrupt ADCEIEN2 = 0; /* Turn the ADC on */ ADCCON1bits.ON = 1; /* Wait for voltage reference to be stable */ while(!ADCCON2bits.BGVRRDY); // Wait until the reference voltage is ready while(ADCCON2bits.REFFLT); // Wait if there is a fault with the reference voltage // Enable clock to the module. ADCCON3bits.DIGEN7 = 1; // Enable ADC7 ADCANCONbits.ANEN7 = 1; // Enable clock, ADC7 while( !ADCANCONbits.WKRDY7 ); // Wait until ADC7 is ready ADCCON3bits.GSWTRG = 1; /* Enable the ADC module */ } uint32_t adc_read() { ADCCON3bits.GSWTRG = 1; // Start software trigger while(ADCDSTAT1bits.ARDY12 == 0); // Wait until the measurement run return ADCDATA12; // Return with measured data } |
|
|
|
哦。。我觉得有点傻吗?上述代码实际上是有效的。问题是我根本没有给自己的电话打电话。这就解释了为什么它是ntchange!
以上来自于百度翻译 以下为原文 Oh.. do i feel a little silly!! the above code actually works. The problem was that i was not calling my init_ADC at all. Which explains exactly why it was'nt converting! |
|
|
|
只有小组成员才能发言,加入小组>>
5242 浏览 9 评论
2031 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3207 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2256 浏览 5 评论
778浏览 1评论
669浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
596浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
679浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 01:09 , Processed in 1.534244 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号