Connect with us

reading frequency into PC

Discussion in 'Electronic Design' started by Kris Duck, Jun 2, 2004.

Scroll to continue with content
  1. Kris Duck

    Kris Duck Guest

    Hi there. I'm new here, so I'm not sure if this is the right group.

    I've got something that outputs pulses per rotation. It uses a sine wave. I
    planned on using (half of) an LM393 to convert it into a square wave, the trying
    to read that into a parallel port so I can run a real-time display.

    Now, the question is, how do I read the frequency (it ranges from 0 to about 150
    pulses per second) into the PC so it's useable? I don't know assembler, but from
    what I can tell, it's a low enough sampling rate that I should be okay with
    something less robust like Basic or VBasic or something.

    My extent of parallel port programming is turning on and off an LED in Basic.


    Thanks in advance,

    Kris
     
  2. What O/S? I doubt it's possible to do this reliably under Wind*ws.


    Best regards,
    Spehro Pefhany
     
  3. Kris Duck

    Kris Duck Guest

    I would have preferred to use XP, but I could go with 98 or DOS. Whatever works.
    I thought that Winblows would work as long as it's not a really high sample
    rate. I figured a max of about 160 hertz would be okay.

    The only reason I wanted Win was so I could have a nice graphical display. I
    planned on using Flash or something for the display. As I said though, I can
    probably kludge through a DOS display.

    Kris
     
  4. In modern operating systems such as used by MS widows and by Linux
    it is not recommended to do a real time read, as the software will
    interrupt any loop (taskswitch every few milliseconds) also there are
    interrupts.
    The only way around it is to use say a PIC microprocessor, it has
    a counter specially for this, and then to get the freq from the PIC
    If you use an xtal osc in the PIC it can be very accurate.
    JP
     
  5. Maybe that's something you need to verify. Otherwise it is a
    show-stopper. Interrupt latencies under windows of 50msec are not
    unheard of, which corresponds to only 20Hz.
    My approach would be to use an external microcontroller and a serial
    interface to communicate with the PC. Then you can use a VB program
    and Windows if you like to do the display and the micro will keep
    track of the low-level stuff.

    You could also consider Linux RT, which is fast enough.

    Best regards,
    Spehro Pefhany
     
  6. Pat Ford

    Pat Ford Guest

    Try sticking it into a sound card input. That way you also get a reasonably
    accurate clock, some input protection and you can also pass it on to a scope
    program.
    Pat
     
  7. MikeM

    MikeM Guest

    150Hz is a period of ~7ms.

    A simple Basic program which loops reading the input register on
    the parallel port, and counts the number of low-to-high transitions
    in one second will provide an updated count once per second.

    Something like:

    While (1)

    bit%=INP(&H379) AND bitmask% 'bitmask gets only specific pin
    'INP reads the PP STATUS reg.
    if (bit%>oldbit%) then
    Count% = Count%+1 'detected up edge, increment
    oldbit%=bit% 'reset edge detector
    endif

    TimeNow = TIMER 'function returns seconds

    If (TimeNow>NextTime) then 'new one second counting period?
    Print Count% 'THE ANSWER!!!
    Count%=0 'zero counter for next period
    NextTime = TimeNow+1 'do it again 1 second hence
    ' midnight rollover bug here!
    endif
    Wend

    QuickBasic running under DOS is an option. QB is interupted periodically by
    memory refresh cycles, and a timer interupt. When the former happens,
    QB will loose a few cpu cycles; the latter causes it to loose about
    1 msec, even on a very old, slow cpu. Since your period is 7ms,
    this shouldn't matter.

    VisualBasic running under WIN98 would also work, as long as there are
    not other programs running, or lots of mouse movement. PP (INP/OUT)
    support under Win98 needs a trivial library.

    VB running under WIN2000 requires a PP driver and a library so that
    it can access the PP.

    MikeM
     
  8. CFoley1064

    CFoley1064 Guest

    Subject: reading frequency into PC
    Hi, Kris. For a tachometer going from 0 to 9000 pulses per minute, the easiest
    solution might be to use the National Semiconductor LM2907 frequency-to-voltage
    converter IC, which is made for tachometer applications. You won't even need
    to use waveshaping, due to the built-in hysteresis on the ground-referenced
    input comparator. Just AC couple the input signal (it has to be more than
    about 100 mV p.p. and less than +/- 28V). Cobble together the data sheet
    Minimum Component application circuit on p. 8 of the data sheet, substituting a
    75K resistor in series with a 10K trimmer pot for the 100K R1, and feed the
    outpt into a Radio Shack DMM with RS-232 output. That will give you basic
    datalogging to the serial port of your PC at 0V = 0 Hz and 2V = 10 KHz (trim
    the 10K pot for 2.000V out with a 10KHz input signal), or if you want to, you
    can use VB or QuickBASIC to read the serial port to your heart's content.
    Since the output voltage of the LM2907 is linearly proportional to input
    frequency, you should simply be able to divide down to find your frequency
    within a percent or so.

    http://www.national.com/pf/LM/LM2907.html
    (available at Digikey)
    http://www.digikey.com/

    PC Interface 46-Range Digital Multimeter $69.99 Brand: RadioShack Catalog #:
    22-812
    (and the perfboard and the rest of the components required, including the 12VDC
    wall wart)
    http://www.radioshack.com/

    Good luck
    Chris
     
  9. Ken Smith

    Ken Smith Guest

    There is "real time Linux".

    There are a couple of obvious other ways around it.

    He could not use a "modern OS". A DOS program may be just what he needs.

    At a low pulse rate, he can turn each pulse into a serial character with a
    one shot and count the characters.
     
  10. Tim Auton

    Tim Auton Guest

    Would it work? I doubt it. At least not consistently. Windows is far
    from a real-time OS.

    Use an external counter and read the count from your program (it is a
    parallel port after all). A 4-bit counter would mean you'd have to
    read about every 100ms, which should be OK, but I wouldn't stake my
    life on it never missing counts. Using a 7-bit counter would mean you
    would only have to read the port every 900ms or so, which even a
    loaded Win98 system and a high-level language like VB should be able
    to manage.


    Tim
     
  11. On a sunny day (Wed, 2 Jun 2004 19:52:47 +0000 (UTC)) it happened
    Yes, but not DOS in a MS windows window.
    'On the PC' these days usually implies the MS trojan virus Xp.
    Or Linux more and more of case.
    JP
     
  12. Ken Smith

    Ken Smith Guest

    In this corner we have a 2GHz PC running XP. In the other corner we have
    a 12MHz 8052 running OS3[*]. The 2GHz XP machine can't keep up with the
    RS-232 from the 8052.

    [*] OS3 is the multitasker that runs on this 8052.

    With pre-XP windows such as NT and ME, we have solved the timing problem
    down to about 1mS. With XP we have to add special hardware.
     
  13. Ken Smith

    Ken Smith Guest


    It doesn't work so well on a laptop with an LCD. There is something in
    the driving of LCDs that cause windows to leave the interrupts off for a
    long time.

    Don't put a CD in the CDROM drive.
     
  14. scada

    scada Guest

    www.dataq.com part # DI-194RS $25, is a 10 bit A/D with software! If you
    don't want the graph display, you can use the waveform to input to your VB
    program!
     
  15. On a sunny day (Wed, 2 Jun 2004 21:22:08 +0000 (UTC)) it happened
    You wrote that? Cool, I wrote a small z80 multitasker with windows
    made with ASCII symbols.
    But I ran out or memory and processor power in the 64kB (8080 asm).
    But it booted from EPROM faster then Xp.. much faster much much much faster :)
    JP
     
  16. mike

    mike Guest

    There's a hardware counter normally used to generate the beep on the PC
    speaker.
    It can be exploited for timing functions...as long as nothing beeps
    while you're timing.

    Look up the spec on the 8253 chip. AFIK, It's emulated in all PC chipsets.

    I don't remember where I got this program excerpt...

    '8253 PC timer data
    'Enable timer 2 by setting bit 0 of &H61
    'Set &H43 to 176 to set mode 0 of counter 2
    'Out lsb then msb to port &H42 to set counter value.
    'Poll the counter value to see when it rolls over.
    'The rollover output should be connected to 8255 port c5
    'input from &H62 bit 5 (32) . This doesn't work
    'On 486 system reading from 61 seems to work.
    'On Panasonic xt system, this don't work at all.
    'This program uses the technique to set the speed of
    'a stepper motor.

    I've used this with quickbasic and DOS. Probably latency issues
    with windows.

    You can also hook the 18mS system timer...but that takes
    more knowledge.
    mike
    --
    Return address is VALID.
    Bunch of stuff For Sale and Wanted at the link below.
    Toshiba & Compaq LiIon Batteries, Test Equipment
    Yaesu FTV901R Transverter, 30pS pulser
    Tektronix Concept Books, spot welding head...
    http://www.geocities.com/SiliconValley/Monitor/4710/
     
  17. This is from noppp_lx PIC programmer source (Linux):

    void delay(int k)
    {
    // Delay at least k microseconds.
    // k must be less than 27304.
    // Minimum delay on a 25-MHz 386 is about 100 microseconds;
    // on a 133-MHz Pentium, about 18 microseconds.

    // Uses system timer 2.
    // When running in a DOS box under OS/2, set HW_TIMER ON in DOS settings.

    #define IODELAY (in_byte(0x61)) // allow time for timer to respond

    unsigned int w;
    unsigned char lo,hi;

    out_byte(0x61, (in_byte(0x61) & 0xFD) | 1); // spkr off, tmr 2 gate on
    w = (unsigned int)(k*1.2);
    out_byte(0x43, 0xB0); // tmr 2 mode 0 2-byte load
    IODELAY;
    out_byte(0x42, (unsigned char)w); // low byte
    IODELAY;
    out_byte(0x42, (unsigned char)(w>>8)); // high byte
    IODELAY;
    do
    {
    out_byte(0x43,0x80); // latch timer count
    IODELAY;
    lo = in_byte(0x42); // discard low byte
    IODELAY;
    hi = in_byte(0x42); // get high byte
    IODELAY;
    }
    while ((hi & 0x80) == 0); // wait for a 1 there, signifying rollover

    return;
    } /* end function delay */
     
  18. Guest

    Send it into your sound card. FFT it and find the freq.
     
  19. Ken Smith

    Ken Smith Guest

    You wrote that? Cool, I wrote a small z80 multitasker with windows
    made with ASCII symbols.[/QUOTE]

    The product in question has a mono graphics LCD. The menu system is done
    in text rendered on the graphics screen. There is about 48K of text in
    the menu system.
    No, you just didn't get clever enough and chickened out too soon. You can
    fairly easily put paged data memory on a Z80. The IN and OUT instructions
    that use the BC pair can address 64K of I/O space. You could have put a
    PROM full of text in I/O space and had enough room to finish the project.
    If you'd only thought of that, people might be cursing Jan and the limited
    Z80 instruction set instead of Bill and the limited X86. :)
    With a Z80, about 0.5 seconds is normal. The reset has to last about that
    long. In my 8052 product, the boot takes about a second or so. I have to
    do a memory test and check the status of the file system etc. Its very
    much like a Windows computer in that regard. The big difference is that
    it gets it all done before the batteries go dead.
     
  20. mike

    mike Guest

    Ok, if we're getting clever...
    Use a one-shot to generate pulse that is 80%or so duty factor at the
    highest frequency. Use one input on the parallel port to sample the
    one-shot randomly. The statistics of your samples will be the same
    as the duty factor, which can be converted to a frequency number.
    The bad news happens at zero frequency...it takes a LONG time to
    get a result ;-) Further bad new is that no technique will get you
    to zero frequency. Maybe you really don't need to go that low???
    mike

    --
    Return address is VALID.
    Bunch of stuff For Sale and Wanted at the link below.
    Toshiba & Compaq LiIon Batteries, Test Equipment
    Yaesu FTV901R Transverter, 30pS pulser
    Tektronix Concept Books, spot welding head...
    http://www.geocities.com/SiliconValley/Monitor/4710/
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-