Connect a voltage to frequency chip to Mbed

13 Sep 2010

hello every one.

I am  trying to read the frequency from a voltage to frequency converter integrated circuit using an Mbed , could  one help me?

Following there is the datasheet

http://www.farnell.com/datasheets/83861.pdf

Cheers

Antonio

13 Sep 2010

Hi Antonio,

You could try an experimental "PwmIn" class I wrote:

This uses InterruptIn to read the PWM properties of an input signal (in your case, wanting to read the period).

Here is the simple Hello World:

// Example using PwmIn interface library, sford
//  - Note: uses InterruptIn, so not available on p19/p20

#include "mbed.h"
#include "PwmIn.h"

PwmOut x(p21);
PwmOut y(p22);

PwmIn a(p5);
PwmIn b(p6);

int main() {
    x = 0.5;
    y = 0.2;
    while(1) {
        printf("a: pw = %f, period = %f\n", a.pulsewidth(), a.period());
        printf("b: pw = %f, period = %f\n", b.pulsewidth(), b.period());
        wait(2);
    }
}
Not sure how you've got your chip wired up, but as in this example, you could use a PwmOut to drive the CLK signal if you didn't want to use an external crystal.
Hope that helps. Please write up your experiences and progress with this chip in your notebook so others can learn what you learn too if possible!
Simon
13 Sep 2010

My target is to extrapolate the frequency from sine wave.

To make understand . I got a signal from Dielectric Resonate Oscillator,  which uses the Radar Doppler Effect. equation, so my signal change  in  frequency and amplitude as  an object is in movement  to or from the  DRO, To calculate the distance  and the velocity of my object i need know the frequency and the amplitude,  the amplitude is easier,  but i have not idea how to know the frequency, (PS  I went to use the FFT, i did not reach the  goal)

Cheers

 

Antonio

13 Sep 2010

Hi Antonio,

What kind of a frequency range are we talking about? kHz? MHz? GHz? Depending on the range, different methods can be used..

14 Sep 2010

is very low from 6Hz Max 100Hz

14 Sep 2010 . Edited: 14 Sep 2010

Hmm. So to make sure.. You are putting in an unknown frequency and a know frequency into the v/f converter then measuring the voltage output to determine the unknown frequency?

If the unknown frequency is from 6-100Hz, can't you measure that directly using an InterruptIn? To do this, you would need to convert the sine wave to a square wave (not very difficult to do) and then use an InterruptIn to measure the time between interrupts to determine the frequency. If I understand correctly, you don't really need to bother with the V/f converter..

 

14 Sep 2010

Will this do?

#include "mbed.h"

InterruptIn frec_input(p5);
Timer t=0;

void start_timer() {
    t.stop();
    printf("period: %3.3f ms\n", t.read()/1000);
    t.reset();
    t.start();
}

int main() {
    frec_input.rise(&start_timer); 
    while(1) {         
    //wait...
    }
}

14 Sep 2010

Ouch, ... Timer t=0; may give you an error, but the program compiled ok.

14 Sep 2010

Yeah, that should work. However, the code can be optimized a little (as shown below). In general, you want to do as little as possible in the interrupt routine. You also don't need to stop and start the timer after a reset or a read (not that it won't work...)

Also, whatever it is you're plugging in, you have to make sure that the input voltage to the pin is within 0 and 3.3 volts. Make sure the signal does not become negative and does not go over 5V. Depending on your device, you might have to do a little singal conditioning before you connect it.

#include "mbed.h"

Serial pc(USBTX, USBRX);
InterruptIn frec_input(p5);
Timer t;	
float T,f;    // Temporary float for period and frequency;

void start_timer() {
    T=t.read()    // Get time between interrupts
    f=1/T;        // Calculate frequency
    t.reset();    // Reset Timer;
    
}

int main() {
    t.reset();
    t.start();    // Start the timer;
    
    frec_input.rise(&start_timer); 
    

    while(1) {         
        printf("period: %3.3fms Frequency: %.2fHz\n",T*1000.0,f);
        wait(1);
        
    }
}

 

15 Sep 2010

Hi,

Did the PwmIn class not do the job? I'd be interested to know if it didn't, to help improve it.

Thanks,
Simon

16 Sep 2010

Hi Guys

Tk so much, I should try, but i do not know now if i can extract the real time, also i was thinking to calcolate it using zero crossing analisys or build a frequency counter in VHDL.

 

Anyway you know guys if ARM like sposorize the project:??

 

Cheers

 

Antonio

24 Sep 2010

Hi Igor

Why u put  this line

 

Serial pc(USBTX, USBRX);

 Cheers

Antonio  

24 Sep 2010

Hi Igor

#include "mbed.h"

Serial pc(USBTX, USBRX);                                        // ( why i use  this one>?)
InterruptIn frec_input(p5);
Timer t;	                                                // i can not understand  this line
float T,f;    // Temporary float for period and frequency;

void start_timer() {
    T=t.read()    // Get time between interrupts
    f=1/T;        // Calculate frequency
    t.reset();    // Reset Timer;
    
}

int main() {
    t.reset();
    t.start();    // Start the timer;
    
    frec_input.rise(&start_timer); 
    

    while(1) {         
        printf("period: %3.3fms Frequency: %.2fHz\n",T*1000.0,f);
        wait(1);
        
    }
}

25 Sep 2010

Hey Antonio,

You can use whatever serial object you want. I chose to use the USB to Serial to print to the terminal.

Timer t; declares a Timer object that is used to time the period between interrupts.

You should try the PwmIn class as Simon suggested instead. The code I wrote is just an example.