Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC pulse train (assembly)

Status
Not open for further replies.

riccardo

Member
Hi,

I'm trying to generate a pulse train on PORTB of a 18F2455. I had a simple Idea of running a loop and incrementing the port number, but this gives me an 'argument out of range message. Does anyone know how to do this properly?

I've just listed "channel" in a cblock and set it to 0 before this loop

Code:
Step
	BSF PORTB, channel			; Set output channel high
	CALL Wait					; Delay
	BCF PORTB, channel			; Clear output channel
	CALL Wait					; Delay
	INCF channel
	; If channel > 7 make it 0
	MOVF channel, W				; Copy channel value to W for testing
	SUBWF 8, W					; Subtract W from 8
	BTFSC STATUS, Z				; Check if result is Zero (channel needs to be reset)
		CLRF channel			; Reset to zero
	GOTO Step
 
You can't use a variable for the BCF or BSF instructions, just a 3 bit fixed value that's hardcoded in the line.

If you're wanting to run a bit along the port, check my tutorials for a number of ways of doing it - including multiple patterns stored in tables.
 
Could you point me to the tutorial that covers this? I can't find what I need.

Can I just use...?

Code:
RLNCF PORTB
 
Here's the code I used for anyone who might need it..

"maxChannel" is an 8-bit value representing how many channels should be pulsed before the loop restarts. 10000000 being 8 channels, while 00000001 is just one.

"channel" is the currently selected channel using the same logic as above.

Code:
Start
	CALL ResetChannels		; Reset to channel 1

Step
	MOVF channel, W		; Copy channel selection
	MOVWF PORTB			; SET outputs to selected channel combo
	CALL Wait				; Delay
	CLRF PORTB			; Clear outputs
	CALL Wait				; Delay
	RLNCF channel			; Increment Channel


	; If channel > maxChannels reset to 1
	MOVF channel, W			; Copy channel value to W for testing
	MOVWF L4
	RRNCF L4					; Go back one because of previous increment
	MOVF L4, W
	SUBWF maxChannel, W		; Subtract W from maxChannel
	BTFSC STATUS, Z			; Check if result is Zero (channel needs to be reset)
		CALL ResetChannels		; Reset to channel 1
	GOTO Step				; ELSE do next channel

ResetChannels	
	MOVLW b'00000001'			; Start with Channel 1
	MOVWF channel
	RETURN
 
Status
Not open for further replies.

Latest threads

Back
Top