100 hz tone on a PIC in C

Status
Not open for further replies.
Hi Mike,

I'm using the highest 8 bits of the 24 bit phase accumulator (bits b23..b16) as the 8 bit index into the sine array. Is that instruction incorrect?

Mike
 
You have defined accum as 32 bit as BoostC doesn't have a 24 bit variety.

Mike.
 
I couldn't find a way to declare 24 bit variables in BoostC so I went ahead and used the 32 bit long type.

The ccpr1l = sinetbl[accum>>16] instruction does produce assembler code that uses the third byte of the accumulator variable (b23..b16) as the sine table index so I thought it was ok.
 
Last edited:
Here's the high performance version (24-bit Phase Accumulator) which requires an 8.388608-MHz crystal.

Thanks Mike. That was fast.

Does anyone know of a good tutorial for PWM for Microchip pics. I have read some of their documents but I need something that explains it in simple. terms. I can understand bits of what Mike has written here, but I could never put this together on my own. I have been scouring the Web for something but I have not found an easy to follow tutorial for PWM and Timers.

Thanks
 
... I assume that a 20MHz crystal could be used instead, it's just that the phase calculation would be more complex.

Yes, you can use a 20-MHz crystal and use new Fdds (DDS frequency) and Fres (Frequency resolution) values in the formulas for determining the phase offset (DDS tuning word).
 
If you'd just like to generate a nice accurate sine wave, I use ML2035 serial loaded sine wave IC. I use it for generating paging tones.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…