Generate a 32.768khz signal

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Contact:

Generate a 32.768khz signal

Post by cobra1 »

Hi.

What would be the best way to generate a 32.768khz signal using a PIC.

Main crystal is 16Mhz.
The signal needs to be a square wave with and amplitude of 3v.
Im thinking something interrupt based toggling a output pin.

I would prefer not to use additional crystals if i can help it. Would timer 2 be able to create this signal using interrupts or is this not reccomended???

User avatar
Benj
Matrix Staff
Posts: 15008
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Generate a 32.768khz signal

Post by Benj »

Hello,

The frequency your after is a bit tricky with a 16MHz crystal. If you instead used a 19.6608MHz then it might be a bit easier.

Anyway you can generate 32.786KHz frequency using PWM with a prescaler of 1 and a rollover of 121 and a 16MHz crystal, not quite the freq your after but it's as close as I can get it. Setting a duty of around 60 will give you 50% mark space ratio.

Otherwise yes timer 2 can be used. You will need to interrupt at twice the frequency (65.536KHz) and use a variable as a flag to indicate if the output pin needs switching on or off.

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Contact:

Re: Generate a 32.768khz signal

Post by cobra1 »

Thanks Ben,

I will have a try with timer 2, If I have no luck I will change the crystal to 19.6608Mhz.

jgu1
Posts: 1227
Joined: Tue Oct 06, 2009 9:39 am
Contact:

Re: Generate a 32.768khz signal

Post by jgu1 »

Hi Cobra!

I do not know what your project is, but certainly something with timing. but do you know that component:

http://datasheets.maximintegrated.com/en/ds/DS32kHz.pdf Cheap.

Best regard

Jorgen

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Contact:

Re: Generate a 32.768khz signal

Post by cobra1 »

Hi Jorgen

I did look at the DS32KHZ chip. At £7 each i thought i could find something better.

jgu1
Posts: 1227
Joined: Tue Oct 06, 2009 9:39 am
Contact:

Re: Generate a 32.768khz signal

Post by jgu1 »

Hi Again!

Ok, but Little cheaper here: http://www.ebay.com/itm/DS32KHZSN-32-76 ... 416f2a42c1


Jorgen

Post Reply