DIP switch problem need help to set address in code!

Making PCB Layouts, Manual routing, Auto-routing, Copper pouring, Updating from Schematic, Manufacturing Output
Post Reply
Message
Author
qbgjkls
Posts: 3
Joined: 15 Aug 2016, 22:50

DIP switch problem need help to set address in code!

#1 Post by qbgjkls » 23 Aug 2016, 21:20

Hi, I am new to PIC in general and have reached a wall trying to figure out how to set the address in the code. I am close to the deadline that would be the end of the product so my options are limited. I cant get the board remade in time and the root cause appears to be a via issue. My only option is to modify the PIC code to set the address for each board instead of reading the DIP switch and setting the address into memory.

I have done as much research as I can in the last few weeks but I hit a wall with progress. I even paid to have a company evaluate the board amd code and it ended with nothing being done to the code. I was told the resistors were not correct and a few other things that ended up being false. There are a lot fo details to this problem.

The board uses a PIC18F4520 (the datasheet:http://www.kynix.com/uploadfiles/pdf659 ... 612916.pdf) . We use this same exact DIP switch and PIC design in many of our other products and never had this problem. We had a new manufacturer make the board and these are the ones that randomly fail. I wont get too much into the PCB layout but if it helps I can post all of the info. Im trying to not have a TLDNR post.

The unit has 12 doors that each get a control board with a PIC. Each board is identical except for the FIP setting to control the door number assigned to it. I dont have access to the person that wrote the code but I am able to tell that the DIP switch works as intended but the corresponding pin on the PIC loses continuity.

When the DIP switch is on it connects the pull ups to the pin and I get 4.8V but when I probe the pin right at the PIC there is 0 and is left floating. The values are correct and have been used for a few years without any changes or problems. Nothing has been changed on the code either.

I started this project not knowing how a PIC reads a DIP and I understand the basics now but my only option given time constraints is to mod the code. The asm code is not well commented and I cant make much sense of it. Even though I hate band aid fixes, I am stuck doing just that.

Here is what I know about the setup. The PICs are on an RS485 network with a maximum of 12 boards or doors. The master is the PC running windows. The network is from a USB to FTDI serial com device via RS485. The address on the DIP matches the door number in binary. The DIP is an 8 position switch but only the forst 4 switches are ever used. All 8 are active but we dont exceed 12 doors so the remaning four stay off to set 0000XXXX, X being 1 or 0.

My company would be extremely grateful for help to get me going in the right direction. I have a lot of confidence in this forum.

The code is below. Can anyone help to figure out where the DIP value is stored and how to remove the part of code that reads the DIP and instead assign an address in the code to the existing variable or memory address location. I dont know the proper terms but hopefully Im close. Each board would have the same firmware except for the door number set in the code. I cant make sense of what the door number variable is or if there is a RS485 address variable that I can set. Im also lost on the network protocol. Im not sure if its a TDM, I2C or CAN. I am not sure how the different methods affect the code. Let me know what you think. It wont let me attach the asm file so here is what I could paste relating to the DIP switch section. I can paste the entire code but didnt know if it was ok to do so.

The DIP switch is on PORTD, RD0 to RD7.

movf EE0A,w
movwf Address_mask2
movf PORTD,w
andwf Address_mask,w
andwf Address_mask2,w
movwf BD_loc

I dont know what address mask is and if BD_loc is what I need to define. I assume that BD_loc is means the board location but Im guessing. I can post more or all of the code if that is ok and it will help. I assume that BD_loc is given an address in the memory register. I dont know what I need to put into the code to just give it the address or BD_loc to use.

What I think I need to do is modify the line that moves PORTD to W register and instead define literal binary value into same memory location or assigned equ. I am a bit confused about how to write a literal value to the memory location that previously contained the PORTD values that defined the RS485 address or what I think is the BD_loc.

I really want to get this working and appreciate any help. I am very new so I apologize for any mistakes in my explanation.

Thanks,
qbgjkls

MDman
Posts: 43
Joined: 25 Oct 2011, 19:53

Re: DIP switch problem need help to set address in code!

#2 Post by MDman » 06 Sep 2016, 21:39

It's probably been sorted now, but I would have been inclined to just get the boards re-manufactured from a different supplier and shipped asap. It will cost more, but I think those boards you have will bite you in the bum at a later stage, especially if there are other vias in the circuit too.

Post Reply