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.

MPLAB 8.0 and PICkit2 incompatability???

Status
Not open for further replies.

grim

New Member
MPLAB 8.0 and PICkit2 incompatability??? SOLVED

to save you reading it all, it's a known issue, nothing to do with the code, MPLAB forcess the VPP hi, so the button doesn't work



I dabbled with microcontrollers a while back. then it got warm and i went outside. I forgot everything, and as the long evenings draw back in I am dabbling again........:D

Microchips PICkit 2 comes with a number of lessons, which start with a 'hello world' and progress through to ADC and other functions.

This program strobes four led, with speed controlled by the on board pot and ADC and the direction set by a push button.

Code:
; PICkit 2 Lesson 7 - Reversible LEDs
;
; This shows how to read the A2D converter and display the
; High order parts on the 4 bit LED display.
; The pot on the Low Pin Count Demo board varies the voltage 
; coming in on in A0.
;
; Also the switch is used to reverse the direction of rotation
;
; The A2D is referenced to the same Vdd as the device, which 
; is provided by the USB cable and nominally is 5V.  The A2D
; returns the ratio of the voltage on Pin RA0 to 5V.  The A2D
; has a resolution of 10 bits, with 1023 representing 5V and
; 0 representing 0V.

#include <p16F690.inc>
	__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

	cblock	0x20
Delay1		; Assign an address to label Delay1
Delay2
Display		; define a variable to hold the diplay
Direction
LookingFor
	endc

	
	org 0
Start
	bsf	STATUS,RP0	; select Register Page 1
	movlw	0xFF
	movwf	TRISA		; Make PortA all input
	clrf	TRISC		; Make PortC all output
	movlw	0x10		; A2D Clock Fosc/8
	movwf	ADCON1
;	bcf	STATUS,RP0	; back to Register Page 0

	bcf	STATUS,RP0	; address Register Page 2
	bsf	STATUS,RP1	
	movlw	0xF7		; we want all Port A pins Analog, except RA3
	movwf	ANSEL
	bcf	STATUS,RP0	; address Register Page 0
	bcf	STATUS,RP1
	
	movlw	0x01
	movwf	ADCON0		; configure A2D for Channel 0 (RA0), Left justified, and turn on the A2D module
	movlw	0x08
	movwf	Display
	clrf	Direction
	clrf	LookingFor	; Looking for a 0 on the button
MainLoop
	movf	Display,w	; Copy the display to the LEDs
	movwf	PORTC
	nop			; wait 5uS for A2D amp to settle and capacitor to charge.
	nop			; wait 1uS
	nop			; wait 1uS
	nop			; wait 1uS
	nop			; wait 1uS
	bsf	ADCON0,GO	; start conversion
	btfss	ADCON0,GO	; this bit will change to zero when the conversion is complete
	goto	$-1
	movf	ADRESH,w	; Copy the display to the LEDs
	movwf	Delay2

A2DDelayLoop
	incfsz	Delay1,f	; Waste time.  
	goto	A2DDelayLoop	; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
	incfsz	Delay2,f	; The outer loop takes and additional 3 instructions per lap * 256 loops
	goto	A2DDelayLoop	; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
				; call it a two-tenths of a second.

	movlw	.13		; Delay another 10mS plus whatever was above
	movwf	Delay2
TenmSdelay	
	decfsz	Delay1,f
	goto	TenmSdelay
	decfsz	Delay2,f
	goto	TenmSdelay

	btfsc	LookingFor,0
	goto	LookingFor1
LookingFor0
	btfsc	PORTA,3		; is the switch pressed (0)
	goto	Rotate
	bsf	LookingFor,0	; yes  Next we'll be looking for a 1
	movlw	0xFF		; load the W register incase we need it
	xorwf	Direction,f	; yes, flip the direction bit
	goto	Rotate

LookingFor1
	btfsc	PORTA,3		; is the switch pressed (0)
	bcf	LookingFor,0
	
Rotate
	bcf	STATUS,C	; ensure the carry bit is clear
	btfss	Direction,0
	goto	RotateLeft
RotateRight
	rrf	Display,f
	btfsc	STATUS,C	; Did the bit rotate into the carry?
	bsf	Display,3	; yes, put it into bit 3.

	goto	MainLoop
RotateLeft
	rlf	Display,f
	btfsc	Display,4	; did it rotate out of the display
	bsf	Display,0	; yes, put it into bit 0
	goto	MainLoop
	
	end

it complies ok in mplab, and will download to the chip, and runs.

