Working PIC with Frequencies


Results 1 to 7 of 7

Threaded View

  1. #1

    Thumbs up Working PIC with Frequencies

    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!
    Last edited by Archangel; - 7th June 2011 at 07:25. Reason: added code tags

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts