Tuesday, January 12, 2021

PIC16F887 Timer1 and Ultra Sonic Range Measurement Application

Introduction

Additionally to Timer0, PIC16F887 has an 16-bit timer - Timer1. This timer is more advanced than Timer0. It has some additional features over Timer0

  • Optional LP oscillator
  • Synchronous or asynchronous operation
  • Gate mode
  • Interrupt on overflow
  • Capture/compare function, etc.
PIC16F887 Timer1 and Ultra Sonic Range Measurement Application
Block diagram of Timer1

 There are some registers to Timer1.

PIC16F887 Timer1 and Ultra Sonic Range Measurement Application
Registers relate to Timer1


 Timer1 Control Register (T1CON) set the overall operations of Timer1.

PIC16F887 Timer1 and Ultra Sonic Range Measurement Application
Timer1 Control Register (T1CON)

 Timer1 Application of Ultra-Sonic Range Measurement

An application of timer is pulse width measurement of external incoming event. For instance Ultrasonic Ranging Module HC-SR04, is a low cost popular range measurement for electronics hobbyist.



PIC16F887 Timer1 and Ultra Sonic Range Measurement Application
Popular HC-SR04 sample (Ali Express)

This module is a non-contact measuring type of sensor. It uses sounds wave traveling in space, along with its echo signal to get the distance. Measurement ranges from 4cm to 4 meters.

To make its measurement works properly the programmer must check its timing diagram.  

PIC16F887 Timer1 and Ultra Sonic Range Measurement Application
Timing Diagram

 It has a formula to measure range in term of receiving pulse width.

Range = (high level time)*(velocity)/2

Velocity of sound is 340m/s.

In short form we use only high time in us,

Range (in cm) = high level time (in us) / 58 

To get range in Inch,

Range (in inch) = high level time (in us) / 148

Programming in MikroC

System has HC-SR04 as its input. A character LCD output displays sampling range measurement. PIC16F887 controller uses its internal 8MHz oscillator.

Timer1 measure echo signal from HC-SR04 input to RD1. RD1 of PIC16F887 is trigger pin initiating range measurement of sensor. Prescaler is assigned to 1:2 to get a 1us timing.

PIC16F887 Timer1 and Ultra Sonic Range Measurement Application
Schematic Diagram


 MikroC source code:



Click here to download its zip file.

No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)