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.

Program to read A/D on firefly...

Status
Not open for further replies.
OK will try to go to RA1

No I bought it assembled...
You must not have work tomorrow! 3:00AM in Brampton land. I gotta go sleep soon. Must slave away tomorrow.

Send me your VR1 code to test. If it works for me and not for you then we will have confirmed that your problem is not likely hardware. Probably user error. :D

Is the 16F88 the right way around in the socket? :p Seated fully? Grasping at straws...
 
Last edited:
I just dug out my FireFly and tried the code and it works as expected.

BTW, the reason the debugging is so slow is because the 88 is running at 32k. If you add,
Code:
	bsf	STATUS,RP0
	movlw	0x70
	movwf	OSCCON
	bcf	STATUS,RP0
to your start up code it runs much faster.

Mike.
 
If it helps, this is how my MPLAB window looked. I added a label "Again" so count got reloaded and put a breakpoint on that line. Pressing F9 makes it execute the look again.

**broken link removed**

Mike.
 
Last edited:
Hi there, just finished work, get right back into the firefly. I really have to get this thing to read. So I added the 4 lines OSCCON and it does run faster, but I still don't get any reading on the ADRESH/L when I run to cursor from goto loop

I'm so glad to hear that my code works fine for you guys. Maybe the other dip switches make a difference, I have junebug connected to Firefly, and the junebug dips are setup 00011111 this way. The firefly dips are 010111. I'm still running on RA3 since it works for you, so there is nothing wrong with the code, and I have 4.3v on the pot and on the pin, so the ADRESH/L should be somewhere around 3f or so. I have zero, nothing moving.

It hangs on: btfsc ADCON0,GO ;conversion done?

The animate just hangs there and doesn't go anywhere... like the GO bit doesn't clear.

You mentionned something about the MPLAB running another program than the one I'm compiling is that a possibility?
 
Last edited:
I also would like to point out that the junebug has yellow and red LED on all the time. The firefly has the green LED on at the end of the ZIF socket. So I'll try to reprogram for the RA1 and see what happens.
 
In the Debugger menu, did you select PICKIT2?
In the Programmer menu, "None" should be selected.

Run your program for 10 seconds, pause it and check the registers.
Press play again, and pause it after 10 seconds. Do the readings change?

Can you make a print screen of your MPLAB screen and attach it, maybe someone can spot something. Can you also attach a pic of the dip switches on your hardware?
 
Last edited:
OK I changed the code to RA1, and PORTA reads 00001000, if that means anything. I changed ADCON0 to B'10001001', and I ran to cursor, with... nothing still.


Yes debugger is on PICKIT2, and none for programmer. And when I run the program with view registers, they change when the animate is going through the paces.

Hey I just got a message saying : "unable to enter debug mode." That's got to be what the problem is.

Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON &  _LVP_OFF

	count	equ		0x22

		bsf		STATUS,5 
		movlw 	B'00000010'
		movwf 	TRISA ;all outputs except RA1
		movwf	ANSEL
		
		movlw 	0x2
		movwf 	ADCON1 
		bcf		STATUS,5
		
		movlw 	B'10001001'
		movwf 	ADCON0 ; channel 0, FOSC/8, enable A/D
		bsf	STATUS,RP0
		movlw	0x70
		movwf	OSCCON
		bcf	STATUS,RP0
		
		movlw 	0x06
		movwf 	count ;initialize count

	loop
		decfsz 	count,F 
		goto 	loop ;until finished

	
		bsf 	ADCON0,GO ;initiate conversion
	

	test
		btfsc 	ADCON0,GO ;conversion done?
		goto 	test ;not finished

		end
 
Last edited:
I tried play pause and the program just hangs there. The whole MPLAB is very slow when I start playing around with the animate and run to cursor, I often get Microsoft error messages when I try to close it. I'm relieved to know the program is running OK, at least I know the code is OK, so the problem has to be either firefly or MPLAB... or me, that's not properly setting up MPLAB, but after talking to you guys, and trying just about everything, I think there might be a problem with my computer, or something like that. I think I'll just let it sit for now, and work on getting a table to read and output correctly. That's the other half of the program I'm trying to set up.
 
I'm so glad to hear that my code works fine for you guys. Maybe the other dip switches make a difference, I have junebug connected to Firefly, and the junebug dips are setup 00011111 this way.
I unplugged the PICkit 2 and plugged in my Junebug. My Junebug dips are 00000000. Only the first three matter in this case though, so don't worry that yours is different.

The firefly dips are 010111.
Yup.

It hangs on: btfsc ADCON0,GO ;conversion done?

The animate just hangs there and doesn't go anywhere... like the GO bit doesn't clear.
Don't animate it. Use run to cursor (or do a breakpoint like Pommie suggested - same thing either way). Waiting for the GO bit to clear in animation can take a long time.

You mentioned something about the MPLAB running another program than the one I'm compiling is that a possibility?
Just double check that the Source File listed in the Project window is the same source file that you're looking at in the editor window.
 
I also would like to point out that the junebug has yellow and red LED on all the time. The firefly has the green LED on at the end of the ZIF socket. So I'll try to reprogram for the RA1 and see what happens.
Firefly LEDs - don't really care. They can turn blue for all I care, as they're not being used in this program.

Junebug should NOT have a red LED on though. You're talking about the green/yellow/red status LEDs up by the USB port? If you're seeing a red LED there, unplug your Junebug and replug it. Then hit ALT-D and C to get MPLAB to reconnect to it before trying again.

The green one should be on. That's the power LED.

The yellow one should be off unless you're powering your Firefly separately (not from the Junebug).
 
Hey I just got a message saying : "unable to enter debug mode." That's got to be what the problem is.
Na. The PICkit 2 does that occasionally. Just reset everything, as in, unplug the Junebug and replug it. Possibly restart MPLAB. Don't worry too much about it. It's just a bit of flakiness that happens once in a while with the software. Doesn't hurt a thing.
 
OK I changed the code to RA1, and PORTA reads 00001000, if that means anything. I changed ADCON0 to B'10001001', and I ran to cursor, with... nothing still.
Found some small problems with your source code. Here it is with everything fixed. I may have to repost to tell you exactly what I changed...

Runs perfect in the debugger. Gives correct results in the Watch window.
Code:
	LIST	p=16F88
	include "P16F88.inc"
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF
	ERRORLEVEL 0, -302

	cblock	0x20
	count
	endc

	banksel	TRISA 		;bank 1
	movlw 	B'00000010'
	movwf 	TRISA		;all outputs except RA1
	movwf	ANSEL
	movlw 	b'11000000'
	movwf 	ADCON1 
	banksel	PORTA		;bank 0
	movlw 	B'01001001'
	movwf 	ADCON0		; channel 0, FOSC/8, enable A/D
	bsf	STATUS,RP0
	movlw	0x70
	movwf	OSCCON
	bcf	STATUS,RP0
bleh	movlw 	0x06
	movwf 	count		;initialize count
loop	decfsz 	count,F 
	goto 	loop		;until finished
	bsf 	ADCON0,GO	;initiate conversion
test	btfsc 	ADCON0,GO	;conversion done?
	goto 	test		;not finished
	goto	bleh
	end

Here's what I changed:
1. I put "ERRORLEVEL 0, -302" so I don't have to see all those warnings.

2. I put a cblock for the variable instead of the EQU.

3. Used banksels cuz I like them better than that cryptic bsf status crap.

4. You had ADCON1 set wrong. "2" just won't do it. :p

4. I changed the aquisition time for 8MHz, though the program isn't running that fast. Now you can speed up the clock and it'll still work well

5. You had nothing at the bottom of the program to catch it from running away. I made it loop back to re-read the A/D.
 
Last edited:
I usually unplug and replug the junebug and press that little check connection button and poof it works.
I don't even see those buttons. :D I hit ALT-D and C in debug and in programming mode I hit ALT-G and C.

I have some carpal tunnel problems from way too long at this computing stuff, so I learn keyboard shortcuts for everything I can. The mouse is pure evil.
 
Status
Not open for further replies.

Latest threads

Back
Top