Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic output low signal

Status
Not open for further replies.

amitaiwe

Member level 3
Member level 3
Joined
Feb 19, 2014
Messages
57
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
547
Hi to all,
I’m trying without success to drive an output from a PIC16F877.
No matter what I did the wanted port pins stay on a logic ‘0’ v…
I have in my disposable 3 PIC’s (and I tried the 3 of them), a picKit3 set
And a uniform led (ltl 30hju). I have tried several things including WDT en/disabled, connecting resistors to the led , changing the output port and verifying Led operation.
The input voltage is 5v and so is the output of various (untouched) pins.
When I wire and connect the PIC to the PIC there are no errors provided from
The IDE (8.9) and all the notifications of compilation and programing seem ok.

So, as it seems the problem is some connection/wiring error which I did but I don’t manage go figure it out. Any idea what’s missing?
Basically I want to get an indication that the pic works properly and for that prepares.
I’m using this code:



Code:
	LIST P=PIC16F877
	include <P16f877.inc>

		org			0x00
reset:	goto			start
		org			0x04

start:		bcf			STATUS, RP1
		bsf			STATUS, RP0		;bank 1
		clrf			TRISD
       		bcf			STATUS, RP0		;bank 0
		movlw		0x01
		movwf       	PORTD
		
LOOP:
		rlf			PORTD, f
		call			DELAY
		call			DELAY
		call			DELAY
		call			DELAY 	; delay * 4	
        
		goto			LOOP

DELAY
		movlw		0xff			;  N1 
		movwf		0x30
cont2:	movlw		0xff			;  N2
		movwf		0x31
cont1:	decfsz		0x31,1
		goto			cont1
		decfsz		0x30,1
		goto			cont2
		return	; D=(5+4N1+3N1N2)*200nsec = (5+4*255+3*255*255)*200ns = 39.22ms
								  

		end

Thanks in advance, Amitai
 
Last edited by a moderator:

You might also have two other issues:

1. rotating the bits directly in the port can cause "read modify write" problems because when reading it uses the voltage on the pins rather than what you last wrote to it. Sometimes it will work but loading on the pins may cause the wrong bits to be rotated.

2. the 'RLF' instruction rotates the bits in the port through the carry bit in the STATUS register. If your delay routine changes the 'C' bit the wrong level may be rotated back into bit 0.

There is a simple fix for both problems, rotate the bits in a normal register then write its contents to the port. If necessary you can save the carry bit using the standard swap routine as listed in Microchips interupt handler.

Brian.
 

Hi,

Your code basically works ok, though worth taking note of what Betwixt has just said.

Have also made a couple of amendments to your code.

First it includes a Config line, set up for High voltage programming and using a crystal oscillator 4mhz or below.
Second, an example of how to name and use variables instead of direct addresses in your delay routine.
Third the use of the banksel directive.

Given your code seems to work what about your hardware ?
Is it on a breadboard or a dev board ?
What oscillaltor are you using.
Have all four VDD/VSS pins been connected
Have you got pin 1 Mclre connected to VDD via a 10k resistor.#

Code:
	LIST P=PIC16F877
	include <P16f877.inc>

	__CONFIG _LVP_OFF &_WDT_OFF &_PWRTE_ON &_CP_OFF & _XT_OSC
	; basic config values  Watchdog OFF. Lvp OFF, XT OSC crystal 4mhz and below


	
	cblock 0x20	; define user registers/variables
	d1,d2,d3    ; delay routine

	endc


	org 0x00
reset: goto start
	org 0x04
	
start: 
;	bcf STATUS, RP1
;	bsf STATUS, RP0      ;bank 1
	banksel	TRISD		; USE INSTEAD OF BSF ETC
	clrf TRISD
	banksel  0           ;bank 0
	movlw 0x01
	movwf PORTD
	
LOOP:
	rlf PORTD, f
	call DELAY
	call DELAY
	call DELAY
	call DELAY ; delay * 4
	
	goto LOOP
	
DELAY
	movlw 0xff ; N1
	movwf d1
cont2: movlw 0xff ; N2
	movwf d2
cont1: decfsz d2,1
	goto cont1
	decfsz d3,1
	goto cont2
	return ; D=(5+4N1+3N1N2)*200nsec = (5+4*255+3*255*255)*200ns = 39.22ms
	
	
	end
 

I'm using a breadboard, no oscillator connected ( I don't need to connect when I don't use
one, right?). all Vdd, Vss connected.
I changed the code to a simpler one:

Code:
	LIST P=PIC16F877
	include <P16f877.inc>

		nop
reset:	goto		start
		org			0x04

start:	bcf			STATUS, RP1
		bsf			STATUS, RP0		;bank 1
		clrf		TRISB
       	bcf			STATUS, RP0		;bank 0
		LOOP1:
		movlw		0xFF
		movwf       PORTB
		goto		LOOP1

		end
 

