Summary of 100KHz Square Wave generator using PIC16C84
This article describes a PIC16C84 assembly program (flashfast) that generates a ~100 kHz square wave by toggling PORTA.0 with 5 µs delays, intended as a simple oscilloscope test signal. It includes source, hex, and schematic, plus hardware notes for reset, PWRT, and an LED with a 220 Ω resistor on RA0.Parts used in the PIC16C84 100kHz Square Wave Generator:
- PIC16C84 microcontroller
- 4 MHz crystal or oscillator (XT mode)
- 4.7 kΩ resistor (reset pull-up to Vcc)
- 220 Ω resistor (series with LED)
- LED
- Power supply (Vcc) and ground connections
- Optional programmer to load flashfast.hex
Given a 4 Mhz PIC 16C84, the program below will generate a 100Khz square wave on PORTA bit 0 (i.e. pin 17). This little program is useful for testing oscilloscopes (though it is not very accurate).
This program is available as:
- flashfast.asm assembly source
- flashfast.hex object file
- flash.jpg schematic
; Mark Crosbie 9/12/98
; Scope test program. Generate a 100Khz square wave.
;
; The Program simply sets up Bit 0 of Port "A" to Output and then
; loops, setting the value alternatively low and high
;
; Hardware Notes:
; Reset is tied through a 4.7K Resistor to Vcc and PWRT is Enabled
; A 220 Ohm Resistor and LED is attached to PORTA.0 and Vcc
;
; device pic16c84
include "p16c84.h"
__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON
; Mainline of FlashFast
org 0
clrf PORTA ; Clear all the Bits in Port "a"
clrf STATUS
bsf STATUS, RP0 ; Goto Bank 1 to set Port Direction
bcf TRISA, 0 ; Set RA0 to Output
bcf STATUS, RP0 ; Go back to Bank 0
Loop
movlw 1 ; Turn on the LED on Port A
movwf PORTA ;
movlw 5
call mdelay ; 5 uS delay
movlw 0 ; Turn off the LED on Port A
movwf PORTA ;
movlw 5
call mdelay ; 5uS delay
goto Loop
; counter variables
For more detail: 100KHz Square Wave generator using PIC16C84
Quick Solutions to Questions related to PIC16C84 100kHz Square Wave Generator:
- What does this program generate?
It generates an approximately 100 kHz square wave on PORTA bit 0 by toggling the pin with 5 microsecond delays. - What PIC device is used?
The program is written for the PIC16C84. - What clock frequency is required to get 100 kHz?
The example uses a 4 MHz PIC clock to produce the approximate 100 kHz square wave. - How is RA0 configured in the code?
RA0 is set as an output by clearing TRISA bit 0 in Bank 1. - How are the high and low periods achieved?
The code writes 1 and 0 to PORTA with calls to a 5 microsecond delay routine between toggles to form the square wave. - What hardware is suggested for the LED connection?
An LED is connected to PORTA.0 with a 220 ohm series resistor to Vcc. - Are any configuration bits mentioned?
Yes; configuration disables code protection and watchdog timer, selects XT oscillator, and enables power-up timer (CP_OFF & WDT_OFF & XT_OSC & PWRTE_ON). - What files are provided with the program?
The assembly source flashfast.asm, the object file flashfast.hex, and a schematic flash.jpg are provided.
Related projects
Exploring the World of PIC Microcontrollers: An Architectural Overview
A Peripheral Interface Microcontroller (PIC), developed by General Instruments Microcontrollers in 1993, operates under software control and is programmed to execute various...
LCD & Display Projects · PIC16C842-Wire LCD Interface using PIC16C84
Alphanumeric LCD displays have become very popular for microcontroller applications because they can add a lot to a project in a variety...
LCD & Display Projects · PIC16C84Using an LCD’s for Graphics Animation using PIC16C84
This project uses Myke's 2-Wire LCD Interface from last week and will help teach you "Graphics Animation" using LCD's. Last week, I...
Power & BatteryImplementing Smart Cooling Control for Induction Heaters with PIC Microcontrollers
Today, induction heating powers countless industrial processes like melting, heat treatment, and welding, plus everyday appliances like cooktops. Its key advantages? High...
Power & BatteryIntegrating Solar Power: Microcontroller-Based Approaches for Domestic Electricity
Abstract: Microcontrollers have found extensive application in endeavors aimed at reducing power consumption. The availability of microcontroller development tools has made them...
Power & BatteryEfficient Power Generation with Microcontroller-Controlled Thermoelectric Generators
INTRODUCTION The global demand for electrical energy continues to rise steadily, necessitating a shift towards renewable energy sources as traditional fossil fuels...
