News:

;) This forum is the property of Proton software developers

Main Menu

Misterious case for a 16F819

Started by keytapper, Jan 21, 2023, 04:19 PM

Previous topic - Next topic

keytapper

Hi forum,
A friend of mine asked me to help for implementing a push button on the PORTA.5 . The results seems that it doesn't do anything. Setting MCLRE to zero the RA5 should act as digital, but the button is ignored and keeps reading as zero.

There might be a suspect that when activating the ADC module the RA5, won't be enabled. My friend will try it when will get a prototipe to test.

Any idea?
Ignorance comes with a cost

trastikata

It might sound basic, but did he check the button itself with a multi-meter to see its actual state at the pin i.e. the voltage at the pin has to be high and go low when the button is pressed ?

keytapper

#2
I think I discovered the mistery. There's no much documentation about that. Microchip has no mentions to such condition  >:(

This site
is telling that the input is allowed only when the PORTA is set as digital.
So whenever the user wants to read the analog inputs, has to remember to do it just for the necessary time and then set the ADCON1:PCF0~3 to 0111, which leads to all digital inputs (referring to 16F81x chip). The compiler is doing at the very beginning of the assembly.
Probably all the ADC module may be affected to such multiplexing, thus if one pin on the port is needed as digital, then it's necessary to disable the analog channels.
Ignorance comes with a cost

keytapper

Well, my friend reports a failure.
I proposed a workaround with the MCLR that will jump into a particular part of the program. If the project is already running some variable aren't cleared, so I tried to work with that condition.
Ignorance comes with a cost

Parmin

Perhaps a pull up resistor could help to ensure it is at a stable state?

keytapper

Quote from: Parmin on Jan 22, 2023, 09:29 PMPerhaps a pull up resistor could help to ensure it is at a stable state?
Thanks for the reply.
The pull up resistor is obviously external and is there, as my friend shown me. I hope some member will like to test whether owning such MCU.
Ignorance comes with a cost

Stephen Moss

I noticed the the PIC is shipped with LVP enabled and the MCLR function as MCLR enabled.

It may not apply to this device but certainly on some devices that are shipped that way and have dual High/Low voltage programming modes you cannot alter the MCLR pin function in LVP mode. Instead you need turn LVP mode off, flash the new configuration to the PIC so that it is now in normal (High voltage) programming mode and then change the MCLR pin function and re-program it in normal mode with the new configuration, which can include re-enabling a return the LVP mode as LVP mode will not take effect until the PIC restarts after programming.

So if your friend has only been using the LVP mode to program the PIC try changing the LVP bit to the high voltage programming mode, then changing the function of the MCLR pin to Input.
As I recall it has something to do with the fact that in LVP mode voltages on certain pins can accidently put the PIC into Programming mode which could result in the PIC acting oddly if the MCRL pin is being used as an input and it function is somehow reverted from Input back to MCLR, as obviously if that were to occur whenever the input signal goes low the PIC would then be held in reset.

keytapper

Quote from: Stephen Moss on Jan 23, 2023, 09:53 AMInstead you need turn LVP mode off
Thanks for the point Stephen,
We always consider RB3 as output because is expected to drive the LCD. Thus the LVP is just a normal digital output.

Device = 16F819
On_Hardware_Interrupt GoTo Isr

Config FOSC_INTOSCIO, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, BOREN_ON, LVP_OFF, _
CPD_OFF, WRT_OFF, DEBUG_OFF, CCPMX_RB2, CP_OFF

Xtal 8
Ignorance comes with a cost