5316 views|4 replies

3

Posts

0

Resources
The OP
 

How to use ADC module to measure external voltage [Copy link]

I am using the tiva c TM4C123GH6PM board, and now I want to use the ADC module to measure the external DC voltage. Then I use the PD0 pin to connect the external voltage value to be measured, and then connect the GND pin to the ground of the circuit to be measured. But I can't measure the value. Even if I change the external voltage, the measured value of the ADC module is always a fixed value. The main program is as follows. I hope you can help! ! #include
#include
#include
#include
#include
#include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/hw_ints.h" #include "inc/hw_gpio.h" #include "inc/hw_sysctl.h" #include "inc/ hw_adc.h" #include "driverlib/adc.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" #include "driverlib/systick.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/ssi. h" #include "uc1701.h" //ADC initializer void ADC_Init() { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_0); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0); ADCSequenceConfigure(ADC0_BASE,1,ADC_TRIGGER_PROCESSOR, 0); ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0); ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, 1); } uint32_t ui32ADC0Value[4]; uint32_t num0; int main() { SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ADC_Init(); UC1701Init(60000); UC1701Clear(); while(1) { UC1701CharDispaly(0, 1, "I love tiva-pb?"); ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value); num0 = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4; UC1701DisplayN(1,1,num0); UC1701Clear(); } } [ size=5]



This post is from Microcontroller MCU

Latest reply

The third post has the correct answer. Try using the official routine first. If the official routine can measure the voltage correctly, it means there is something wrong with the program.   Details Published on 2018-12-7 18:40
 

2

Posts

1

Resources
2
 
As for the circuit, there may be something wrong with your circuit itself.
This post is from Microcontroller MCU
 
 

9703

Posts

24

Resources
3
 
It should be a code problem. Try using TI's official ADC routine first. Do not measure the external voltage first. Try connecting the ADC input pin to GND or the MCU power supply to see if there is any change. After it is adjusted, measure the external voltage again.
This post is from Microcontroller MCU
 
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 

6570

Posts

0

Resources
4
 
The TM4C123GH6PM circuit diagram is not posted, so it is difficult to judge. There are many circuit problems.
This post is from Microcontroller MCU
 
 
 

6366

Posts

4936

Resources
5
 
The third post has the correct answer. Try using the official routine first. If the official routine can measure the voltage correctly, it means there is something wrong with the program.
This post is from Microcontroller MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list