Tool/software: TI C/C++ Compiler
Hi there,
I'm new to Tiva. I tried to write a code to generate a sine wave for sound generation in Embedded C. I've used the FPU to generate sound. I don't know the bit shift method which converts 32 bit value to 8 bit value. My code generates the value of 32 bit, i need to write 8 bit value. Anyone here would help me?
Below is my code:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include <math.h>
#include "driverlib/fpu.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#define PWM_FREQUENCY 55
#endif
#define SERIES_LENGTH 100
float gSeriesData[SERIES_LENGTH];
volatile uint32_t a =0;
volatile uint32_t b =0;
volatile uint32_t c =0;
volatile uint32_t d =0;
volatile uint8_t j =0;
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // set up the clock
// SysCtlPWMClockSet(SYSCTL_PWMDIV_64);
// SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // enable port A for Switch
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // enable port B for DAC
SysCtlDelay(3);
//GPIOPinTypePWM(GPIO_PORTD _BASE, GPIO_PIN_0);
//GPIOPinConfigure(GPIO_PB0_M1PWM0);
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
GPIOPadConfigSet(GPIO_PORTA_BASE,GPIO_PIN_2,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); // Internal pull down resistor for pin2
FPULazyStackingEnable();
FPUEnable();
// uint32_t ui32PinData;
float fRadians;
int32_t i32DataCount = 0;
uint8_t i = 0;
fRadians = ((2 * M_PI) / SERIES_LENGTH);
while(1)
{
a = GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_2);
if(a==0)
{
while(i32DataCount < SERIES_LENGTH)
{
gSeriesData[i32DataCount] = 100*sinf(fRadians * i32DataCount);
for (i=0; i<=100; i++)
{
// j = 100*gSeriesData[i];
GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, gSeriesData[i]);
}
i32DataCount++;
}
i32DataCount =0;
}
}
}
Also, can anyone tell me if I'm wrong anywhere in implementation? I've referred the FPU code from : www.cse.iitb.ac.in/.../TM4C123G_LaunchPad_Workshop_Workbook.pdf