please dont rip this site


The PIC Source Book: Pulsout

produces a pulse by inverting the state of the specified pin for a period of 1 to 65,535 units of 10 instruction cycles.

Pulsout can produce brief clock pulses to blip the enable lines of LCD modules and logic devices, or wide-range pulses to drive positioning servos. It differs from the Pwm command in two ways: it produces only one pulse each time it is called, and duty cycle is controlled by the ratio of the pulse width to the interval between pulses (if it is called repeatedly).

To use Pulsout, you must set the desired pin to output and supply three arguments: the desired length of the pulse in 10-instruction cycle units in the 16-bit variable consisting of hiB and lowB, the pin number (0 to 7) in pin, and the port number (0 = RA, 1 = RB, etc.) in w.

The type of pulse generated by Pulsout depends on the state of the pin's output latch when the routine is called. If pin is initially 1, Pulsout will invert it to 0 for the specified period of time, then restore it to 1. If it's initially 0, it will be set to 1 for the specified time, then cleared to 0.

Upon return, the contents of hiB and lowB will have been cleared, so keep copies of these values if they are required elsewhere in your program.

Half of Pulsout's 10-cycle delay is produced with nop instructions. If you want a 5-cycle version of Pulsout, remove the nops.

Pulsout, like the other routines that accept pin and port arguments, requires the short table Pinz. Remember that tables must be located in the first 256 words of a 512-word program memory page. One hint on using Pulsout: always assign the port number to w immediately before calling the routine. If you don't, some other instruction that uses w may change its contents, causing an error.

Demonstrating Pulsout.

To see Pulsout in operation, either run the program with the PSIM simulator, or connect the circuit below to an erasable PIC or PIC emulator, such as the Parallax downloader. Assemble and run PULSOUT.SRC. The 'scope will show a series of 100-µs pulses (assuming a 4-MHz clock for the PIC).



;
; ***************************************************************************
; ***  Bubble Software Parallax to PIC Source Converter. Copyright 1999.  ***
; ***  http://www.bubblesoftonline.com                 email: sales@picnpoke.com  ***
; ***************************************************************************
;
; PULSOUT port, pin, time
; Generates an output pulse in 10-cycle (10 us at 4 MHz) units,
; based on a 16-bit (1 to 65,535) value. The pulse is the reverse
; of the pin's state when pulsout is called. For instance,	if the
; specified pin is initially 1, Pulsout will invert it to make a
; negative-going pulse.

	P = pic16c55
	#include <16c55.inc>   ; processor assembler definitions
	_CONFIG _xt_osc & _wdt_off & _protect_off
 reset start

 org 8
hiB Res d'1' ; MSB of time.
lowB Res d'1' ; LSB of time.
pin Res d'1' ; Pin number to pulse (0-7).

temp Res d'1' ; Temporary variables for time delay
temp2 Res d'1' ; between pulses

; Device data and reset vector
 org 0
; Table to convert pin number (0-7) into bit mask (00000001b to 10000000b).
Pinz         ADDWF pcl                  
             RETLW d'1'                 
             RETLW d'2'
             RETLW d'4'
             RETLW d'8'
             RETLW d'16'
             RETLW d'32'
             RETLW d'64'
             RETLW d'128'

start        MOVLW d'0'                 ; All outputs.
             TRIS 5h
             CLRF 5h                    ; Start with 0s.
             MOVLW d'10'                ; 10 x 10-cycle pulse
             MOVWF lowB
             CLRF hiB                   
             MOVLW d'2'                 ; Pin 2.
             MOVWF pin
             MOVLW d'0'                 ; of port ra.
             CALL Pulsout               ; Pulse pin high for 100 cycles.
             CALL delay                 ; Wait a while between pulses.
             GOTO start                 ; Do it again.

; Upon entry, the desired pin must already be set up as an output.
; The w register contains a number representing the output port (0-2) for
; RA through RC. Variable "pin" contains the pin number (0-7). The variables
; hiB and lowB are the MSB and LSB of the time argument.

