Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with MPLAB SIM

Status
Not open for further replies.

ljcox

Well-Known Member
I have a Desk Top computer that employs Windows 7.
I have MPLAB V8.92 and have an unusual problem with a programme I am currently writing.

Using MPLAB SIM, I cannot see any change to PORTA in the Watch Window when I attempt to simulate an output change.

Below is a sample of the code. After executing bsf rly, there is no change to PORTA.

I set TRISA to make RA4:0 outputs.

I had this problem several years ago with another programme I was attempting to stimulate, but unfortunately, I can't recall what I did to fix it.

I have explored the options in MPLAB but cannot find anything that will fix the problem.
I even used Control Panel to repair MPLAB but that didn't make any difference.

Any assistance will be appreciated.

#define chk_sw PORTA, 0 ;applies +5V to switches
#define rly PORTA, 2 ;relay
#define buzzer PORTA, 3

ORG 0x00 ; processor reset vector
call init ;Initiate parameters
bsf rly ;operate relay
 
As Ian says turn off the comparators or ADC

As the pic shows, it runs ok, but when defined as 'rly' the watch window changes to 0x04 when the TRISA is executed ? changing it to 'rly1' then it changes correctly to 0x04 on the BSF instruction (v8.92)
 

Attachments

  • 000048.jpg
    000048.jpg
    46.3 KB · Views: 259
The ADC is already off. It's all about pin mode assignment.

If you're using pins that are multiplexed with the on-chip ADC, you have to write to the appropriate register to assign these pins to digital I/O mode.

Which PIC are you using?
 
The ADC is already off. It's all about pin mode assignment.
Not on microchip they aren't.... You HAVE to turn them off... I have been stung too many time with this...
 
Not on microchip they aren't.... You HAVE to turn them off... I have been stung too many time with this...

The ADC module is turned off at reset (ADCONx). It's the Analog Select Register (ANSELx) that set the I/O port pins to analog input, disabling the digital I/O buffer on reset.
 
All academic as we dont know the pic... Not all pics have ansel registers... The original pic's were all enabled... the newer ones have the ansel registers on o boot... either way you need to disable them..
 
Regardless of the legacy version or newer, the ADC itself is always turned off on reset. On legacy processors, analog/digital mode was selected by writing a value from 0-F to the LSB's of the ADCON1 register. ADCON0 contains the ADC On/Off bit, which is always a 0 on reset.

Either way, it all has to do with the pin mode selection.
 
If the processor has an ADC then you have to disable it!! Which processor are you using??
Thanks for that suggestion, it fixed the issue.

I'm using a 16F628A. I had forgotten that it has analogue inputs as it is a long time since I last used one

Thanks to the others who responded.
 
Ian!!! I know what you're saying but you're wording it incorrectly.

While there are multiple ADC "channels", there is only one ADC "module".

The ADC "module" is OFF on reset. That bit resides in ADCON0.

The pins that are multiplexed with ADC "inputs", however, are set to "analog" mode on reset. It is this setting that ADCON1 controls and must be configured for digital I/O in the initialization routine.

That said...we're dealing with a 16F628A. This one requires the value of 0x07 to be written to CMCON to disable the on-chip comparator. I usually write these two instructions first before anything else when coding F628A.
 
Ok!..... The pins on powerup are connected through to the ADC module.... You are right, but what I'm insinuating is the pins are "ADC" ready on power up...

Like you said, it's the comparator..

Any way... I read this..
Using MPLAB SIM, I cannot see any change to PORTA in the Watch Window when I attempt to simulate an output change.
And as the comparator doesn't control all of port a I assumed ADC...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top