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.

how many max sample adc can i get when I use TM4c123 kit

how many max  sample adc can i get when I use TM4c123 kit

I trigger frequency PwM at 20khz but I can't read value ADC , It is not enough ? 

when I  trigger frequency PwM at 5khz it work ok?

thankyou

  • Hi,
    The best idea is to post some code to see if some problems may be there. Only speculating is waisting time...
  • that is my code
    in program interrup pwm , 3 led not worked,


    #include"stdbool.h"
    #include"stdint.h"
    #include "stdio.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_ints.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pwm.h"
    #include "driverlib/adc.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include <string.h>
    #include "inc/hw_uart.h"
    #include "driverlib/uart.h"
    #include "driverlib/interrupt.h"

    #define LED_RED GPIO_PIN_1
    #define LED_GREEN GPIO_PIN_2
    #define LED_BLUE GPIO_PIN_3

    int iVal;
    int loi1,loi2;
    int j;
    uint32_t adcbuffer[4];
    uint32_t dong,dong_cu,ie,k;
    uint32_t dong1,dong2,dong3,t,f,q;
    void PWM0IntHandler(void)
    {
    PWMGenIntClear(PWM0_BASE, PWM_GEN_0, PWM_INT_CNT_LOAD); // clear int
    while(!ADCIntStatus(ADC0_BASE, 1, false)){} // Wait for conversion to be completed.
    //Clear the ADC interrupt flag.
    ADCSequenceDataGet(ADC0_BASE, 1, adcbuffer); // Read ADC Value.
    ADCIntClear(ADC0_BASE, 1);
    dong1 = adcbuffer[0];
    dong2 = adcbuffer[1];
    dong3 = adcbuffer[2];
    GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|GPIO_PIN_3, 0xFF);
    }
    void main()
    {


    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    //PortF Enable
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));


    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    //Config GPIO that connect to LED - PIN 1,2,3
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_GREEN|GPIO_PIN_3);
    //Turn off all LEDs
    //GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|GPIO_PIN_3, 0x00);



    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);


    GPIOPinConfigure(GPIO_PB6_M0PWM0); // cau hinh chan pb6 lam pwm
    GPIOPinConfigure(GPIO_PB4_M0PWM2);
    GPIOPinConfigure(GPIO_PE4_M0PWM4);


    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4);
    GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_4);
    // GPIOPinTypePWM(GPIO_PORTC_BASE, GPIO_PIN_4);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC);
    PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_UP_DOWN| PWM_GEN_MODE_NO_SYNC);
    // PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC);

    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0,2500 );
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1,2500 );
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2,2500 );

    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 0);

    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,0);
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, 0);



    PWMGenEnable(PWM0_BASE, PWM_GEN_0);
    PWMGenEnable(PWM0_BASE, PWM_GEN_1);
    PWMGenEnable(PWM0_BASE, PWM_GEN_2);




    // cau hinh GPIO

    GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_7);
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4 );
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4 );


    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_3 );
    GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6 );


    GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6 );//dau doc hall

    //t PWM
    PWMGenIntRegister(PWM0_BASE,PWM_GEN_0,PWM0IntHandler);
    PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0);
    PWMGenIntTrigEnable(PWM0_BASE,PWM_GEN_0,PWM_INT_CNT_LOAD);
    PWMGenIntTrigEnable(PWM0_BASE,PWM_GEN_0,PWM_TR_CNT_LOAD);
    IntMasterEnable();
    // adc
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); // Configuring PE1 as ADC input
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); // Configuring PE2 as ADC input
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Configuring PE2 as ADC input
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PWM0 , 0);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH2 );
    ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1 );
    ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0|ADC_CTL_IE | ADC_CTL_END );
    ADCSequenceEnable(ADC0_BASE, 1);



    while(1)
    {

    }
    }
  • Hello Vu,

    There are 2 parameters when using PWM. One is the PWM Module and other is the Generator

    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PWM0 , 0);

    Only the PWM is mentioned and not the generator!!!

    Regards
    Amit
  • I configured Adc after pwm modul run so it is not working
    that my problem
    thank for your help