M a r k   C r o s b i e

You are in: PIC 100Khz square wave  Home  Resume  Linux  LEGO  Electronics  Movies  Mac OS X 


Details
Development LED flasher Square wave generator Timed delay library Serial I/O Stepper motor driver Motor Mind B LCD library
Contact Mark at mark@mastincrosbie.com

PIC 100KHz Square Wave generator

Following on from the LED flasher circuit, we can reduce the delay in the loop to 10uS (10 microseconds) and produce a 100Khz square wave.

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:
; 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

CNT	dt	0
CNT1	dt	0
CNT2	dt	0
CNT3	dt	0
CNT4	dt	0

; delay for w uS. Set the w register to the desired delay value

MDELAY:
	MOVWF	CNT		;LOAD DELAY TIME
COUNT:	NOP			;TWO NO OPERATIONS
	NOP			;TO OBTAIN THE DELAY
	DECFSZ	CNT,1		;DECREMENT THE COUNTER
	GOTO	COUNT		;GOTO COUNT IF NOT FINNISHED
	RETURN
 
  end


 
cover
PIC Microcontroller Project Book
Lot's of great PIC project ideas!
cover

Programming and Customizing the Pic Microcontroller

If you are learning to program microcontrollers then Myke's book is good start.
cover
The Art of Electronics
A classic in the field. Teaches you the art and science of linear and digital electronic design. If you want to learn why your circuit is not working, read this book and you'll know why.
cover
Mobile Robots: Inspiration to Implementation
A very readable introduction to the art of robotic design and implementation from the best practioners in the field: the MIT Artificial Intelligence Lab!
cover
Microcontroller Cookbook
A set of cookbook style designs for the 8051 and PIC microcontrollers. A handy reference to have if you need a quick solution to a problem.

© 2002-2004 Mark Crosbie   shareright © 2002 Phlash