Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

frequency measurement using atmega32

Status
Not open for further replies.

sasidhar60

Newbie level 6
Joined
May 17, 2012
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,358
hey,
i am using a v-f converter to measure votage and i want to use atmega32 to measure the frequency so that i can get the voltage value from the frequency using simple arithmetic
problem is i dont know how to measure frequency continuously.
i have to update my value as my voltage change.
my frequency is in the range of 3KHZ.
 

The logic can be that you Rectifay the frequency and fed it to shmitt trigger ic (may be 4093 nand gate shmitt trigger) and the fed the TTL compatible output of the 4093 to the counter/timer pin of atmega32 and count the number of pulses and display them on lcd module.

hope this will be a helpful clue for you.
 

I tried something similar a while back, using ATmega32U2.
My code snippet is below.

My frequency was lower (maybe 700Hz from memory), so you will need to scale your values accordingly.
The code below sums 8 pulses, and then scales it for a value between 0 and 250, and stores it in a
variable called potval which can be accessed from your main function.
I'm sure you could do it other ways, but this was a quick thing which worked for me.
My input was a potentiometer connected to a 555 oscillator, functioning as a crude V-F converter.
The 555 worked, but it was not accurate enough for my particular needs even with a polypropelyne timing capacitor.
I've yet to try it with any other V-F converter.

Code:
unsigned char iter=0;
unsigned char potval; // this will hold a value between 0 and 225
unsigned int cval=0;

#pragma vector = TIMER1_CAPT_vect
__interrupt void TIMER1_CAPT_ISR(void)
{
  unsigned int tempval;
  cval+=ICR1;
  TCNT1=0x0000;
  if (iter==0)
  {
    iter=1;
    cval=0;

    return;
  }

  iter++;
  if (iter>9) // have we obtained 8 samples?
  {
    iter=1;
    // value of 1 sample is around 3450-3900, but we will
    // however, lets assume 3425-3925
    // so the 4 sample value will be 13700-15700
    // this is a span of 2000
    
    if (cval>29400)
    {
      LED_ON;
    }
    else
    {
      LED_OFF;
    }
    
    
    tempval=cval-27400; // remove the offset
    cval=0; // reset the sampled value
    // we need a value of between 0 and 200
    // if we divide by 8, this is a span of 250 which is good
    tempval=tempval>>4; 
    potval=(unsigned char)tempval;
  }
  
}





void
init(void)
{

  // set up timer1
  TCNT1=0x0000;
  TCCR1B=0x01; // trigger on falling edge, and set prescaler to 1
  
  
  
}



int main( void )
{
  unsigned char oldpotval=0;
  unsigned int pllval;
  init();

  
  TCNT1=0x0000;
  TIMSK1=0x20; // enable input capture interrupt
  __enable_interrupt();
  
  while(1)
  {
    // pot value is between 0 and 250
    if (potval>125)
    {
     LED_ON;
    }
    else
    {
     LED_OFF;
    }
    
 
  
  } // end while
  

  return 0; // expect a warning on this line, because we never return  
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top