mindstorm88
Joined: 06 Dec 2006 Posts: 102 Location: Montreal , Canada
|
Lookup table fast access !! |
Posted: Tue Apr 26, 2011 9:16 am |
|
|
Hi guys , is there a way to increase the speed of that sine wave generator ??
Code: |
#include <18f452.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed osc with HW enabled 4X PLL
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=20000000)
#byte PORTC = 0xF82
int8 sine_table[256] =
{127,130,133,136,139,143,146,149,152,155,158,161,164,167,
170,173,176,178,181,184,187,190,192,195,198,200,203,205,
208,210,212,215,217,219,221,223,225,227,229,231,233,234,
236,238,239,240,242,243,244,245,247,248,249,249,250,251,
252,252,253,253,253,254,254,254,254,254,254,254,253,253,
253,252,252,251,250,249,249,248,247,245,244,243,242,240,
239,238,236,234,233,231,229,227,225,223,221,219,217,215,
212,210,208,205,203,200,198,195,192,190,187,184,181,178,
176,173,170,167,164,161,158,155,152,149,146,143,139,136,
133,130,127,124,121,118,115,111,108,105,102,99,96,93,90,
87,84,81,78,76,73,70,67,64,62,59,56,54,51,49,46,44,42,39,
37,35,33,31,29,27,25,23,21,20,18,16,15,14,12,11,10,9,7,6,
5,5,4,3,2,2,1,1,1,0,0,0,0,0,0,0,1,1,1,2,2,3,4,5,5,6,7,9,10,
11,12,14,15,16,18,20,21,23,25,27,29,31,33,35,37,39,42,44,
46,49,51,54,56,59,62,64,67,70,73,76,78,81,84,87,90,93,96,
99,102,105,108,111,115,118,121,124};
/*const unsigned char sine_table[64] =
{127,139,152,164,176,187,198,208,217,225,233,239,244,249,252,253,
254,253,252,249,244,239,233,225,217,208,198,187,176,164,152,139,
127,115,102,90,78,67,56,46,37,29,21,15,10,5,2,1,0,1,2,5,10,15,21,
29,37,46,56,67,78,90,102,115};
*/
int8 sine_index;
//=============================================
// main
//=============================================
void main()
{
set_tris_c(0b00000000);
sine_index=0;
while(1)
{
PORTC = (sine_table[sine_index]); // Bits 7-2
sine_index++;
}
}
|
i would like to get higher frequency without losing resolution !!
Thanks |
|