This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

potentiometer reading

I have some issue with analog reading, but when it shown in putty, the reading from potentiometer is not changing when I turn the knob. Here is the code that I wrote:

#include <stdint.h>
#include <stdbool.h>
#include "stdlib.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_timer.h"
#include "inc/hw_uart.h"
#include "inc/hw_gpio.h"
#include "inc/hw_pwm.h"
#include "inc/hw_types.h"
#include "driverlib/adc.h"
#include "driverlib/pin_map.h"
#include "driverlib/timer.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/udma.h"
#include "driverlib/pwm.h"
#include "driverlib/ssi.h"
#include "driverlib/systick.h"
#include <string.h>

#define TARGET_IS_TM4C123_RB1
#define UART_BUFFERED
volatile uint32_t millis=0;

void SycTickInt()
{
millis++;
}

void SysTickbegin()
{
SysTickPeriodSet(80000);
SysTickIntRegister(SycTickInt);
SysTickIntEnable();
SysTickEnable();
}

void Wait(uint32_t time){
uint32_t temp = millis;
while( (millis-temp) < time){
}
}

void InitConsole(void)
{

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioConfig(0, 115200, 16000000);
}

int main(void)
{
uint32_t ADCValues[1];
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
SysTickbegin();
InitConsole();

UARTprintf("ADC ->\n");
UARTprintf(" Type: Potentiometer\n");
UARTprintf(" Samples: One\n");
UARTprintf(" Update Rate: 250ms\n");
UARTprintf(" Input Pin: PIN E3 \n\n");

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);


while(1)
{
ADCIntClear(ADC0_BASE, 3);
ADCProcessorTrigger(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, ADCValues);
UARTprintf("value = %2d \n" , ADCValues);

SysCtlDelay(80000000 / 12);
}
}

Thanks,

Ferry

  • Ferry,


    What device are you using? How do you have your circuit hooked up and what are you measuring? A schematic might help show that. We'll need a lot more detail in order to help you.

    If you're having problems with communication, you should also get an oscilloscope or logic analyzer to show the communication. In general it helps to show the same information shown in the timing diagrams.


    Joseph Wu