CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Calculation of Frequency

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
malu79



Joined: 26 Jun 2011
Posts: 5

View user's profile Send private message

Calculation of Frequency
PostPosted: Sun Jun 26, 2011 6:04 am     Reply with quote

Hello,
I am a guy who recently approached the planning of the pic, in this regard I would ask yourself a question. I refer to the example in the CCS C Compiler (EX_PATG.c) and the question is as follows:
how can I determine the frequencies starting from periods? I'll explain: For example, assuming you have a clock 4000000 Hz, a time of 25600 microseconds (each period is a multiple of 400) and an interrupt of 200 microseconds, with an oscilloscope, I get that the frequency corresponding to that period is 7.9 Hz If you use the formula f = 1 / T can not get that value and then how can I determine the value of frequency?
Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 26, 2011 3:55 pm     Reply with quote

You want to run the Ex_patg.c program at 4 MHz instead of 20 MHz.
You can do it, but only with one output (not with 7 outputs). The reason
is that the code inside the #int_timer1 routine takes too long to run at
4 MHz. I measured it on the oscilloscope with the PIC running at 4 MHz,
and with all 7 outputs being generated, the code in the isr takes 500 us.
The isr overhead takes about 50us at 4MHz, so that's a total of 550 us
per interrupt, and it's supposed to be 200 us. It can't do it. The code
in the isr takes too long to execute at 4 MHz if you try to run 7 channels.

Here are the changes I made to run it at 4 MHz with only 1 channel.
The output is on Pin B0 only:
Quote:

#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)


#INT_TIMER1
void wave_timer() {
int i;

set_timer1(0xFF64); // (was 0xFC4F)
output_b(port_b_image);

for(i=0; i < 1; i++) // Change loop count to only 1.
{


You could probably get 7 channels at 4 MHz, but not with it interrupting
every 200 us. Maybe have it interrupt every 1 ms.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group