Pulsout      MOVWF fsr                  ; Point to the port number.
             MOVLW 5h                   ; Add offset for port RA.
             ADDWF fsr
             MOVF pin,w                 
             CALL Pinz                  ; Get bit mask from the table.
             MOVWF pin                  ; Put the mask into pin
             COMF hiB                   ; Take twos complement
             COMF lowB                  ; of the 16-bit counter
             INCF lowB                  
             BTFSC status,z             ; If zero, lowB overflowed,
             INCF hiB                   ; so carry into hiB.
             MOVF pin,w                 ; Invert the selected pin.
             XORWF indirect

; The main timing loop. Remove the nops for 5-cycle resolution.
Pulsout_loop GOTO $+1                   ; Two-cycle "nop."
             GOTO $+1                   ; Two-cycle "nop."
             NOP                        
             INCF lowB                  ; lowB = lowB+1.
             BTFSC status,z             ; Overflow in lowB?
             INCFSZ hiB                 ; Yes: hiB=hiB+1, watch for overflow.
             GOTO Pulsout_loop          ; If not overflow, do it again.
             MOVF pin,w                 ; Invert pin (back to initial state).
             XORWF indirect
             RETLW 0h                   

; Delay routine for demonstration. Not required by Pulsout.

delay        DECFSZ temp                ; Time delay to provide spacing
             GOTO delay
             DECFSZ temp2               ; between pulses.
             GOTO delay
             RETLW 0h                   
             
             
             end


; PULSOUT port, pin, time
; Generates an output pulse in 10-cycle (10 us at 4 MHz) units,
; based on a 16-bit (1 to 65,535) value. The pulse is the reverse
; of the pin's state when pulsout is called. For instance,	if the
; specified pin is initially 1, Pulsout will invert it to make a
; negative-going pulse.

	device	pic16c55,xt_osc,wdt_off,protect_off
	reset	start

	org	8
hiB	ds	1	; MSB of time.
lowB	ds	1	; LSB of time.
pin	ds	1	; Pin number to pulse (0-7).

temp	ds	1	; Temporary variables for time delay
temp2	ds	1	; between pulses

; Device data and reset vector
	org	0
; Table to convert pin number (0-7) into bit mask (00000001b to 10000000b).
Pinz	jmp	pc+w
	retw	1,2,4,8,16,32,64,128

start	mov	!ra, #0 	; All outputs.
	clr	ra		; Start with 0s.
	mov	lowB,#10	; 10 x 10-cycle pulse
	clr	hiB
	mov	pin,#2		; Pin 2.
	mov	w,#0		; of port ra.
	call	Pulsout 	; Pulse pin high for 100 cycles.
	call	delay		; Wait a while between pulses.
	jmp	start		; Do it again.

; Upon entry, the desired pin must already be set up as an output.
; The w register contains a number representing the output port (0-2) for
; RA through RC. Variable "pin" contains the pin number (0-7). The variables
; hiB and lowB are the MSB and LSB of the time argument.

Pulsout mov	fsr,w		; Point to the port number.
	add	fsr,#RA 	; Add offset for port RA.
	mov	w,pin
	call	Pinz		; Get bit mask from the table.
	mov	pin,w		; Put the mask into pin
	NOT	hiB		; Take twos complement
	NOT	lowB		; of the 16-bit counter
	inc	lowB
	snz			; If zero, lowB overflowed,
	inc	hiB		; so carry into hiB.
	XOR	indirect,pin	; Invert the selected pin.

; The main timing loop. Remove the nops for 5-cycle resolution.
:loop	jmp	$+1		; Two-cycle "nop."
	jmp	$+1		; Two-cycle "nop."
	nop
	inc	lowB		; lowB = lowB+1.
	snz			; Overflow in lowB?
	incsz	hiB		; Yes: hiB=hiB+1, watch for overflow.
	jmp	:loop		; If not overflow, do it again.
	XOR	indirect,pin	; Invert pin (back to initial state).
	ret

; Delay routine for demonstration. Not required by Pulsout.

delay	djnz	temp,delay	; Time delay to provide spacing
	djnz	temp2,delay	; between pulses.
	ret


file: /Techref/microchip/seepicsrc/psbpix/pulsout.htm, 8KB, , updated: 2011/1/8 14:40, local time: 2024/11/24 01:12,
TOP NEW HELP FIND: 
3.144.115.125:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/techref/microchip/seepicsrc/psbpix/pulsout.htm"> The PIC Source Book: pulsout</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .