Page 1 of 1

12.8kHz SQUARE WAVE.

Posted: Tue Feb 14, 2017 10:21 pm
by Tony Brown
Hi All,

Is it possible to generate a 12.8Khz square wave using a 12f615?

I have tried using TMR2 and got to 7Khz (ish) but the square wave wasnt very square.

Regards

Tony

Re: 12.8kHz SQUARE WAVE.

Posted: Wed Feb 15, 2017 10:05 am
by medelec35
Hi Tony,
There are two ways I can think of.
Assuming using internal osc set to 8MHz

1) Add PWM component (don't forget enable).
In PWM properties, Set Prescaler to 1 and Period to 155.
Add SetDutyCycle and use 78 for duty.
That should give a square wave of 12.8205 KHz

Or

2) Add Timer2 interrupt
Set Prescaler and postscaler at 1:1
Set Rollover value to 78
This will give an interrupt frequency of 25.641KHz
Add a Bool variable e.g called toggle.
within interrupt macro, add a calculation box with

Code: Select all

Toggle=!Toggle
Then just set an output using the Toggle variable
That will divide 25.641KHz by 2 with equal time periods.= 12.8205 KHz square wave.

If you get stuck then post a flowchart and I will help you further.

Martin

Re: 12.8kHz SQUARE WAVE.

Posted: Wed Mar 01, 2017 10:56 pm
by Tony Brown
Thanks Martin, I'll try it over the weekend and update you. When you say "set an output using the toggle variable" what exactly do you mean?

Many thanks

Tony

Re: 12.8kHz SQUARE WAVE.

Posted: Sat Mar 04, 2017 9:28 pm
by Tony Brown
Hi Martin,

I tried the timer2 method and it worked brilliantly.

Thanks for your help

Regards

Tony

Re: 12.8kHz SQUARE WAVE.

Posted: Sat Mar 04, 2017 11:43 pm
by medelec35
Hi Tony,
Your welcome.
Glad it works well for you.
Thanks for letting us know.

Martin