Hi,


You must have an oscillator otherwise the chip cannot work !

Do you have a suitable crystal and capacitors , example 4Mhz crystal and 2 x 22pf capacitors.

You can also use a ceramic resonator or a R/C (resistor/capacitor) though the R/C is only good enough for simple projects.

Say what you have or can easily get then we can tell you how to use it.
 
I tried using a RC without success.
I have a CRYSTAL OSCILLATOR HO 11C of hosonic.
The oscillator is supposed to be simple but It also dosen't show any Freq. in the DMM.
it is a 4 leg osc. which I connected to vdd and vss with and output (no other leg to connect to
the osc2 leg !? )

Thanks again, Amitai
 

Check your DMM can measure frequencies up to 4MHz, many can't. It seems your connections are correct OSC o/p -> OSC1 with OSC2 left disconnected. With no clock it certainly wont work so sort that out first.

Brian.
 

I tried using a RC without success.
I have a CRYSTAL OSCILLATOR HO 11C of hosonic.
The oscillator is supposed to be simple but It also dosen't show any Freq. in the DMM.
it is a 4 leg osc. which I connected to vdd and vss with and output (no other leg to connect to
the osc2 leg !? )

Thanks again, Amitai

Hi,

What values R and C did you use ? - R/C will probably be way too slow for your original code using a delay, if remove some of the delays it may work ok

What is the stated frequency of that type of oscillator, there are various frequencies under that HO 11C code.
You will not be able to measure its output with most dvms, you will need a scope.

Also you did not mention if you had pin1 connected to Vdd, without that it will not work properly.
 

The led works!!
Thanks to all the helpers

and now to the next stage...

I want to transmit data via UART to a Bluetooth module (RN42SM).
The BT works well - a PC manages to connect to it and send to it information and the red led of transmitting
on the BT turns on.
The problem is transmitting data via the Bluetooth which doesn't happen for some reason.
The connection of the VDD and the Vss is correct because the BT to PC communication works well.
I left the code of the LED as part of this code for checking that nothing went wrong in the meantime. The wiring that has been done is VDD and VSS and RX to TX and vice versa.

Thanks again,
Amitai

WP_000057.jpg

here's the code:

Code:
LIST P=PIC16F877
include <P16f877.inc>

	__CONFIG _LVP_OFF &_WDT_OFF &_PWRTE_OFF &_CP_OFF & _RC_OSC
; basic config values  Watchdog ON, Lvp OFF, XT OSC crystal 4mhz and below


		nop
reset:	goto		start
		org			0x04

start:
; configuration
;-----------------------------------

	  bcf		STATUS, IRP	 ; Indirect Addressing to Bank 0-1
;UART/*/*/      
	  bsf		STATUS,RP0	 ; bank 1
	  bcf		STATUS,RP1
		movlw    0xB2        		 ; master, transmit EN, sync mode, Transmit Shift Register empty
		movwf    TXSTA	       		; Baud Rate = Fosc/(4(SPBRG+1)) , BRGH (baud rate) ignored in sync
		
		; clrf     TRISC         		; making port C output (also for SPI) 
		bsf	 	TRISC, 6 
		bsf		TRISC, 7	
		
		movlw	 0x10		   		; = d"16" which corresponds to 15Kbps with 8MHz clock
		movwf	 SPBRG
	
	  bcf		STATUS,RP0	; bank 0
		movlw    0x80		  		; enable UART	
		movwf    RCSTA	
		 
;LED/*/*/
		bsf			STATUS, RP0		;bank 1
		clrf		TRISD
; end configuration --------------------------------------


;************ MAIN PROGRAM ***************
;*****************************************
		bcf		STATUS,RP0	; bank 0
		movlw	0x50
		movwf	FSR	

	fill_reg:	
		incf	INDF
		incf	FSR
		movlw	0x60
		subwf	FSR, W
		btfss	STATUS, Z
		goto	fill_reg
		
MAIN_loop:
			
;-----transmit_data
		movlw	0x50
		movwf	FSR								; indirect Addressing points on 0x21	
		
	transmit_data:
		movf	INDF, W
		movwf   TXREG					    	; writing to TXREG clears TXIF
        trans_wait2:	btfss	PIR1, TXIF		; wait for the frame to be transmitted
		goto	trans_wait2
		;call	DELAY

		incf	FSR, F
		movlw	0x60							;transmit for 16 sensors
		subwf	FSR, W
		btfss	STATUS, Z
		goto	transmit_data
	
	led_loop:
			movlw		0x02
			movwf		0x32
			movlw		0x02
			movwf		0x33
				
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY
			
			led_green:	
			bcf			PORTD,3
			bsf			PORTD,2		
			decfsz	    0x32, f
			goto		led_green
			
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY
			CALL		DELAY

			led_red:
			bcf			PORTD,2
			bsf			PORTD,3
			decfsz	    0x33, f
			goto		led_red
			
	goto		led_loop	
	
