Part Number: EK-TM4C123GXL
Tool/software: Code Composer Studio
Hi, I'm Sung Min.
I don't Know why my output waveform is not correct
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
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);
}
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
void
ConfigureUART(void)
{
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 115200, 16000000);
}
int
main(void)
{
float a;
float b;
MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_8);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
MAP_GPIOPinConfigure(GPIO_PB6_M0PWM0);
MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
PWM_GEN_MODE_NO_SYNC);
MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, (SysCtlClockGet() / 250));
MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
uint32_t ui32SysClock;
#endif
uint32_t pui32ADC0Value[1];
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
//
// Note: SYSCTL_CFG_VCO_240 is a new setting provided in TivaWare 2.2.x and
// later to better reflect the actual VCO speed due to SYSCTL#22.
//
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_240), 20000000);
#else
SysCtlClockSet(SYSCTL_SYSDIV_16 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_1MHZ);
#endif
InitConsole();
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
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);
ADCIntClear(ADC0_BASE, 3);
while(1)
{
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
UARTprintf("AIN0 = %d\n", pui32ADC0Value[0]);
a=pui32ADC0Value[0];
b=a-1970;
if (b>100)
{
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0);
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0.999);
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0);
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0.999);
SysCtlDelay(100000);
}
else
{
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0.999);
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0);
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0.999);
MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) *0);
SysCtlDelay(100000);
}
}
}
above is my code
and I want to make the output square form(0101)when some input(b>100) and else when(b<100) I want to make the output square waveform (1010)
but the Oscilloscope's waveform is not same what I think
Do Anyone knows the reason?
During this month, I have been doing this part of project.
But anyone don't know the reason of the error