完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我有麻烦让ADC工作在PIC24FJ128GA202上读取一个引脚上的电压。我注意到数据表上写着AVSS和AVDD作为参考,而我的28个引脚包没有这些引脚,而带有更多引脚的包没有。如果我配置它使用AVDD/AVSS作为参考,它会使用VDD/VSS吗?我已经尝试了手动采样和自动设置SAMP位。
以上来自于百度翻译 以下为原文 Hi, I am having trouble getting ADC to work on PIC24FJ128GA202 to read the voltage on a pin. I notice the datasheet says AVSS and AVDD as reference, and my 28 pin package doesnt have these pins while the package with more pins does. If i configure it to use AVDD/AVSS as reference, will it use VDD/VSS? I have tried it on manual sampling and automatic set SAMP bit /* * File: helloworld.c * Author: Chenxi_2 * * Created on July 26, 2016, 3:31 PM */ #define _XTAL_FREQ 7370000 //29480000 #define FOSC 7370000 //29480000 #define FCY FOSC/2 // CONFIG4 #pragma config DSWDTPS = DSWDTPS1F // Deep Sleep Watchdog Timer Postscale Select bits (1:68719476736 (25.7 Days)) #pragma config DSWDTOSC = LPRC // DSWDT Reference Clock Select (DSWDT uses LPRC as reference clock) #pragma config DSBOREN = ON // Deep Sleep BOR Enable bit (DSBOR Enabled) #pragma config DSWDTEN = ON // Deep Sleep Watchdog Timer Enable (DSWDT Enabled) #pragma config DSSWEN = ON // DSEN Bit Enable (Deep Sleep is controlled by the register bit DSEN) #pragma config PLLDIV = DISABLED // USB 96 MHz PLL Prescaler Select bits (PLL Disabled) #pragma config I2C1SEL = DISABLE // Alternate I2C1 enable bit (I2C1 uses SCL1 and SDA1 pins) #pragma config IOL1WAY = OFF // PPS IOLOCK Set Only Once Enable bit (The IOLOCK bit can be set and cleared using the unlock sequence) // CONFIG3 #pragma config WPFP = WPFP127 // Write Protection Flash Page Segment Boundary (Page 127 (0x1FC00)) #pragma config SOSCSEL = OFF // SOSC Selection bits (Digital (SCLKI) mode) #pragma config WDTWIN = PS25_0 // Window Mode Watchdog Timer Window Width Select (Watch Dog Timer Window Width is 25 percent) #pragma config PLLSS = PLL_FRC // PLL Secondary Selection Configuration bit (PLL is fed by the on-chip Fast RC (FRC) oscillator) #pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset Enable) #pragma config WPDIS = WPDIS // Segment Write Protection Disable (Disabled) #pragma config WPCFG = WPCFGDIS // Write Protect Configuration Page Select (Disabled) #pragma config WPEND = WPENDMEM // Segment Write Protection End Page Select (Write Protect from WPFP to the last page of memory) // CONFIG2 #pragma config POSCMD = NONE // Primary Oscillator Select (Primary Oscillator Disabled) #pragma config WDTCLK = LPRC // WDT Clock Source Select bits (WDT uses LPRC) #pragma config OSCIOFCN = OFF // OSCO Pin Configuration (OSCO/CLKO/RA3 functions as CLKO (FOSC/2)) #pragma config FCKSM = CSDCMD // Clock Switching and Fail-Safe Clock Monitor Configuration bits (Clock switching and Fail-Safe Clock Monitor are disabled) #pragma config FNOSC = FRC // Initial Oscillator Select (Fast RC Oscillator (FRC)) #pragma config ALTCMPI = CxINC_RX // Alternate Comparator Input bit (C1INC, C2INC and C3INC are on RB9) #pragma config WDTCMX = WDTCLK // WDT Clock Source Select bits (WDT clock source is determined by the WDTCLK Configuration bits) #pragma config IESO = OFF // Internal External Switchover (Disabled) // CONFIG1 #pragma config WDTPS = PS32768 // Watchdog Timer Postscaler Select (1:32,768) #pragma config FWPSA = PR128 // WDT Prescaler Ratio Select (1:128) #pragma config WINDIS = OFF // Windowed WDT Disable (Standard Watchdog Timer) #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT disabled in hardware; SWDTEN bit disabled) #pragma config ICS = PGx1 // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC1/PGED1) #pragma config LPCFG = OFF // Low power regulator control (Disabled - regardless of RETEN) #pragma config GWRP = OFF // General Segment Write Protect (Write to program memory allowed) #pragma config GCP = OFF // General Segment Code Protect (Code protection is disabled) #pragma config JTAGEN = OFF // JTAG Port Enable (Disabled) #include #include #include int main(void) { TRISBbits.TRISB15 = 1; //set LED port as input TRISBbits.TRISB11 = 1; ANSBbits.ANSB15 = 1; //set as analog //control register AD1CON1 = 0x2476; //ADON adcon, discontinue if idle, PIA mode //Extended DMA & buffer off, 12 bit mode, decimal unsigned, internal counter // manual sample. sample and hold sampling AD1CON2 = 0; //AVDD, ADSS reference voltages, sample &hold normal inputs //FIFO, no input scan, fill ADC1BUF0-7, interrupt every sample, fill start at ADC1BUf0, Always sample input select for A AD1CON3 = 0x1F02; //system clock, no extended sampling, disable charge pump, //31TAD sampling , 4 times TCY = TAD AD1CHS = 0x0009; ANCFG = 0; AD1CSSH = 0; AD1CSSL = 0; AD1CHITL = 0; ADC1BUF0 = -1; AD1CTMENL = 0; //IFS0bits.AD1IF = 0; // Clear A/D conversion interrupt. AD1CON1bits.ADON=1; int lightlevel[50]; while(1) { int i=0; while (i<50){ //AD1CON1bits.SAMP = 1; __delay_ms(100); //AD1CON1bits.SAMP = 0; while (AD1CON1bits.DONE == 0){ //lightlevel = ADC1BUF0; //AD1CON1bits.DONE = 0; } lightlevel = ADC1BUF0; //AD1CON1bits.DONE = 0; i++; } } return 1; } // Example code for A/D ISR: //void __attribute__ ((__interrupt__)) _ADC1Interrupt(void) //{ //IFS0bits.AD1IF = 0; //} |
|
相关推荐
4个回答
|
|
我忘了提到我是如何测试它的。我正在3.25V通过ICD3为它供电。由于某些原因,它不让我编辑原始post当我在调试模式下运行代码时,它总是给我一个大约3900的大值,用于ADC1BUF0中的值。此外,当我将信道选择AD1CHS寄存器设置为AVSS或AVDD时,它确实给了我0或4096。我用万用表测量引脚电压,测试电压通常为300mV,或者1.0V,它仍然总是读3900。
以上来自于百度翻译 以下为原文 I forgot to mention how i tested it so far. I am powering it through ICD3 at 3.25V. For some reason it wont let me edit the original post When I run the code in debug mode, it gives me a large value around 3900 all the time for the value in ADC1BUF0. Also, when i set the channel select AD1CHS register to AVSS or AVDD, it does give me either 0 or 4096 respectively. I measure the pin voltage with multimeter, with the test voltage I give it usually around 300mV, or 1.0V, it still always reads 3900. |
|
|
|
是的,A引脚只存在于较大的PIC中,否则使用“标准”电源引脚(这会导致更多的噪声,但没问题)。至于您的代码,我想说(不确定,但几乎!)如果你不使用“SAMP”位,那么你必须通过GO-DOWN位开始转换。
以上来自于百度翻译 以下为原文 Yes, the A pins are there only in larger PICs, otherwise the "standard" power pins are used (which can lead to more noise but ok). As for your code, I'd say (not sure but almost!) that if you're not using "SAMP" bit then you must start the conversion via GO-DONE bit... |
|
|
|
这是否意味着我需要使用VREF+和VREF-?
以上来自于百度翻译 以下为原文 so does that mean I need to use VREF+ and VREF- ? |
|
|
|
好,我只是有点困惑,因为这两个设置是VREF+/VREF-和AVDD,AVSS。AVDD,AVSS是电源设置吗?它使用VDD和VSS引脚之间的电压,因为在我的芯片上没有AVDD引脚或AVSS引脚。
以上来自于百度翻译 以下为原文 ok I am just a bit confused because the two settings are VREF+/VREF- and AVDD, AVSS. Is AVDD, AVSS the power supply setting where it uses the voltage between VDD and VSS pins, because there is not AVDD pin or AVSS pins on my chip |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
777浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
676浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 01:59 , Processed in 1.242623 second(s), Total 51, Slave 45 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号