EXCEPT the mplab version looses the push button functionality. nothing happens at all:( lights just strobe in one direction. adc speed change is working

apart from donloading an earlier version of mplab, and comments?
 
Last edited:
yes, exactly. both compiled from the same asm file

so either the 'looking for' part isn't seeing the button press, or the reversing part isn't working.

I suppose that should be my starting point. cerate a delay of a few seconds and call it from various places in the program to see where it goes, or doesn't
 
I have tried changing MCLR from hi to low. with the program running, clicking on that changes the direction sometimes, but the button still doesn't.

however I have carried on the experiment. quitting MPLAB, and starting up PICKit 2 sotfware and turning on the kit. so its running the program downloaded by MPLAB, but now being powered by PICkit2

and the MCLR function on the pickit2 software sorts it out. clicking it on and off gives the same fairly random change of direction, but with it off the button works perfectly, and with it on, it doesn't work at all.

so, you were right, it was the MCLR function - for soem reason although it seems to do something in MPLAB when i click it (because it sometimes changes the direction) it obviously doesn't work properly


which sounds like a bug.:(

addendum
RA3 is the MCLR pin, it also happens to be the pin that the reversing switch is using.

when powered by the pickit2 software RA3 is at 5v until i press the button, when it is then pulled low. setting MCLR low, means it can't pull it down, so the button stops functioning.

powered by MPLAB, the voltage on RA3 does change from 5v to 0 when i set or clear MCLR

the difference is though, that when it is powered by MPLAB, the push button is only able to pull RA3 down to 4.6v, not zero.
 
Last edited:
MPLAB holds MCLR low after you program the PIC. You have to manually release it from reset (There was a post on the 13/11/07 about this).

The switch on your demo board connects to RA3 which is the MCLR input on the PIC. The config word in your .ASM file is setting the RA3 pin to function as an input but it is still connected to the programmer.

When you press the switch it pulls RA3 low, when you release it RA3 is pulled up via a 10K resistor (from the schematic in the user manual)

If the programmer (MPLAB) holds MCLR low it is the same as pressing and holding SW1 on the demo board. If you tell MPLAB to release from reset, the switch should work as expected.

From the extra info you added after I replied.

Looking at the schematic for the PICkit 2 programmer, it looks as though when you tell MPLAB to 'release from reset', it's not just releasing the MCLR line, it's actively pulling it high through L1/D3/Q6

I guess it's one of those 'function as designed' issues.
 
Last edited:
Hi Geko, I guess you were posting as I was editing. ;)

the issue seems to be a different source impedance on the MCLR pin of the programmer, depending on weather it's powered by the pickit or mplab. when using mplab, the button cannot pull RA3 down, so i guess it's being driven direct from a chip, but the pickit2 drives it via a hi resistance (100k or so)
 
dohh. i need a rethink
 
Last edited:
I've kind of given up on using MPLAB to do the programming now I've got a Junebug PICkit2 compatible programmer. I use the PICkit app to program the PIC and MPLAB to develop the code.

The PICkit2 application is smart enough to reload the current HEX file each time you select 'write' to the PIC so it's not really much of an issue to have both MPLAB and PICkit2 applications open.
 
I use MPLAB 8.0 with my Junebug (PICkit 2) and it programs/debugs fine, not sure why you're using the PK2 software at the same time?

The Junebugs tutor does not support VPP before VDD but the external ICD does, so it's possible to use reset RA5 on the 18F1320 as an input switch but you may have to move it to an external adapter to reflash it if you decide to test this feature.

PS I've found out from the Microchip forums not to use the DEBUG_ON config statement as MPLAB sets it when needed automatically.
 
Hi Bill

I used the pickit2 software, and ran all the demos. Then I started playing with MPLAB and started fiddling with the existing programs, that was when I discovered that this one doesn't work under MPLAB - going back to pickit2 software it does

It appears that when pickit2 software controls the pickit2 hardware, the VPP/MCLR pin floats/hovers/whatever at 5v, and can be pulled down by the button. When MPLAB controls the pickit2 hardware, VPP/MCLR is driven to 5v, and cannot be pulled down by the button.

I will now put my pickit2 back together, shrug, and try to get on with life.


funny, I have probably learnt more today from something that didn't work, than I would if it had. They don't make it easy for us beginners though :rolleyes:
 
**broken link removed**

item F
 
I use MPLAB 8.0 with my Junebug (PICkit 2) and it programs/debugs fine, not sure why you're using the PK2 software at the same time?

Well I have two monitors on my PC so I can have both apps side by side. Do a quickbuild in MPLAB, then click write in PK2 app and off it goes + it doesn't hold the target in reset like MPLAB does either.
 
on the microchip forum they say to power the board from pickit2 because of this issue
 
nice to figure it out though ;)
 
Sounds like a VPP before VDD issue. If you use MCLR as a input pin you have to be able to control your targets power (VDD) to reprogram it.
 
the programming wasn't the issue, it was the fact that mplab holds VPP at 5v, where as pickit2 'guides' it there, but allows you to pull it down
 
For the simple reason that the Red Push button on my PICkit2 does not have any insignia, I do not use it. Its best not touch unidentified things. That fact is if they meant for that button to be used effectively, it would have been very clearly written in silk screen just like the other holes in the plastic case.

Tip, keep the Programmer tool box real close to Output window as I do.
 

Attachments

  • quicky.jpg
    quicky.jpg
    51.7 KB · Views: 175
Status
Not open for further replies.

Latest threads

Back
Top