I am having some trouble having an output pin mimic an input pin. I have a program where all I want to happen is an output pin do exactly the same thing as the input pin. To test this I wrote a short program and put a 4KHz clock signal on the input and tested the frequency of both. The input was 4KHz, but the output was only between 500 and 600 Hz. I am running at 8MHz, so it should have no problem with the 4KHZ, right? Here is my code. It is on a 16F88, internal 8MHz clock, clean power source w/caps, SourceBoost compiler. BTW, the final program will do much more than this, if you are curious why this is written in C and not assembly.
I also tried a more straight forward approach where I would just set the output to the input time every time, without checking the current state. That one is even weirder. 4KHz in, 396 KHz out!?
Any idea what is causing either problem? I am almost embarrassed to post this because it is such a silly program, but I cannot figure it out.
Code:
#pragma DATA 0x2007, 0b0001111100010000
#include <system.h>
bit iCLK @ PORTA.2;
bit pCLK;
bit oCLK @ PORTB.1;
void main()
{
//*********************//
// configure I/O ports //
//*********************//
portb = 000000000b;
trisb = 000000000b; //0 = Output, 1 = Input
porta = 00000000b;
trisa = 11111111b; //0 = Output, 1 = Input
osccon = 01110000b; //internal oscillator @ 8MHz
cmcon = 00000111b; //comparators off
ansel = 00000001b; //AN0 on (RA0)
pCLK = iCLK;
oCLK = iCLK;
while(1)
{
if (iCLK != pCLK)
{
pCLK = iCLK;
oCLK = pCLK;
}
}
}
I also tried a more straight forward approach where I would just set the output to the input time every time, without checking the current state. That one is even weirder. 4KHz in, 396 KHz out!?
Code:
#pragma DATA 0x2007, 0b0001111100010000
#include <system.h>
bit iCLK @ PORTA.2;
bit pCLK;
bit oCLK @ PORTB.1;
void main()
{
//*********************//
// configure I/O ports //
//*********************//
portb = 000000000b;
trisb = 000000000b; //0 = Output, 1 = Input
porta = 00000000b;
trisa = 11111111b; //0 = Output, 1 = Input
osccon = 01110000b; //internal oscillator @ 8MHz
cmcon = 00000111b; //comparators off
ansel = 00000001b; //AN0 on (RA0)
pCLK = iCLK;
oCLK = iCLK;
while(1)
{
oCLK = iCLK;
}
}
Any idea what is causing either problem? I am almost embarrassed to post this because it is such a silly program, but I cannot figure it out.