12.8kHz SQUARE WAVE.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Tony Brown
Posts: 81
Joined: Wed Jun 20, 2012 9:59 pm
Has thanked: 36 times
Been thanked: 5 times
Contact:

12.8kHz SQUARE WAVE.

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 12.8kHz SQUARE WAVE.

Post 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
Martin

Tony Brown
Posts: 81
Joined: Wed Jun 20, 2012 9:59 pm
Has thanked: 36 times
Been thanked: 5 times
Contact:

Re: 12.8kHz SQUARE WAVE.

Post 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

Tony Brown
Posts: 81
Joined: Wed Jun 20, 2012 9:59 pm
Has thanked: 36 times
Been thanked: 5 times
Contact:

Re: 12.8kHz SQUARE WAVE.

Post by Tony Brown »

Hi Martin,

I tried the timer2 method and it worked brilliantly.

Thanks for your help

Regards

Tony

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 12.8kHz SQUARE WAVE.

Post by medelec35 »

Hi Tony,
Your welcome.
Glad it works well for you.
Thanks for letting us know.

Martin
Martin

Post Reply