Hi there.
I know there's a way to work frequencies with a PIC 16f877a, my teacher told me It could work using the internal timer that the PIC has. It doesn't work with frequencies as such, but with pulses. The problem is that I don't know how to get a pulse value from a random frequency, but I'm going to share a code where someone put some pulse values for a frequency.
Code:
void main()
{
// VARIABLES
//int16 pulse;
int16 pulse;
int n = 0;
int x = 1;
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// setup_oscillator(False);
x=1;
output_b(0);
while(n < 14){delay_ms(150);output_toggle(PIN_B0);n++;}
while(TRUE)
{
// Detection of pulse length
while(input_state(input));
while(!input_state(input));
output_b(0);
if(input_state(input))
{
set_timer1(0);
while(input_state(input));
pulso = get_timer1();
printf("%Lu \n\r",pulse);
}
if ( pulse > 1450 && pulse < 1562 ) {
output_high(PIN_B0); //This works when I'm giving a frequency of 82.64 Hz
}
else if ( pulse > 1094 && pulse < 1194 ) {
output_high(PIN_B1); //This works when I'm giving a frequency of 109.2 Hz
}
else if ( pulse > 800 && pulse < 900 ) {
output_high(PIN_B2); //This works when I'm giving a frequency of 147.1 Hz
}
}
}
So if there's someone who could help me how to find a way to become frequency values into pulse values that I could use.
Thank you!
Bookmarks