Jump to content
Forum sending old emails Read more... ×

oam4647

Members
  • Content Count

    3
  • Joined

  • Last visited

  1. oam4647

    tiva c verifying system clock frequency

    I used Timer A to trigger the ADC so I could vary the sampling frequency. I am also trying to configure it for SPI setup too, so I apologize if it looks messy. The problem is that the ADC is not sampling at higher frequencies when we change sample_rate. I am not sure why. Thanks for the help. Here is the code: #include <stdint.h> #include <stdbool.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/debug.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/pin_map.h" #include "driverlib/rom.h" #include "driverlib/rom_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/adc.h" #include "driverlib/timer.h" #include "driverlib/ssi.h" #include "utils/uartstdio.h" #include <stdlib.h> //***************************************************************************** // // Number of bytes to send and receive. // //***************************************************************************** #define NUM_SSI_DATA 3 //**************************************************************************** //! This code configures the internal ADC, samples the input signal at a //! specified frequency using a timer, and then sends that data through the USB //! using the FIFO with the UART. The FIFO depth is 1 byte. //! //! This example uses the following peripherals and I/O signals. You must //! review these and change as needed for your own board: //! - ADC0 peripheral //***************************************************************************** uint32_t g_ui32SysClock; // System clock rate in Hz. uint32_t sample_rate; //sample rate for adc in Hz uint32_t pui32ADC0Value[1]; // adc value sent to USB uint32_t pui8Buffer[4]; // break down 32 bit value to 4 8-bit values int32_t Recieved_USB[64]; // ?? uint8_t flag_timer = 0; // not doing anything uint32_t a; uint32_t clock_speed; uint32_t adc_sample_rate; int test_value = 1234; char test_value_string[10]; #ifdef DEBUG // The error routine that is called if the driver library encounters an error. void __error__(char *pcFilename, uint32_t ui32Line) { } #endif void// The UART interrupt handler. UARTIntHandler(void) { uint32_t ui32Status; // // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART0_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // int i = 0; for(i=0; ROM_UARTCharsAvail(UART0_BASE) > 0; i++) { Recieved_USB = UARTCharGetNonBlocking(UART0_BASE); } if ((Recieved_USB[0] == 87) && (Recieved_USB[1] == 65) && (Recieved_USB[2] == 75) && (Recieved_USB[3] == 69) && (Recieved_USB[4] == 85) && (Recieved_USB[5] == 80) && (Recieved_USB[6] == 13)){ //itoat(test_value, test_value_string, 10); // Enable the timer TimerEnable(TIMER0_BASE, TIMER_A); } //SysCtlDelay(g_ui32SysClock / (1000 * 3)); } //void// Send a string to the UART //UARTSend(uint32_t pui32Buffer) //{ // // separate 32-bit value to 4 8-bit values to send to USB // pui8Buffer[3] = (pui32Buffer & 0xff000000) >> 24; // pui8Buffer[2] = (pui32Buffer & 0x00ff0000) >> 16; // pui8Buffer[1] = (pui32Buffer & 0x0000ff00) >> 8; // pui8Buffer[0] = (pui32Buffer & 0x000000ff) ; // // int result = 0; // int n; // for (n=3;n>-1;n--){ // result = 0; // while(result ==0) // { // // send result to USB // result = ROM_UARTCharPutNonBlocking(UART0_BASE, pui8Buffer[n]); // } // } //} void// Send a string to the UART UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) { int result = 0; // // Loop while there are more characters to send. // while(ui32Count--) { // // Write the next character to the UART. // result = 0; while(result ==0) { // send result to USB result = ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++); } } while(result ==0) { // send result to USB result = ROM_UARTCharPutNonBlocking(UART0_BASE, 13); } } void ADC0IntHandler(void) { // clear interrupt status flag ADCIntClear(ADC0_BASE, 3); // get ADC value, store in pui32ADC0Value ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value); // call UART send function //UARTSend(pui32ADC0Value[0]); //adc_sample_rate = SysCtlADCSpeedGet(); //UARTSend((uint8_t *)"Hello World", 16); } // Implementation of itoa() //char* itoat(int num, char* str, int base) //{ // int i = 0; // bool isNegative = false; // // /* Handle 0 explicitely, otherwise empty string is printed for 0 */ // if (num == 0) // { // str[i++] = '0'; // str = '\0'; // return str; // } // // // Process individual digits // while (num != 0) // { // int rem = num % base; // str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0'; // num = num/base; // } // // // str = '\0'; // Append string terminator // // // Reverse the string // //reverse(str, i); // // return str; //} //***************************************************************************** // // // // // //***************************************************************************** int main(void) { // Set the clocking to run directly from the crystal at 120MHz. g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // g_ui32SysClock = 120000000; // SysCtlClockSet(SYSCTL_XTAL_16MHZ | // SYSCTL_OSC_INT | // SYSCTL_USE_PLL | // SYSCTL_CFG_VCO_480); sample_rate = 500000; // just for testing, sets sample rate to 96khz // Enable the GPIO port that is used for the on-board LED. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // Enable the GPIO pins for the LED (PN0). ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); // Enable the peripherals used by this example. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable processor interrupts. ROM_IntMasterEnable(); // Set GPIO A0 and A1 as UART pins. GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Configure the UART for 115,200 Baud rate, 8-N-1 operation. ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable the UART interrupt. ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // The ADC0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //added epw ADCReferenceSet(ADC0_BASE, ADC_REF_INT); //Set reference to the internal reference // You can set it to 1V or 3 V GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5); //Configure GPIO as ADC ADCSequenceDisable(ADC0_BASE, 3); //It is always a good practice to disable ADC prior //to usage ,else the ADC may not be accurate // due to previous initializations ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); // configure trigger source ADCSequenceStepConfigure(ADC0_BASE, 3, 0,ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END); //epw //Configure ADC to read from channel 8 ,trigger the interrupt to end data capture // // // Since sample sequence 3 is now configured, it must be enabled. // ADCSequenceEnable(ADC0_BASE, 3); // // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before we sample. // ADCIntClear(ADC0_BASE, 3); // Enable the Timer peripheral SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // Timer should run periodically TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); //periodic timer // Set the value that is loaded into the timer everytime it finishes // it's the number of clock cycles it takes till the timer triggers the ADC // #define F_SAMPLE 1000 TimerLoadSet(TIMER0_BASE, TIMER_A, (g_ui32SysClock/sample_rate)); a = TimerLoadGet(TIMER0_BASE, TIMER_A); // Enable ADC triggering TimerControlTrigger(TIMER0_BASE, TIMER_A, true); // Enable processor interrupts. IntMasterEnable(); // Enable ADC interrupts again after sampling ADCIntEnable(ADC0_BASE, 3); IntEnable(INT_ADC0SS3); //SPI SETUP uint32_t pui32DataTx[NUM_SSI_DATA]; uint32_t pui32DataRx[NUM_SSI_DATA]; uint32_t ui32Index; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | // SYSCTL_XTAL_16MHZ); // // The SSI0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); // // For this example SSI0 is used with PortA[5:2]. The actual port and pins // used may be different on your part, consult the data sheet for more // information. GPIO port A needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5. // This step is not necessary if your part does not support pin muxing. // TODO: change this to select the port/pin you are using. // // GPIOPinConfigure(GPIO_PA2_SSI0CLK); // GPIOPinConfigure(GPIO_PA3_SSI0FSS); // GPIOPinConfigure(GPIO_PA4_SSI0RX); // GPIOPinConfigure(GPIO_PA5_SSI0TX); // // Configure the GPIO settings for the SSI pins. This function also gives // control of these pins to the SSI hardware. Consult the data sheet to // see which functions are allocated per pin. // The pins are assigned as follows: // PA5 - SSI0Tx // PA4 - SSI0Rx // PA3 - SSI0Fss // PA2 - SSI0CLK // TODO: change this to select the port/pin you are using. // GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); // // Configure and enable the SSI port for SPI master mode. Use SSI0, // system clock supply, idle clock level low and active low clock in // freescale SPI mode, master mode, 1MHz SSI frequency, and 8-bit data. // For SPI mode, you can set the polarity of the SSI clock when the SSI // unit is idle. You can also configure what clock edge you want to // capture data on. Please reference the datasheet for more information on // the different SPI modes. // SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, //Need to change number of data bits to match ADCs SSI_MODE_MASTER, 1000000, 8); // // Enable the SSI0 module. // SSIEnable(SSI0_BASE); // // Read any residual data from the SSI port. This makes sure the receive // FIFOs are empty, so we don't read any unwanted junk. This is done here // because the SPI SSI mode is full-duplex, which allows you to send and // receive at the same time. The SSIDataGetNonBlocking function returns // "true" when data was returned, and "false" when no data was returned. // The "non-blocking" function checks if there is any data in the receive // FIFO and does not "hang" if there isn't. // while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0])) { } // // Initialize the data to send. // pui32DataTx[0] = 's'; //Write data to ADC here pui32DataTx[1] = 'p'; pui32DataTx[2] = 'i'; // // Send 3 bytes of data. // for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++) { // // Send the data using the "blocking" put function. This function // will wait until there is room in the send FIFO before returning. // This allows you to assure that all the data you send makes it into // the send FIFO. // SSIDataPut(SSI0_BASE, pui32DataTx[ui32Index]); } // // Wait until SSI0 is done transferring all the data in the transmit FIFO. // while(SSIBusy(SSI0_BASE)) { } // // Receive 3 bytes of data. // for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++) { // // Receive the data using the "blocking" Get function. This function // will wait until there is data in the receive FIFO before returning. // SSIDataGet(SSI0_BASE, &pui32DataRx[ui32Index]); // // Since we are using 8-bit data, mask off the MSB. // pui32DataRx[ui32Index] &= 0x00FF; } // // Return no errors // //return(0); // //forever // while(1) { } } // ////***************************************************************************** //// //// uart_echo.c - Example for reading data from and writing data to the UART in //// an interrupt driven fashion. //// //// Copyright © 2013-2014 Texas Instruments Incorporated. All rights reserved. //// Software License Agreement //// //// Texas Instruments (TI) is supplying this software for use solely and //// exclusively on TI's microcontroller products. The software is owned by //// TI and/or its suppliers, and is protected under applicable copyright //// laws. You may not combine this software with "viral" open-source //// software in order to form a larger program. //// //// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. //// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT //// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR //// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY //// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL //// DAMAGES, FOR ANY REASON WHATSOEVER. //// //// This is part of revision 2.1.0.12573 of the EK-TM4C1294XL Firmware Package. //// ////***************************************************************************** // //#include <stdint.h> //#include <stdbool.h> //#include "inc/hw_ints.h" //#include "inc/hw_memmap.h" //#include "driverlib/debug.h" //#include "driverlib/gpio.h" //#include "driverlib/interrupt.h" //#include "driverlib/pin_map.h" //#include "driverlib/rom.h" //#include "driverlib/rom_map.h" //#include "driverlib/sysctl.h" //#include "driverlib/uart.h" // ////***************************************************************************** //// ////! \addtogroup example_list ////! <h1>UART Echo (uart_echo)</h1> ////! ////! This example application utilizes the UART to echo text. The first UART ////! (connected to the USB debug virtual serial port on the evaluation board) ////! will be configured in 115,200 baud, 8-n-1 mode. All characters received on ////! the UART are transmitted back to the UART. //// ////***************************************************************************** // ////**************************************************************************** //// //// System clock rate in Hz. //// ////**************************************************************************** //uint32_t g_ui32SysClock; // ////***************************************************************************** //// //// The error routine that is called if the driver library encounters an error. //// ////***************************************************************************** //#ifdef DEBUG //void //__error__(char *pcFilename, uint32_t ui32Line) //{ //} //#endif // ////***************************************************************************** //// //// The UART interrupt handler. //// ////***************************************************************************** //void //UARTIntHandler(void) //{ // uint32_t ui32Status; // // // // // Get the interrrupt status. // // // ui32Status = ROM_UARTIntStatus(UART0_BASE, true); // // // // // Clear the asserted interrupts. // // // ROM_UARTIntClear(UART0_BASE, ui32Status); // // // // // Loop while there are characters in the receive FIFO. // // // while(ROM_UARTCharsAvail(UART0_BASE)) // { // // // // Read the next character from the UART and write it back to the UART. // // // ROM_UARTCharPutNonBlocking(UART0_BASE, // ROM_UARTCharGetNonBlocking(UART0_BASE)); // // // // // Blink the LED to show a character transfer is occuring. // // // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); // // // // // Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks. // // // SysCtlDelay(g_ui32SysClock / (1000 * 3)); // // // // // Turn off the LED // // // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0); // } //} // ////***************************************************************************** //// //// Send a string to the UART. //// ////***************************************************************************** //void //UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) //{ // // // // Loop while there are more characters to send. // // // while(ui32Count--) // { // // // // Write the next character to the UART. // // // ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++); // } //} // ////***************************************************************************** //// //// This example demonstrates how to send a string of data to the UART. //// ////***************************************************************************** //int //main(void) //{ // // // // Set the clocking to run directly from the crystal at 120MHz. // // // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | // SYSCTL_OSC_MAIN | // SYSCTL_USE_PLL | // SYSCTL_CFG_VCO_480), 120000000); // // // // Enable the GPIO port that is used for the on-board LED. // // // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // // // // Enable the GPIO pins for the LED (PN0). // // // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); // // // // // Enable the peripherals used by this example. // // // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // // // // Enable processor interrupts. // // // ROM_IntMasterEnable(); // // // // // Set GPIO A0 and A1 as UART pins. // // // GPIOPinConfigure(GPIO_PA0_U0RX); // GPIOPinConfigure(GPIO_PA1_U0TX); // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // // // // Configure the UART for 115,200, 8-N-1 operation. // // // ROM_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200, // (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | // UART_CONFIG_PAR_NONE)); // // // // // Enable the UART interrupt. // // // ROM_IntEnable(INT_UART0); // ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // // // // Prompt for text to be entered. // // // //UARTSend((uint8_t *)"\033[2JEnter text: ", 16); // while(1) //epw // { // UARTSend((uint8_t *)"Hello World", 16); //epw //// while(100--) //// { //// } // } // // // // Loop forever echoing data through the UART. // // //// while(1) //// { //// } //}
  2. oam4647

    tiva c verifying system clock frequency

    I am using the TM4C1294, so yeah the one with 80 pins. If there is a bug with SysCtlClockGet, how would I check to make sure that I am actually running at 120 MHz? Thanks for all the help. All of the control registers show that the processor should be running at 120 MHz, but for some reason the internal ADC is not sampling at the frequency I want it to, and I thought it had something to do with the processor clock frequency.
  3. Hello, I am using the Tiva C launchpad, and I am trying to set the system clock frequency to 120 MHz. I have used both of these functions below to set the system clock frequency: g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); and also, SysCtlClockSet(SYSCTL_XTAL_16MHZ | SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480); Then I check the clock speed using: clock_speed = SysCtlClockGet(); I have changed different parameters in the two functions above, but the value of clock_speed seems to be either 15 MHz or 9.6 MHz. One of the things I don't understand is the difference between MAP_SysCtlClockFreqSet and SysCtlClockSet. If anyone could help, it would be greatly appreciated. Thanks.
×