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.

Strange Output - HELP Please

Status
Not open for further replies.

3BABY

Member level 5
Joined
Jan 14, 2011
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
New Zealand
Activity points
2,252
Hi Guys,

so after working on my project for a few months now i have come across some strange output.. i have set up the ports below, basically after some computations im my program i output an 8bit binary number to portb.. portd is working fine.. the strange thing is.. when i turn on my development board say for example i am expecting 01001000 on portb (after computations and im inputing a static variable), i dont get this result i get 10011110.. this is not a problem with my math functions in my program ( i have checked them and verified in MPLAB SIM) sometimes when i turn on the development board i get the proper result, then ill turn it off and back on and i will have the incorrect output on portb.. it seems like an intermittent problem.. and the only thing i can think of is that i have not setup the ports properly? i have all the outputs pulled low via a 10k resistor on each. i have tryed using a differnt MCU (PIC18F4550).. and i have the same problem

any help would be much appreciated! :)

Code:
;------------ Port Settings --------------------------------------


		CLRF PORTB			;PORTB is output 
		CLRF TRISB

		CLRF PORTD			;PORTD - output except RD6 which is input

		BCF TRISD, RD0
		BCF TRISD, RD1
		BCF TRISD, RD2
		BCF TRISD, RD3
		BCF TRISD, RD4
		BCF TRISD, RD5
		BSF TRISD, RD6
		BCF TRISD, RD7



;--- after computations--


MOVFF VAR2, PORTB
 

There is ne error on this code. may be wrong your comp. Can you show all your code.
 

There is ne error on this code. may be wrong your comp. Can you show all your code.


Hi there,

thanks for the reply, the code compiles with no errors.. to be honest the program is huge and is not worth putting up.. it would just create more confusion, the computations are good.. i have checked them. below is a screen shot of the output in MPLAB SIM

address 75 (VAR2) is what i am trying to send to portb (as you can see it is the same a address 62.. this is taken from the end of the computations).. everything look good in the SIM but im practice sometimes when i turn on the MCU it works.. sometimes it gives me a incorrect output..



**broken link removed**
 

hi
can you debug? look value of VAR2. then compare it with PORTB.
 

hi
can you debug? look value of VAR2. then compare it with PORTB.

Hi,

i cant debug in system.. i dont know how to use it with this dev board.. but as you can see from the sim VAR2 = 01001000 and this is sent to portb.. but sometimes i get 10011110 on portb

i have this dev board: MikroElektronika - EasyPIC6 Development System - PIC Development Board

could it be a hardware fault? i have tried the MCU in two different boards.. and also tried two different MCUs..

is there any other port settings im missing? for example 1 out of 5 times i turn on the MCU in the dev board i get bad output.. the other times it works like it should
 

i cant debug in system.. i dont know how to use it with this dev board.. but as you can see from the sim VAR2 = 01001000 and this is sent to portb.. but sometimes i get 10011110 on portb

what are you using as IDE? Yes VAR2 must be 01001000.

could it be a hardware fault? i have tried the MCU in two different boards.. and also tried two different MCUs..
i think it cant be hardware fault. so i cant say about your code is correct or not. i have explorer 16 dev board. if you want i can debug your code here.

is there any other port settings im missing? for example 1 out of 5 times i turn on the MCU in the dev board i get bad output.. the other times it works like it should
 

yes i agree i cant see any reason why it would be a hardware fault..

ill PM you with the code..

many thanks
 

yes i agree i cant see any reason why it would be a hardware fault..

It could be jumper settings, most of the ports on the MikroE boards have several possible devices attached. I have a couple of the EasyPIC boards.

Are you using the MikroC compiler or another third party compiler?


ill PM you with the code..

I do not believe you can send attachments through the PM system. A better idea would be to zip up your project and upload it to the thread.
Doing so would allow several of us to have a look at the code and debug it with an EasyPIC board, if they have one available.

Ciao
 

Hiya,

thanks for the reply. your correct it was too big to send.. i emaild it. i would prefer to email the code to anyone thats interested.. i know this sounds a little counter productive but this is a 4th year engineering project i dont really want floating around the web & the code is very very messy and needs allot of explaining.. i can email you the asm.. or the project if you like? just PM me your email.. it would be great if you could put it on one of oyur boards..

i have set all my jumpers correct to the best of my knowledge.. VCC on the push buttons and all ports to pull low

i using MPLAB IDE v8.63
 

Hi there,

In my experience, PICs are notorious for problems like these, I would suggest trying to write to the output latch as opposed to directly to the port, ie LATB instead of PORTB, even if this doesnt solve your problem it is good working practice.

Other than that, have you configured the PORTS correctly in terms of on-board peripherals, for instance the SPI in on PORTB, there are also some A2D channels that could be contributing to the problem, on page 115 onwards of this datasheet

https://ww1.microchip.com/downloads/en/DeviceDoc/39632b.pdf

it summarises the PORTB associated registers, ensure that any extra functionality is turned off before setting up your TRIS settings, this could well be your problem, regardless of the fact that it is working sometimes!

Also, make sure that your PORTB pins are set to digital I/O in your config settings.

Hope this helps.

Pete.

