View previous topic :: View next topic |
Author |
Message |
ressas
Joined: 15 Nov 2019 Posts: 135
|
Pic16f1824 and frequency measuring |
Posted: Mon Dec 16, 2019 8:52 am |
|
|
Hello everybody.
me again
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
|
|
Posted: Thu Dec 19, 2019 4:09 pm |
|
|
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
|
|
Posted: Fri Dec 20, 2019 2:57 pm |
|
|
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
|
|
Posted: Tue Dec 24, 2019 12:01 am |
|
|
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
|
|
Posted: Tue Dec 24, 2019 1:25 am |
|
|
And I saw your answer for 2812b. I'il answer him as soon as I can. |
|
|
|