goto MAIN_loop
				
;******** END MAIN LOOP ********************		

DELAY:
		movlw	0xFF
		movwf	0x30
		movlw	0xFF
		movwf	0x31
	
		loopa:
		decfsz	0x30, f
		goto	loopa
		loopb:
		decfsz	0x31, f
		goto	loopb
		return

end
 

Please don't change bank with bsf and bcf instructions, it makes it difficult to follow, use 'banksel' instead. Also be extremely careful if you pick addresses like 0x30 and 0x31 which could clash with something else. Instead define variables with the 'cblock....endc' directives and give them names. That will automatically tell the compiler to allocate free addresses and make the code much easier to read. Wp100 is giving you good advice, please follow it.

Brian.
 

OK, thanks betwixt, i'll change that.
what about the BT problem?

Amitai
 

Hi,

You need to clarify things, your picture is showing a R/C as the oscillator, do you have any idea what frequency that creates ?

As you will have see from the code you have used, the USART timings are all based on the main oscillators frequency; as said earlier the R/C oscillator is only good for simple projects, for the USART you must use a crystal, ceramic resonator or external oscillator.

Suggest you obtain a 4, 8 or 16 mhz crystal and matching caps before trying any further work on your USART code.

On your breadboard fit a 100nf cap across VDD and VSS as close to the pic pins as possible to avoid interference.

You might find these tutorials of use.

**broken link removed**
http://www.winpicprog.co.uk/pic_tutorial.htm
http://www.amqrp.org/elmer160/lessons/
http://www.epemag.wimborne.co.uk/resources.htm
http://www.mikroe.com/chapters/view/5/chapter-4-timers/
 
Thanks again,

I do have a 20Mhz oscillator (HO 11 of hosonic) which has very little data available.
It's a 4 leg osc with a N.C. , Vdd , GND and output legs.
Checking the output of the osc with a DMM (without connecting it to the pic)
provides an output of a few Khz maximum, assuming that the DMM is correct
in the frequency measure.

Thanks for the tutorials, they have good explanations.

Amitai

PS
I don't need any interrupts as TMR0, correct?
 

Hi,

Best way to check things out is connect the oscillator as show in the pic below.

Take the working code I sent in entry #4, but change the Config paramenter XT_OSC to HS_OSC

Then program that code into the 877 and see if you can see PortD running up and down all 8 bits in about 2 seconds - if it does then the oscillator is good.

Do not place your meter on the oscillators output or pics osc input pins as the load of the meter will possibly affect its running.

As said most dmms only measure low frequencies; with 20mhz don't thing even a fluke dvm would do that
 

Attachments

  • 000101.jpg
    000101.jpg
    27.2 KB · Views: 65
Hi amitaiwe,

Depending on the oscillator vlaue ur using u should change SPBUG(Baud Rate Generator Register). Please refer table 10.3 in the datasheet. Bluetooth module (RN42SM) dafault burd rate is 9600 so if u use 20MHz oscillator the value of SPBUG is 31, 9600 BURD will be selected. I suggest u to check the USART communication with out connecting the blurtooth. use scope to see the output or if u have max232 use pc to verify USART functionallity.
 

Hi,
Want I wanted to do on the first place is to use this project:
https://www.micro-examples.com/public/microex-navig/doc/076-picodetector.html
and send the data that is received via BT.

When I think about it- In that project He uses an LC circuit for creating the freq.
and for sending the data via UART I need a resonator/crystal.

Is there any solution for this problem? checking the freq. change in another way?

Thanks, Amitai
 

What about using the SPI protocol by sending the output of the clk out (which is oscillated by
the external crystal) to the SPI receiver (of the same PIC)and measuring the changes of the incoming freq. ?

Amitai
 

What about using the SPI protocol by sending the output of the clk out (which is oscillated by
the external crystal) to the SPI receiver (of the same PIC)and measuring the changes of the incoming freq. ?

Amitai


Hi,

You need to try and understand what the micros are about, like your own heart, it must beat regularly for you to work, and it has to function within a minimum and maximum range.

A micro is even more exacting , demanding accuracy of the heartbeat, typically at around 1 millionth of a second per pulse.
Expecting random pulses from a metal detector as the main oscillator simply will not work for anything practical.

All communications like USART, SPI, I2C need exacting timings to be able to work with the devices they connect to.

Your best way forward is to look for a Pic project that does the detecting but from a standard port pin/s so allowing you to use a proper crystal as the main oscillator which then allows you to run the program code and communications properly.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top