---------- Post added at 09:08 ---------- Previous post was at 09:01 ----------

My bad, thought it said PORTB, regardless, its still worth checking the onboard peripherals associated with that PORT and still worth writing to the latch. Page 120 of the above datasheet has the information about it.

Pete
 

File received.

Please give me a rundown on all jumper and switch settings attached to PORTB.

It's 2:30AM, so I'll be shutting it down for the night soon. I'll fire up the EasyPIC in the morning.

Ciao
 

Hi there,

In my experience......

Hi Pete,

thanks for the reply, this is the first time ive experienced this type of issue.. im having a look at the data sheet at and around the pages you recommended and going to do a little work with the initialization of PORTB and LATB.. will let you know how it goes..

cheers :)

---------- Post added at 09:02 ---------- Previous post was at 08:56 ----------

File received.

Please give me a rundown on all jumper and switch settings attached to PORTB.

It's 2:30AM, so I'll be shutting it down for the night soon. I'll fire up the EasyPIC in the morning.

Ciao

yeah was getting a little late here too so went and caught some Z's .. awesome thanks..

ok so

- the Dip Switch on the Right Hand side of the board next to the PORTB 10pin header.. all are set to "on" and the jumper next to it is set to pull down,

- on the bottom Left corner of the board just below the RESET switch and next to the push buttons the jumper is set to "VCC"

- just under the LCD Contrast the Dip Switch is set to "LED ON" on PORTs A/E thru D


thanks :)
 

- the Dip Switch on the Right Hand side of the board next to the PORTB 10pin header.. all are set to "on" and the jumper next to it is set to pull down,

Is this DIP switch SW2? If so set them all to "off", run your program again and let me know the outcome.

Leave the remaining settings unchanged:

- on the bottom Left corner of the board just below the RESET switch and next to the push buttons the jumper is set to "VCC"

- just under the LCD Contrast the Dip Switch is set to "LED ON" on PORTs A/E thru D

I'll wait for your reply.

Ciao

---------- Post added at 04:06 ---------- Previous post was at 03:50 ----------

By the way, do you have either the optional 2x16 LCD or the GLCD installed? Both of which use PORTB lines and could easily overload the bus causing what is referred to as read-modify-write issue. If either optional display is install, remove it and run your program again and report the results.

Ciao
 

How are you reading the value on PORTB? By the LEDs? Has the frequency of the "false" outputs decreased?
 

1. For PIC18F4550, some PORTB pins are configured as analogue inputs on reset.
2. LATB should be used for output instead of PORTB, especially from Hardware point of view.
3. It is better to program the chip and run it in standalone mode, without attaching it to an emulator/debugger etc.
 

1. For PIC18F4550, some PORTB pins are configured as analogue inputs on reset.

3BABY has disable the ADC in the code, so this is not an issue.

2. LATB should be used for output instead of PORTB, especially from Hardware point of view.

Either way, PORTB or LATB, works fine on the EasyPIC5 here,

....going to do a little work with the initialization of PORTB and LATB.. will let you know how it goes...

3BABY indicated neither works on the EasyPIC6 there.

3. It is better to program the chip and run it in standalone mode, without attaching it to an emulator/debugger etc.

Correct, if the debugging process would interfered with time critical routines like serial communications
But in this case,
Incorrect, slowing down the program execution, would if anything allow the false levels, due to capacitive overloading, on PORTB to stabilize in relation to the LATB levels.

i cant debug in system.. i dont know how to use it with this dev board..

Besides, 3BABY hasn't used the debugger.

Ciao
 
Last edited:

How are you reading the value on PORTB? By the LEDs? Has the frequency of the "false" outputs decreased?

im reading the output of PORTB on the LEDs on the EasyPIC6.. with SW2 set to "off" the frequency of the erroneous output has gotn slightly worse say 1 out of 4 times, after setting SW2 to "on" and pull low the frequency decreases to say 1 out of 7 times.

i have a PIC-Ready 1 board with some LEDs attached that i put the same MCU in.. and PORTB is pulled low.. and i get the bad output 100% of the time..

could this be a hardware issue or code.. thats where im confused..


.. i was swamped yesterday so im going to see if i can work around with the LATB today etc etc
 

could this be a hardware issue or code.. thats where im confused..


.. i was swamped yesterday so im going to see if i can work around with the LATB today etc etc

ok so ive initialized PORTB/ LATB and for example used:

MOVFF VAL2, LATB

and still no change in the error in output on the EasyPIC6 or the PIC Ready1.. so .. as you will see in the commented out code below i commented out MOVFF VAL2, LATB and used

MOVLW d'170'
MOVWF LATB

just to see if i would get 10101010 on PORTB and this works on the EasyPIC6 and the PIC Ready1.. so this must be a software based issue.. is it a problem with the MOVFF instruction? what in practice is the difference between MOVFF VAL2, LATB and MOVWF LATB in terms of getting some output on PORTB ..
 

Hey Guys,

so after a long wait.. and allot of working through the code chopping out parts and doing a process of elimination i have solved the issue, turns out it was a bad Table Pointer that was returning an incorrect value.. and hence screwed up the rest of the calculations..

Thanks all :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top