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.

CCS/TM4C123GH6PM: i want to write code for interface two potentiometer with tm4c123gxl according that i need to control speed of motor.

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

for below code what i need to change so i can interface two potentiometer.

when i try this simultenously it not control  the motor speed.

in my this program i have to control speed of motor using two potentiometer.

#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_memmap.h"
#include"driverlib/gpio.h"
#include"inc/hw_types.h"
#include"driverlib/debug.h"
#include"driverlib/sysctl.h"
#include"driverlib/adc.h"
// TO STORE THE VALUE IN VARIABLE ui32ADC0Value FOR EVERY SAMPLING//

uint32_t ui32ADC0Value[1],ui32ADC0Value1[1];
int main(void)
{
// SYSTEM CLOCK AT 40MHZ
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // ENABLE ADC0 MODULE
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1); // ENABLE ADC0 MODULE

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // ENABLE GPIO for ADC0
//MODULE
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);// ENABLE AN0 OF ADC0 MODULE
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_2);// ENABLE AN0 OF ADC0 MODULE

// ADC0 MODULE, TRIGGER IS PROCESSOR EVENT, SEQUENCER 0 IS CONFIGURED
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC1_BASE, 1, ADC_TRIGGER_PROCESSOR, 1);
// ADC0 MODULE, SEQUENCER 0 , FOR 1 SAMPLING, INPUT IS FROM CHANNEL 0 PE3
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC1_BASE, 1, 1, ADC_CTL_CH1);
// ENABLE THE SEQUENCE 1 FOR ADC0
ADCSequenceEnable(ADC0_BASE, 1);
ADCSequenceEnable(ADC1_BASE, 1);
while(1)
{
// CLEAR INTERRUPT FLAG FOR ADC0, SEQUENCER 1
ADCIntClear(ADC0_BASE, 1);
ADCIntClear(ADC1_BASE, 1);
// TRIGGER IS GIVEN FOR ADC 0 MODULE, SEQUENCER 1
ADCProcessorTrigger(ADC0_BASE, 1);
ADCProcessorTrigger(ADC1_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}

//
// Clear the ADC interrupt flag.
//
ADCIntClear(ADC0_BASE, 3);

// STORE THE CONVERTED VALUE FOR ALL DIFFERENT SAMPLING IN ARRAY
//ui32ADC0Value
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
ADCSequenceDataGet(ADC1_BASE, 1, ui32ADC0Value1);
}
}

  • Hi Mangal,

    Have you had a chance to reference the TivaWare examples? Please take at look how the example works. The example can be found in <TivaWare_Installation>/examples/peripheral/adc.

    I have some comments with your code. First thing is that I think your intention is to use two different sequencers from only one ADC module but you are configuring two different ADC modules. Please clarify if you really wanted to use two ADC modules or two different ADC sequencers from one ADC module. From what I see from your application you can do with just one ADC module. But if you want to use two ADC modules it is fine as well. Please note that there are two ADC modules in the chip. Each ADC module has 4 sequencers. Each sequencer can support different number of channels.

    The second comment is for the below code. You setup the priority 0 for ADC0 sequencer 1 and priority 1 for ADC1 sequencer 1. The priority level is only needed if you are using sequencers within the same ADC module. Since you are using two different ADC modules the priority can be set to 0 for each.

    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceConfigure(ADC1_BASE, 1, ADC_TRIGGER_PROCESSOR, 1);

    The third comment is on the below code. Sequencer 1 can support 4 steps. You are assigning CH0 to step 0. But you need to also tell the sequencer that step 0 is also the last step. Otherwise, the ADC doesn't know what to do with the other 3 steps. You need to qualify with ADC_CTL_END to tell the ADC that step 0 is also the last step.
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);


    The fourth comment is on the below code. You are assigning CH1 to step 1 of the sequencer 1 of ADC1. You need to again tell the ADC1 that step 1 is the last step of the sequencer 1.
    ADCSequenceStepConfigure(ADC1_BASE, 1, 1, ADC_CTL_CH1);

    I really think you should reference the TivaWare example. If you want to use two ADC modules, that is fine. If that is the case, why don't you use the sequencer 3 which supports only one step? You can assign one channel to ADC0 sequencer 3 and another channel to ADC1 sequencer 3. Why wouldn't you even consider assigning two channels to just one sequencer such as sequencer 1 of just one ADC module? The sequencer 1 can support 4 steps. You can assign two ADC channels to sequencer 1. Once the sequencer 1 is triggered it will sample both channels one at a time. Wouldn't that be easier.
  • Sir I want handle two interrupt. But I not know how to handle two interrupt in interrupt handler because both  

    ADC will send interrupt when conversion completes .

  • Not sure if you went through my last reply. If you use two different ADC modules or two different sequencers then you will get two different interrupt requests. You will need to have two different ISR to handle the two interrupts separately. As I suggested in my last reply, if you use only one sequencer that samples two ADC channels then you only have one interrupt. When the interrupt occurs, it means both channels have been sampled and converted.