Advertisement
worms005

sinsus2103

Dec 6th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. /*****************************************************************************/
  2. /* */
  3. /* PROJECT */
  4. /* Sinewaves */
  5. /* */
  6. /* FILENAME */
  7. /* main.c */
  8. /* */
  9. /* DESCRIPTION */
  10. /* TMS320C5505 USB Stick Application 4. Generating sine waves. */
  11. /* Generating sinewaves of variable frequency using DSPLIB. */
  12. /* */
  13. /* REVISION */
  14. /* Revision: 1.00 */
  15. /* Author : Richard Sikora */
  16. /*---------------------------------------------------------------------------*/
  17. /* */
  18. /* HISTORY */
  19. /* */
  20. /* Revision 1.00 */
  21. /* 1st March 2010. Original template code Spectrum Digital. */
  22. /* */
  23. /* Revision 1.01 */
  24. /* 5th August 2010. Converted to use CSL. */
  25. /* */
  26. /*****************************************************************************/
  27. /*
  28. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  29. *
  30. *
  31. * Redistribution and use in source and binary forms, with or without
  32. * modification, are permitted provided that the following conditions
  33. * are met:
  34. *
  35. * Redistributions of source code must retain the above copyright
  36. * notice, this list of conditions and the following disclaimer.
  37. *
  38. * Redistributions in binary form must reproduce the above copyright
  39. * notice, this list of conditions and the following disclaimer in the
  40. * documentation and/or other materials provided with the
  41. * distribution.
  42. *
  43. * Neither the name of Texas Instruments Incorporated nor the names of
  44. * its contributors may be used to endorse or promote products derived
  45. * from this software without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  48. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  49. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  50. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  51. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  53. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  54. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  55. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  56. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  57. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  58. *
  59. */
  60.  
  61. #include "stdio.h"
  62. #include "usbstk5505.h"
  63. #include "aic3204.h"
  64. #include "PLL.h"
  65. #include "sinewaves.h"
  66.  
  67.  
  68. Int16 left_input;
  69. Int16 right_input;
  70. Int16 left_output;
  71. Int16 right_output;
  72.  
  73. Int16 left[512];
  74. Int16 right[512];
  75. Int16 idx = 0;
  76.  
  77.  
  78. #define SAMPLES_PER_SECOND 24000
  79. #define GAIN_IN_dB 0
  80.  
  81. unsigned long int i = 0;
  82.  
  83.  
  84. /* ------------------------------------------------------------------------ *
  85. * *
  86. * main( ) *
  87. * *
  88. * ------------------------------------------------------------------------ */
  89. void main( void )
  90. {
  91. /* Initialize BSL */
  92. USBSTK5505_init( );
  93.  
  94. /* Initialize the Phase Locked Loop in EEPROM */
  95. pll_frequency_setup(100);
  96.  
  97. /* Initialise hardware interface and I2C for code */
  98. aic3204_hardware_init();
  99.  
  100. /* Initialise the AIC3204 codec */
  101. aic3204_init();
  102.  
  103.  
  104. /* Set sampling frequency in Hz and ADC gain in dB */
  105. set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);
  106.  
  107. printf("\nRunning Sinewaves Project\n\n");
  108. printf( "Sinewave 250Hz on left HP output, 1000Hz on right HP output\n\n" );
  109.  
  110. asm(" bclr XF");
  111.  
  112. for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
  113. {
  114.  
  115. aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two channels.
  116.  
  117. left_output = 4 * generate_sinewave_1(500, 10000); // Sinewave 1 is 250 Hz.
  118. right_output = generate_sinewave_2(523, 10000); // Sinewave 2 is 1000 Hz.
  119.  
  120. aic3204_codec_write(left_output, right_output);
  121.  
  122. left[idx] = left_output;
  123. right[idx] = right_output;
  124. idx+=1;
  125. if(idx == 512)
  126. idx = 0;
  127.  
  128. }
  129.  
  130. /* Disable I2S and put codec into reset */
  131. aic3204_disable();
  132.  
  133. printf( "\n***Program has Terminated***\n" );
  134. SW_BREAKPOINT;
  135. }
  136.  
  137. /* ------------------------------------------------------------------------ *
  138. * *
  139. * End of main.c *
  140. * *
  141. * ------------------------------------------------------------------------ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement