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.

Fault in ADC.c Tiva C library

Hello,

My goal here is to get PWM1 (generator 2) to trigger adc sequence. Here is my PWM configuration:

// Configure PWM for PORTF1
void ConfigurePWM(void)
{
    // Set the PWM clock to the system clock.
    SysCtlPWMClockSet(SYSCTL_PWMDIV_4);

	// Enable PWM peripheral and gpio peripheral
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);

	// Configure GPIO pin to pwm mode
	GPIOPinConfigure(GPIO_PF1_M1PWM5);
	GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);

	// Configure PWM1
    //PWM_GEN_2 Covers M1PWM4 and M1PWM5
    //PWM_GEN_3 Covers M1PWM6 and M1PWM7
    PWMGenConfigure(PWM1_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
    PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_2, PWM_INT_CNT_ZERO | PWM_TR_CNT_ZERO);

    // Set pwm resolution 10 bits. With PWM clock set to 1/4 sys clock, pwm period is ~20 kHz
    PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, 0x3FF);

    // Set PWM to zero
    PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, 1);

    // Enable the PWM1 Bit 5 (PF1)
    PWMOutputState(PWM1_BASE, PWM_OUT_5_BIT, true);


    PWMIntEnable(PWM1_BASE, PWM_INT_GEN_2);
    IntEnable(INT_PWM1_2);

    // Enables the counter for a PWM generator block.
    PWMGenEnable(PWM1_BASE, PWM_GEN_2);
}

And here is my ADC configuration:

// Configure ADC0 AIN6 (PD1) to analog input
void ConfigureAdc(void)
{
	// Enable adc peripherals
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	// Set hardware averaging
	ADCHardwareOversampleConfigure(ADC0_BASE, 2);

	// Change pin type for adc compatible
	GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1);

	// Configure adc sequencer. ADC sequence will be synchronized to pwm generator
	ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PWM2 | ADC_TRIGGER_PWM_MOD1, 0);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH6 | ADC_CTL_IE | ADC_CTL_END);

	// Clear pending adc interrupt flag
	ADCIntClear(ADC0_BASE, 1);
	// Enable Adc
	ADCSequenceEnable(ADC0_BASE, 1);

	// Configure adc interrupt
	ADCIntEnable(ADC0_BASE, 1);

	IntEnable(INT_ADC0SS1);
}

The problem occurs when Configurating adc-sequence. When setting triggers in ADCSequenceConfigure function, the ADC_TRIGGER_PWM2 | ADC_TRIGGER_PWM_MO1 sets register values as follows:

ADC_TSSEL: 0x00001000

ADC_EMUX: 0x00000080

How ever the correct value should be 

ADC_TSSEL: 0x00100000

ADC_EMUX: 0x00000080

I did look into this problem and if I increase the sequence number in ADCSequenceConfigure from 1 to 2, the register values are as follows:

ADC_TSSEL: 0x00100000

ADC_EMUX: 0x00000800

As we can see, this doesn't work either. The problem seems to be that the values to the ADC_TSSEL register are shifted by the adc sequence number, not by the ADC_TRIGGER_PWM2 value.

I'm using TivaWare_C_Series-2.1.0.12573. I hope someone can confirm my problem.