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 support@ccsinfo.com

Pic16f1824 and frequency measuring

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



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

Pic16f1824 and frequency measuring
PostPosted: Mon Dec 16, 2019 8:52 am     Reply with quote

Hello everybody.
me again Wink

Code:

#include "16F1824.h"
#device PIC16F1824 ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,clkout //CLKOUT = pin_A4 OUTPUT 8 MHZ.
#use delay(internal=32000000)
#use  rs232(baud=9600,parity=N,xmit=PIN_a0,rcv=PIN_a1,bits=8)
unsigned int32 i=0;
#INT_CCP2
void capacitive(){
 i++;
}
void main(void){

   set_tris_a(0x10);    //pin_a5 in BECAUSE A5 = ccp2 and capture mod

   enable_interrupts(INT_CCP2);  // INT_CCP2 enable
   enable_interrupts(GLOBAL);    // all interrupts enable
   
   setup_ccp2(CCP_CAPTURE_RE);   //a5 capture signa raising edge
   
   CCP_2_HIGH=0x00; // CCPR2H register = 0
   CCP_2_LOW=0x00;  // CCPR2H register = 0

      while(True){

   enable_interrupts(INT_CCP2); 
   enable_interrupts(GLOBAL);
   printf("%lu",i);          // i  send serial port
   delay_ms(1000);

   }
}


I'm generating an 8 MHz signal from the clkout (PIN_A4) pin.
I want to measure this frequency from ccp2 (PIN_A5) pin.

No algorithms occurred in my head.
How can I measure the frequency with an algorithm?
The pins are not important.
But the method is important.

Thank you for answers.

----------------------------------------

As a Turkish proverb says;
To do someone a favor, teach him how to fish. Don't give a fish
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Dec 19, 2019 4:09 pm     Reply with quote

There are many examples on this forum.

Several use Timer1 as input.

Either way if your code is correct you will inevitably 8MHz, whether your clock is really in the low MHz or high tens MHz.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 20, 2019 2:57 pm     Reply with quote

ressas,
The reason you didn't get a reply for several days on your question
is that you had a big thread going here:

WS2812b and Pic18f46k22 -
http://www.ccsinfo.com/forum/viewtopic.php?t=58408

I gave you an answer that showed a significant bug in your code, but you
never came back and said if it worked. You didn't close out the thread.
You left it hanging. Then you asked a new question and people said "why bother ?".
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Tue Dec 24, 2019 12:01 am     Reply with quote

pcm programmer.
My fdc2112 module is broken.
I ordered a new one. But I haven't received it yet.
When I get it, I'll try again and write the result.
Is it a crime that I'm dealing with new projects while I'm waiting?
Be a little understanding.
Tell me if there's a mistake in my work.
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Tue Dec 24, 2019 1:25 am     Reply with quote

And I saw your answer for 2812b. I'il answer him as soon as I can.
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