CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Lookup table fast access !!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

Lookup table fast access !!
PostPosted: Tue Apr 26, 2011 9:16 am     Reply with quote

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
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

View user's profile Send private message Visit poster's website

PostPosted: Tue Apr 26, 2011 9:56 am     Reply with quote

You have it trimmed down pretty far. There are only a few things I can think of that would speed it up:

1. If you can, up the clock speed

2. Switch to directly setting the port with constant values like this:
Code:


Code:

//=============================================
// main
//=============================================
void main()
{

set_tris_c(0b00000000);
sine_index=0;
while(1)
   {
   PORTC = 127;
   PORTC = 130;
   PORTC = 133;
   PORTC = 136;
<you get the point>

   }
}


This creates code that doesn't need to do any look ups in a table. It's horribly inefficient space wise and inflexible but it's fast.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 10:11 am     Reply with quote

The quick way is to get a 10 MHz crystal and use the PLL oscillator to
run at 40 MHz. Instant 2x speed increase.
mindstorm88



Joined: 06 Dec 2006
Posts: 102
Location: Montreal , Canada

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 10:15 am     Reply with quote

Thanks guys , i want to sweep between 20kHz and 30 kHz , so i guess i will have to reduce the resolution and use a bit of filtering !!!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Apr 26, 2011 1:20 pm     Reply with quote

if the goal is not to merely see how far you can overload the PIC and clean HF sines are the goal , then
here is how to get fabulous CLEAN 10 bit quality sine waves
using SPI to control a DDS chip

http://www.ccsinfo.com/forum/viewtopic.php?t=39364&highlight=ad9833
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group