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???
Generate a 32.768khz signal
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Generate a 32.768khz signal
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: Generate a 32.768khz signal
Thanks Ben,
I will have a try with timer 2, If I have no luck I will change the crystal to 19.6608Mhz.
I will have a try with timer 2, If I have no luck I will change the crystal to 19.6608Mhz.
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
Re: Generate a 32.768khz signal
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
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
-
- Posts: 175
- Joined: Thu Feb 04, 2010 7:44 am
- Has thanked: 3 times
- Been thanked: 3 times
- Contact:
Re: Generate a 32.768khz signal
Hi Jorgen
I did look at the DS32KHZ chip. At £7 each i thought i could find something better.
I did look at the DS32KHZ chip. At £7 each i thought i could find something better.
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
Re: Generate a 32.768khz signal
Hi Again!
Ok, but Little cheaper here: http://www.ebay.com/itm/DS32KHZSN-32-76 ... 416f2a42c1
Jorgen
Ok, but Little cheaper here: http://www.ebay.com/itm/DS32KHZSN-32-76 ... 416f2a42c1
Jorgen