完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我正试图使用ADC,我总是读它的0x3FF,如果有人有任何想法。下面你可以找到代码。这是初始化:这是我如何读取值:谢谢,
以上来自于百度翻译 以下为原文 Hello, Im trying to use the ADC and i always read 0x3FF on it, please if anyone have any idea. Below you can find the code. This is the initialization: /*Setup Ports For Analog pin*/ /*Configure the ADC Pins as Analog*/ PLIB_PORTS_PinModeSelect(PORTS_ID_0, BOARD_TEMP_ADC, PORTS_PIN_MODE_ANALOG); /*Select the ADC Reference*/ PLIB_ADC_VoltageReferenceSelect(ADC_ID_1, ADC_REFERENCE_VDD_TO_AVSS ); /* Include all channels in scan */ PLIB_ADC_InputScanMaskAdd(ADC_ID_1, PORTS_ANALOG_PIN_23); /*Internal Counter triggers conversion*/ PLIB_ADC_ConversionTriggerSourceSelect(ADC_ID_1, ADC_CONVERSION_TRIGGER_INTERNAL_COUNT); // Sample Time ADC_SampleAcquisitionTimeSet_Default(ADC_ID_1, 60); PLIB_ADC_ConversionClockSet(ADC_ID_1, SYS_CLK_BUS_PERIPHERAL_1, 32); // Set the interrupt PLIB_ADC_SamplesPerInterruptSelect(ADC_ID_1, 1); // Enable scanning of channels PLIB_ADC_MuxAInputScanEnable(ADC_ID_1); // Enable the ADC PLIB_ADC_Enable(ADC_ID_1); // Start Sampling the ADC PLIB_ADC_SampleAutoStartEnable(ADC_ID_1); This is how i read the value: while(!PLIB_ADC_ConversionHasCompleted(ADC_ID_1)) //while(!DRV_ADC_SamplesAvailable()) { /*Timeout verification*/ timer--; if(timer==0x00) { Nop(); break; } } /*Check if variable its not timeout*/ if(timer!=0x00) { read = ADC_ResultGetByIndex_Default(ADC_ID_1,0); } Thanks, |
|
相关推荐
2个回答
|
|
这个代码对我来说绝对适用。
以上来自于百度翻译 以下为原文 /* Select Clock Source */ PLIB_ADC_ConversionClockSourceSelect(DRV_ADC_ID_1, ADC_CLOCK_SOURCE_SYSTEM_CLOCK); /* Select Clock Prescaler */ PLIB_ADC_ConversionClockSet(DRV_ADC_ID_1, SYS_CLK_BUS_PERIPHERAL_1, 320000000); /* Select Power Mode */ PLIB_ADC_StopInIdleDisable(DRV_ADC_ID_1); /* Select Voltage Reference */ PLIB_ADC_VoltageReferenceSelect(DRV_ADC_ID_1, ADC_REFERENCE_VDD_TO_AVSS); /* Sampling Selections */ /* Select Sampling Mode */ PLIB_ADC_SamplingModeSelect(DRV_ADC_ID_1, ADC_SAMPLING_MODE_MUXA); /* Number of Samples Per Interrupt */ PLIB_ADC_SamplesPerInterruptSelect(DRV_ADC_ID_1, ADC_1SAMPLE_PER_INTERRUPT); /* Conversion Selections */ /* Select Trigger Source */ PLIB_ADC_ConversionTriggerSourceSelect(DRV_ADC_ID_1, ADC_CONVERSION_TRIGGER_INTERNAL_COUNT); /* Select Result Format */ PLIB_ADC_ResultFormatSelect(DRV_ADC_ID_1, ADC_RESULT_FORMAT_INTEGER_16BIT); /* Buffer Mode */ PLIB_ADC_ResultBufferModeSelect(DRV_ADC_ID_1, ADC_BUFFER_MODE_ONE_16WORD_BUFFER); /* Channel Selections */ /* MUX A Negative Input Select */ PLIB_ADC_MuxChannel0InputNegativeSelect(DRV_ADC_ID_1, ADC_MUX_A, ADC_INPUT_NEGATIVE_VREF_MINUS); PLIB_PORTS_PinModeSelect(PORTS_ID_0, GPIO_ANALOG_PIN_0, PORTS_PIN_MODE_ANALOG); PLIB_PORTS_AnPinsModeSelect(PORTS_ID_0, PORTS_AN_PIN_4, PORTS_PIN_MODE_ANALOG); PLIB_PORTS_PinDirectionInputSet(PORTS_ID_0, GPIO0PORT, GPIO0POS); DRV_ADC_PositiveInputSelect(ADC_MUX_A, ADC_INPUT_POSITIVE_AN4); DRV_ADC_Open(); DRV_ADC_Start(); if(DRV_ADC_SamplesAvailable()) { AdcResult = DRV_ADC_SamplesRead(0); } DRV_ADC_Close(); *(dataPtr) = *((uint8_t *)&AdcResult + 1); dataPtr ++; *dataPtr = *((uint8_t *)&AdcResult); dataPtr++; This code works absolutely fine for me. |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
778浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
677浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 09:57 , Processed in 1.518685 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号