Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE HELP Signal pass through from ADC to DAC with Ping-Pong buffering. Create a new CCS project Lab8_2. The input and output setup of this
PLEASE HELP
Signal pass through from ADC to DAC with Ping-Pong buffering. Create a new CCS project Lab8_2. The input and output setup of this lab is exactly same as Problem 1. Use the Ping-Pong buffering technique to implement the same signal pass-through functionality as in Lab8_1. Triple buffering technique was used in Lab8_1, which is different from the Ping-Pong buffering. Ping-Pong buffering is explained in class and briefly summarized in the lecture notes. Explain in your report how the Ping-Pong buffering technique works.
#include#include #include #include //Exact-width integer types #include //Driver library #define CLOCK_HF 48000000 //48MHz #define CLOCK_LF 32000 //32kHz #define TIMER0_FREQ 1 //unit: Hz #define SAMPLE_FREQ 32000 //Frequency in Hz, common sampling rates for digital audio: 8000, 32000, 44100, 48000 #define MCP4921_SPI_BITRATE 20e6 //needs to > SAMPLE_FREQ*16, and < SMCLK/2, max 20M #define MCP4921_SPI_DATA_MASK 0x0FFF //See datasheet, MCP4921 #define MCP4921_SPI_CTRL_MASK 0x7000 //See datasheet, MCP4921 #define RED_LED GPIO_PIN0 #define GREEN_LED GPIO_PIN1 #define BLUE_LED GPIO_PIN2 #define NUM_DISP_TEXT_LINE 4 // Definitions for triple buffering. #define NUM_DATA_BUFFER 3 #define DATA_BUFFER_LEN 200 //Function prototypes void initDevice_HFXT(void); void initGPIO(void); void initTimer(void); void initUART(void); void initADC14(void); void initSPI(void); void initDataBuffer(void); void processData(void); void uart0_transmitStr(const char *str); //Global variables uint32_t clockMCLK, clockSMCLK; uint8_t currentLED = RED_LED; volatile uint32_t dataBuffer[NUM_DATA_BUFFER][DATA_BUFFER_LEN]; volatile uint32_t buf_inputIndex=0, buf_outputIndex=1, buf_dataIndex=2; volatile bool buf_dataReady=false, buf_overrunError=false; const char *terminalDisplayText[NUM_DISP_TEXT_LINE] = { " ", "Signal Pass-through with triple buffering ", "R: Red, G: Green, B: Blue, H: Help ", "> " }; void main(void) { uint32_t i; uint8_t data; initDevice_HFXT(); initGPIO(); initTimer(); initUART(); initADC14(); initSPI(); initDataBuffer(); Interrupt_enableMaster(); Timer32_startTimer(TIMER32_0_BASE, false); // Initial display on terminal. for(i=0; i "); break; case 'G': case 'g': currentLED = GREEN_LED; uart0_transmitStr("Blink green LED. > "); break; case 'B': case 'b': currentLED = BLUE_LED; uart0_transmitStr("Blink blue LED. > "); break; case 'H': case 'h': for(i=0; i >8); b0 = (uint8_t) data; //SPI is written with register-level operation. P5->OUT &= ~BIT2; //Set CS to LOW on SPI slave. for(i=0; i<2; i++); //delay at least 40ns, t_CSSR. EUSCI_B0->TXBUF = b1; //Transmit Byte 1 while(!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG)); //Check if TX buffer is ready, no need to clear the flag TXIFG. EUSCI_B0->TXBUF = b0; //Transmit Byte 0 while(!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG)); //Check if TX buffer is ready, no need to clear the flag TXIFG. //LDAC tied to GND, so transfer on rising edge of CS. P5->OUT |= BIT2; //Set CS to HIGH on SPI slave. //Update buffer indices and sample index. if(++sampleIndex >= DATA_BUFFER_LEN) { sampleIndex = 0; if(buf_dataReady) { buf_overrunError = true; } tmpIndex = buf_inputIndex; buf_inputIndex = buf_outputIndex; buf_outputIndex = buf_dataIndex; buf_dataIndex = tmpIndex; buf_dataReady = true; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started