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.

Conveting ADC value in the buffer

Other Parts Discussed in Thread: LM3S3748

Hi,

I am using the Tiva C series Launchpad to sample two channels and to display it in a GLCD for an oscilloscope project. I configured two ADC modules and initiated the sampling. The code is shown below. I will be needing only the MSB 6 bits of the ADC value. So I use a separate 8 bit word to store the values. But I am not able to display anything on the GLCD. When I try giving default values for the adcdata, I get a perfect sine wave. Please help me out.

void PortFunctionInit(void){
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);			// Port A for control pins
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);			// Port B for data pins
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);			// For ADC pins
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);			// Port E for ADC inputs
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);			// Port F for LED lights
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);				// The ADC0 peripheral must be enabled for use.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);				// The ADC1 peripheral must be enabled for use.
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0);			// Configuring PD0 as ADC input (channel 1) 	CH7	ADC0
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1);			// Configuring PD1 as ADC input (channel 2)	CH6	ADC1
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2);			// Configuring PD2 as ADC input (time base)	CH5
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3);			// Configuring PD3 as ADC input (trigger level)	CH4
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);			// Configuring PE0 as ADC input (X-POS)		CH3
}

int main(void)
{
	uint8_t adc0data[128],adc1data[128];
	uint32_t timebase,triglvl,xpos,adcbuffer[1],i;
	SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); //20 MHz clock
	PortFunctionInit();
	GLCD_Initalize();
	GLCD_ClearScreen();
	uint8_t sinwav[128] = {0x20,0x25,0x2A,0x2F,0x33,0x37,0x3A,0x3C,0x3E,0x3F,0x3F,0x3E,0x3C,0x3A,0x36,0x32,0x2E,0x29,0x24,0x1F,0x19,0x14,0x10,0x0B,0x08,0x05,0x02,0x01,0x00,0x00,0x01,0x03,0x06,0x09,0x0D,0x12,0x17,0x1C,0x21,0x26,0x2B,0x30,0x34,0x38,0x3B,0x3D,0x3E,0x3F,0x3F,0x3D,0x3B,0x39,0x35,0x31,0x2C,0x28,0x22,0x1D,0x18,0x13,0x0E,0x0A,0x07,0x04,0x02,0x00,0x00,0x00,0x02,0x04,0x07,0x0A,0x0F,0x13,0x18,0x1D,0x23,0x28,0x2D,0x31,0x35,0x39,0x3C,0x3E,0x3F,0x3F,0x3E,0x3D,0x3B,0x38,0x34,0x30,0x2B,0x26,0x21,0x1C,0x16,0x12,0x0D,0x09,0x06,0x03,0x01,0x00,0x00,0x01,0x02,0x05,0x08,0x0C,0x10,0x15,0x1A,0x1F,0x24,0x29,0x2E,0x33,0x36,0x3A,0x3C,0x3E,0x3F,0x3F,0x3E,0x3C,0x3A,0x37};
	/*while(1)
	{
		GLCD_ClearScreen();
		for(i=64;i<128;i++)
			GLCD_SetPixel(i,63-sinwav[i-64]);
		for(i=0;i<63;i++)
			GLCD_SetPixel(i,63-sinwav[i+64]);
		for(i=0;i<1000;i++)
			SysCtlDelay(1000);
	}*/

	ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
	ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);
	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);
	ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_CH4 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 2);
	ADCSequenceEnable(ADC0_BASE, 3);
	ADCSequenceEnable(ADC1_BASE, 3);

	ADCIntClear(ADC0_BASE, 2);
	ADCIntClear(ADC0_BASE, 3);
	ADCIntClear(ADC1_BASE, 3);

	while(1)
	{
		ADCIntClear(ADC0_BASE, 2);
		ADCProcessorTrigger(ADC0_BASE, 2);			// Trigger the ADC conversion.
		while(!ADCIntStatus(ADC0_BASE, 2, false)){}		// Wait for conversion to be completed.
		ADCIntClear(ADC0_BASE, 2);				// Clear the ADC interrupt flag.
		ADCSequenceDataGet(ADC0_BASE, 3, adcbuffer);		// Read ADC Value.
		timebase = adcbuffer[0];
		for (i=0;i<128;i++)
		{
			ADCIntClear(ADC0_BASE, 3);
			ADCIntClear(ADC1_BASE, 3);
			ADCProcessorTrigger(ADC1_BASE, (3|ADC_TRIGGER_WAIT));		// Put ADC-1 in Trigger Wait
			ADCProcessorTrigger(ADC0_BASE, (3|ADC_TRIGGER_SIGNAL));		// Put ADC-0 in Global Trigger
			while(!ADCIntStatus(ADC0_BASE, 3, false)){}			// Wait for conversion to be completed.
			ADCIntClear(ADC0_BASE, 3);					// Clear the ADC interrupt flag.
			ADCIntClear(ADC1_BASE, 3);					// Clear the ADC interrupt flag.
			ADCSequenceDataGet(ADC0_BASE, 3, adcbuffer);			// Read ADC Value.
			adc0data[i] = adcbuffer[0]>>8;
			ADCSequenceDataGet(ADC1_BASE, 3, adcbuffer);			// Read ADC Value.
			adc1data[i] = adcbuffer[0]>>8;
		}
		GLCD_ClearScreen();
		for(i=0;i<128;i++)
		{
			GLCD_SetPixel(i,adc0data[i]);
			GLCD_SetPixel(i,adc1data[i]);
		}

	}
}

Regarding the code, the array sinwav is just a sample waveform which will be used by the commented code right next to it to check if a sine wave can be displayed on the GLCD.

Thanks in advance.

  • Hi,

       Have you tried to display anything before at your GLCD, like "Hello". Provide more details about this GLCD. Is this the Kentec Boosterpack?

    -kel

  • Hi,

    I am using a JHD12864E GLCD which uses the KS0108 controller. I am not using any booster pack, just the GLCD module by connecting through wires. And I forgot to ask one more question: is there a watch window available so that I can view the contents of certain variables while running the code in real time ?

    Thank you

  • Hi,

    From your first post in this thread, it is not clear how do you configure the system clock - you need to check because there are some problems, highlighted in the errata sheet. Also some problems with sequencer 2 and 3 used by you. 

    But the main problem seems to be you did not correctly understand what is an sequencer and how must be used. Let me explain: a sequencer is a hardware bundle implemented to help the user to trigger several conversions with a single command - so you can configure a single sequencer to sample different or the same channel(s) - you speed up the conversion rate, asked by you in another thread. So you can simplify your code.

    About your code not showing the waveform: you put your ADC on wait, but what trigger it to acquire samples? (128)

    Also, if you have previous StellarisWare versions or you still can find the related files for LM3S3748 (if I remember well), there was an example application for an oscilloscope based on Cortex-M3 micro.

    Petrei