# [SOLVED]V/F control help in frequency control

Status
Not open for further replies.

#### abc_de

##### Full Member level 4
hello i am working on an900 code but i am not getting exact frequency from formula as mention in an900 app note

formula is

imer0 Reload Value = FFFFh –[(FOSC/4)/(2 • (sine table entries – 1)) × Timer0 prescaler value × f]

but i am getting 35hz even i am compute the equation for 50hz

#### betwixt

##### Super Moderator
Staff member
Check you have Timer0 configured in 16-bit mode. It can be set to 8-bit or 16-bit. If you use that calculation in 8-bit mode you will get the wrong result.

Brian.

#### abc_de

##### Full Member level 4
hello
i am using pic18f4431, timer0 is configured in 16bit mode
1) FOSC = 8mhz ,
2) Timer0 prescaler value =4
3) sine table entries=32
4) f=50hz

according to equation it gives 161 counts timer0 load value 65374

- - - Updated - - -

which is correct i have checked it in this way

internal clock = 8MHZ/4=2MHZ

internal clock frequency 1/2MHZ = 0.0000005 SEC

timer0 roll over time= 0.0000005 x 161 x 4=0.000322 sec

total time to cover 62 sine entries
0.000322 x 62 =0.019964 sec

hence frequency = 1/(0.019964) = 50.90HZ

but i have check my output on CRO it gives 35.5HZ around

#### betwixt

##### Super Moderator
Staff member
Your math seems fine. A CRO isn't the best instrument for measuring frequency, are you sure it is accurate? Can you use a frequency counter or alternatively, if you have a dual trace CRO, can you apply 50Hz AC from a mains transformer to the second trace and see if they align about once per second?

Brian.

#### abc_de

##### Full Member level 4
hello
i am sure cro gives accurate result. also cross check with transformer out put
its really arround 35hz

#### betwixt

##### Super Moderator
Staff member
Can you post the complete source code so I can simulate it here please.

Brian.

#### abc_de

##### Full Member level 4
hello Betwixt
i am very thankful for your support.
i just simulate my source code in MPLAB SIM debugger then i found so much time has been wasted in ISR Routine which was actual cause of lack in frequency 36HZ.
after that i have minimize my code so that CPU could not waste too much time in ISR. then i got desire frequency not highly accurate like 49 HZ at 50 HZ
I am very thankful for you support.
if you want to study my code then i can post it.

#### betwixt

##### Super Moderator
Staff member
Well done.
Always try to keep processing inside an ISR to a minimum.

Brian.

#### abc_de

##### Full Member level 4
thank you :smile:

Status
Not open for further replies.