18F4680 pins will not go low - Page 1
Forum section: electronics / general

author: txescientist
author_rank: Regular Contributor
timestamp: April 12, 2017, 08:40:37 pm
content: Hi to all!I have a strange problem. Pins 22 and 21 (port D3 and D2) on PIC 18F4680 will not go low as they should. I have disabled comparator, parallel slave port and what not and it still will not work. Can someone please help? Attached you can find logic analyzer screenshot of the problem.Code:'18f4680 PicBacic PRODEFINE OSC 20 '20MHzECCP1CON = %00000000CCP1CON = %00000000CMCON = %00000111TRISE = %00000000TRISD = %00000000ADCON1 = %00001111output portd.2output portd.3main:low portd.3low portd.2pauseus 100high portd.3high portd.2pauseus 100goto main

author: Niklas
author_rank: Frequent Contributor
timestamp: April 12, 2017, 10:32:54 pm
content: Have you checked the ANSEL and ANSELH registers? If I remember correct, the pins with analog features are set to analog after reset.

author: JTR
author_rank: Regular Contributor
timestamp: April 13, 2017, 08:20:31 am
content: Looks very much like a RMW problem. (Google is your friend. Try googling "pic rmw problem").

author: macboy
author_rank: Super Contributor
timestamp: April 13, 2017, 01:44:27 pm
content: Quote from: JTR on April 13, 2017, 08:20:31 amThisshould notbe a RMW problem. The 18F series, including 18F4680, have output latch registers (e.g. LATD) which are used to set the output state, and will not read back the present state of the output pins. They are intended specifically to avoid the RMW problem. Provided that PicBasic Pro wasn't developed by a room full of monkeys banging randomly at keyboards, then it should be using the latch registers for the low and high instructions, and there will be no RMW issue.To help eliminate RMW issue, add maybe five NOPs after each low or high instruction (Google says "@ NOP" will do it). A NOP is equivalent to a one-cycle delay. I can't imagine that this will fix the issue, but if it does, then that proves the monkey theory. Otherwise you have some other issue.

author: JTR
author_rank: Regular Contributor
timestamp: April 13, 2017, 02:44:38 pm
content: I would hope you'd be right but I see no references to latches on the PBP web site.http://melabs.com/resources/pbpmanual/Anyway even a RMW problem should only affect the first outputted low. The second should not be affected but that said, and with a quick look at the data sheet I cannot see that the op has done anything wrong with the code. To me, at least the second low should stick. Really not sure...

author: txescientist
author_rank: Regular Contributor
timestamp: April 13, 2017, 02:58:09 pm
content: Found the problem, just need to verify it and I will post the results. When I use CMCON = %11111111 it works, but I have to test portD.0 and portD.1. There are many things to consider when the part has 480 pages datasheetThank you all

author: picandmix
author_rank: Frequent Contributor
timestamp: April 13, 2017, 08:54:23 pm
content: Are you using the 4680 for some if its special features like CAN or is it just a chip you had around.The 4620 has the same memory, but much simpler i/o , functions and register set ; a lot easier to set up and use.The 4520 similarly easier but a bit less memory.

author: txescientist
author_rank: Regular Contributor
timestamp: April 13, 2017, 09:10:10 pm
content: Just using it for the digital I/O, measuring voltage... general purpose, but I need 64k of memory. Recompiled the program from 18F4550 to 18F4680 and it works good, besides this little problem I had. Which one do you think is more reliable PIC, 4680 or the 4620? Using 4550 for a lot of stuff and never have a problem with it. Have weather station built around it and it works great since 4 years, 24/7, never had a glitch, so I think it is very reliable.

author: picandmix
author_rank: Frequent Contributor
timestamp: April 13, 2017, 09:51:03 pm
content: Am sure those three chips are equally reliable, its just that the 4680 with its extra fuctions like CAN use so many more system registers that use up whats normally user ram, that its your code thats in danger of inadvertently affecting this, that will cause the program code or hardware functions to clash.Your complier should help avoid such problems, but as you have already found not all of them; the trouble is some problem may not be evident during compling or early testing.Still as long as you are aware if these potential problems you should be ok, but if I had to buy more chips I would get a 4620.

author: txescientist
author_rank: Regular Contributor
timestamp: April 13, 2017, 09:55:53 pm
content: That is a good point and an advice. Thank you