Skip to content

Tutorial — Practice 3: Frequency meter

Learn by programming: follow each step, write your own code, then validate with the lab questions and exam. Adapt pins and routines to your board when needed.

What you will build

Measure frequency with Timer0 as counter, 1 s window via Timer1 ISR, and multiplex three displays.

  1. 1

    Configure PORTD and PORTE for the display

    RD0–RD3 send BCD to the 74LS48. RE0–RE3 select the digit (transistors). Configure both ports as outputs. `ADCON1 = 0x0F` keeps RA4/T0CKI digital for the frequency input.
    
    								        MOVLW   0x0F
            MOVWF   ADCON1
            CLRF    TRISD
            CLRF    TRISE
    							
  2. 2

    Timer0 as pulse counter

    Configure T0CON: `T0CS = 1` (external counter), 16-bit mode, increment on rising edge at RA4/T0CKI. Clear TMR0H:TMR0L before each measurement.
    
    								        MOVLW   B'00111000'
            MOVWF   T0CON
            CLRF    TMR0H
            CLRF    TMR0L
    							
  3. 3

    Define the 1-second window

    For exactly 1 s, Timer0 counts external pulses. Options: Timer1 every 50 ms (20 ticks = 1 s) in an ISR, or a calibrated `ventana_1s` delay tuned in Proteus. When the window closes, copy TMR0H:TMR0L to `snap` variables—that is your frequency count in Hz.

    Tip: Official pseudocode in this practice design challenge.

  4. 4

    Convert count to hundreds, tens, and units

    After measurement, split the value into three BCD digits (max 999; saturate at 999 on overflow). Store in `centenas`, `decenas`, `unidades` variables for multiplexing.
  5. 5

    Multiplex three digits without flicker

    In the main loop (or short ISR): enable one digit on RE, put the BCD nibble on RD, wait ~2–5 ms, turn all off, next digit. Repeat at >50 Hz per digit. The eye sees three stable digits.
    
    								mostrar_digito:
            ; digito_act = 0..2
            ; seleccionar RE, LATD = centenas/decenas/unidades
            CALL    retardo_corto
            CLRF    LATE           ; apagar todos
            RETURN
    							
  6. 6

    Calibrate with a known signal

    In Proteus connect a generator (e.g. 100 Hz, 1 kHz). Compare reading vs actual value. Tune `ventana_1s` or Timer1 reload until error is acceptable. Document useful range (16-bit counter → ~65 kHz max in 1 s).

Before you code — pre-lab

Pre-laboratory — reference research

Research base for Practice 3 (Frequency meter with multiplexed displays, UNEXPO).

Q 1 How does a frequency meter measure signal frequency?

A frequency meter counts pulses during a known time window:

`frequency = pulse_count / window_time`

Example: 1000 rising edges in 1 second → 1000 Hz. The PIC uses a timer in counter mode for external pulses and another timer for the window.

Q 2 Multiplexed 7-segment display

A multiplexed display shares the segment bus (a–g, dp) and enables one digit at a time via transistors or digit select lines.

- Advantage: fewer pins (one 74LS48 + 3–4 digit lines).
- Requirement: fast refresh (~50 Hz per digit) for persistence of vision.
- In the lab: 74LS48 decoder, transistors per digit, Timer to rotate active digit.

Q 3 Timers as external event counters

Timer0 or Timer1 can count external pulses on T0CKI / T1CKI (per schematic):

- Configure prescaler to extend range if needed.
- Read 16-bit register when the window closes.
- Clear counter at each new measurement.

A 1 s window can use another timer or calibrated loop + interrupts.

Connect course Timer0/Timer1 with measurement window and display refresh.

Design your solution

Design before coding

The lab sheet asks for pseudocode and a flowchart before the .ASM. Write yours first, then unlock the reference guide.

  1. 1. Pseudocode
  2. 2. Flowchart
  3. 3. Reference

Write your pseudocode

Include: Timer0 as counter, Timer1 50 ms tick, CNT_50MS (20×50 ms = 1 s), multiplexing and the ISR (save/restore context).

0 characters (minimum 80)

Build and adapt the code

Practica · UNEXPO

Lab Practice 3

Frequency meter with multiplexed 7-segment displays. Use timers for the measurement window and display refresh.

  • Timer as external pulse counter
  • Display multiplexing to save pins
  • Visual persistence with fast refresh (~50 Hz per digit)
  • Calculation: frequency = count / window time

After building — post-lab

Post-laboratory — reference research

Analysis questions after implementing the frequency meter.

Q 1 What error does slow multiplex refresh cause?

If refresh is too slow (< ~30 Hz per digit), visible flicker appears. If refresh blocks measurement too long, the count window distorts. Use short periodic interrupts for multiplexing without blocking pulse counting.

Q 2 Measurement limits with a 16-bit counter

A 16-bit counter maxes at 65535. With a 1 s window, max frequency without overflow is ~65 kHz (theoretical). Above that use a prescaler or shorter window. State your design's useful range in the report.

Compare measured frequency in Proteus with the configured signal generator.

Check what you learned

Exams by difficulty level

Open each level when you are ready. Basic is public; intermediate and UNEXPO levels require a CALETAS account to submit answers.

Basic Basic level — Concept and schematic 3 questions

Frequency measurement and multiplexed displays.

0 of 0 answered

A frequency meter measures frequency as…
Multiplexed display means…
The 74LS48 decoder converts…
Intermediate Intermediate level — Timers and calculation 3 questions

Measurement window, counter and refresh.

0 of 0 answered

If you count 2500 pulses in 1 second, frequency is…
Timer in counter mode increments on…
~50 Hz refresh per digit avoids…
UNEXPO UNEXPO level — Full design 3 questions

Oral on multiplexing, range and measurement errors.

0 of 0 answered

16-bit counter, no prescaler, 1 s window: theoretical max frequency ≈
If display refresh blocks counting too long…
Orally: why multiplex instead of one display per pin?

Tutorial hub · Exercises