NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Basic Electronics » Counting

January 17, 2011
by Jalex
Jalex's Avatar

Hi I want to read a frequency for a few ms and print out the result similar to a frequency counter. I know how to set up the pins and read inputs but I don't know the best procedure for timing. The frequency is fairly slow, Less than 10k. Do I use a timer for this? I don't want to tie up the program with a delay as it is doing other things as well. Also can you explain a little on the interupts as to what they are for and how the function?

January 17, 2011
by Jalex
Jalex's Avatar

I wrote some code to do it but I wanted to learn more on using the timers and interupts. I saw one of the kits used the timer but I can't find it to study as I forgot wich one it was.

January 17, 2011
by Ralphxyz
Ralphxyz's Avatar

Probable best to start with the Real Time Clock tutorial.

That will walk you through a timer interrupt.

I'd be interested in seeing your code once you get this figured out.

Ralph

January 18, 2011
by Jalex
Jalex's Avatar

Hi Ralph I didn't want to show you this because I know it's not good programming but it works. The IR is high when ever the trimmer is past the 180 degree(fully meshed position) mark. It just uses a do nothing count while another variable counts out the Wind Speed
The rotation direction is above.

      while(1) {
      lcd_home();
      lcd_write_int16(Result);
      lcd_write_string(PSTR(" :Degrees"));
      lcd_line_two();
      lcd_write_int16(WindCnt);
      lcd_write_string(PSTR(" :Wind Speed"));
      lcd_line_three();
       lcd_write_string(PSTR("This is My Test"));

        Result = 0;
            // Turn on PC4 
        PORTC |= (1<<PC4);
        delay_us(5);
        //turn PC4 back off
        PORTC &= ~(1<<PC4);
        // Count to 180 only when PC5 is low
      while (PINC &= (1<<PC5) && ((Result <180))) {

         // If IR is on then add the difference to 180
        if (PINC &= (1<<PC6)) {
         Result = ((180 - Result)) + 180;
        }
         return Result;
  ***************
   // Tc is just a do nothing count.
    // WindCnt counts the pulses on PC3 and TC acts as a timer.
      }
       WindCnt = 0;
       Tc = 0;
      while(Tc < 255) {
       Tc++;

        if (PINC &= (1<<PC3)) {

       WindCnt++;
           }

         }

        delay_ms(1000);
        }

  return 0;
}
January 18, 2011
by Jalex
Jalex's Avatar

Hi Again Anyway now you can see why I need to learn timers. I could then get rid of the 555 oscillator on the RC circuit and just measure the time between pulses. I am going to study real time clock now and learn to use it. I do it this way because we have lots of rain here and capasitors seem to handle the damp climate better. I make my own with just one rotating plate close to the other.

Post a Reply

Please log in to post a reply.

Did you know that you can use printf and scanf functions to talk to your computer from your USB NerdKit? Learn more...