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.
Hi Robert.
If you want to look at the ADRESH or L registers (or any other) when debugging use the "Watch" window. In MPLAB, click on "View" >> "Watch" and then add the registers you want to look at.... this has been said before, but from one of your posts after that it still looks like you use the Special Function register window.
 
but from one of your posts after that it still looks like you use the Special Function register window.
Is that what he was looking at?!? :eek: I didn't catch that. No wonder there was so much confusion! :p I clearly said "watching (in the Watch list)" and "Open a Watch window.", but I could imagine someone not taking me literally and thinking I meant the SFR window, I guess...
 
Last edited:
I did that, and the ADRESH, ASRESL in the watch window did not change from 00 when I pressed animate. All the other registers changed, but not these.

I just came back from work, and I'll have supper, then I'll get back into it around 7 or so. I think I'll try to run what worked before, then go into tables, and see if I can program a table to read from the switches. I'll get back into AD later. Futz said my program worked on his computer, so I assume it is right, so I'll pick it up from there.
 
OK I'm back, I started MPLAB and ran the AD again, and got this message:

ADC-W0001: Tad time is less than 1.60us
ADC-W0008: No stimulus file attached to ADRESL for A/D.


So I increased the acquisition time to 20 tocks, but I don't understand what stimulus file is supposed to be attached to ADRESL. Now I'll run it with the new Tacq time and see what happens.
 
OK I'm back, I started MPLAB and ran the AD again, and got this message:

ADC-W0001: Tad time is less than 1.60us
ADC-W0008: No stimulus file attached to ADRESL for A/D.


So I increased the acquisition time to 20 tocks, but I don't understand what stimulus file is supposed to be attached to ADRESL. Now I'll run it with the new Tacq time and see what happens.
If it wants a stimulus file you're probably in the simulator, rather than the debugger. And without a stimulus file you'll never see ADRESH/L change. Ever.

A stimulus file is just fake input data for various inputs, like A/D. You use it in the simulator because there's no actual MCU there providing the real data, so you simulate it with a stimulus file. You use it so you can see how your program would respond if the input data was what's in the stimulus file parameters.

Perhaps you've been using the sim all along and thinking it was the debugger? That would be funny!
 
Last edited:
Aaaah.... :) OK...!

It works... :)

Well I got two values in ADRESH/L and it doesn't seem to want to change when I move the pot. It just stays there, with all the LEDs lit up on the firefly.
 
Last edited:
Well I got two values in ADRESH/L and it doesn't seem to want to change when I move the pot. It just stays there, with all the LEDs lit up on the firefly.
Then you're doing it wrong! :D :p

Let me go through this step by step:
1. I start with this source file in my project
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'00001000'	;MAKE RA3 INPUT
	movwf	TRISA
	movwf	ANSEL		;MAKE RA3 ANALOG INPUT
	movlw	B'10000000'
	movwf	ADCON1		;set right justified
	banksel	ADCON0		;bank 0
	movlw	B'01011001'
	movwf	ADCON0		;enable A/D
	movlw	0x06
	movwf	count		;set count register

loop	decfsz	count,F		;count 6 tocks
	goto	loop
	bsf	ADCON0,GO	;capture A/D
	btfsc	ADCON0,GO
	goto	$-1		;waiting for A/D to finish
	goto	loop

	end
Screen looks like this
bleh.jpg
My Firefly dip switch is set to 010111
The PICkit 2 is plugged into the Firefly and connected. Powering from PICkit 2.

2. I click on Debugger/Select Tool and select PICkit 2. The PICkit 2 connects.

3. I hit F10 to assemble the file and wait for it to be done. When it reports BUILD SUCCEEDED I continue.

4. I hit ALT-D and then the G key to program the PIC on the Firefly with the assembled program (executable) and the debug monitor.

5. If I didn't already have one up, I'd now open a Watch window by clicking View/Watch. Then I'd get ADRESH and ADRESL displayed in there.

6. Now I put the cursor on " goto loop", right-click and select "Run To Cursor". Wait a bit. Look at ADRESH/L.

7. Turn the VR2 pot a little and goto step 6. Repeat as necessary. ADRESH/L change as expected. Fully clockwise is $03ff and fully counter-clockwise is $0000.
 
Last edited:
I do all that, but the MPLAB is very slow, and it is stuck on:

btfsc ADCON0,GO

And I only get two reading on the ADRESH/L that is 0x08, and 0x40. And I don't get anything else....


Mind you, it's a big step from nothing before... Just have to find out why it's so slow.
 
Mind you, it's a big step from nothing before... Just have to find out why it's so slow.
Relax and wait a bit. It is slow. I don't know the reasons, but other chips I've debugged aren't as slow as this F88.

If you've moved the pot before hitting Run To Cursor, you should wait until the ADRESH/L values go red, meaning the debugger has finished Running To Cursor and has updated the register values in the Watch list. At that point the Output window will display "Target Halted" as well.

BTW: If you just hit Run in the debugger, your Watch window values will not update until the program is Halted, or hits a breakpoint. They will be updated in Animate though. But Animate can be very slow for some things.
 
Last edited:
As slow as ten minutes?
Something wrong there. :p Should take 5 or 6 seconds.

Go through my step-by-step again in detail. Don't add or skip anything. Leave that Firefly dip switch alone!

What version of MPLAB you using?

What does your Output window say when you hit ALT-D and then C?

You say you have all LEDs lit on the Firefly? I don't. With the above program I get #1 Red and #2 Green and #3 Off. Sure you have your project set up right? The Project window should have the correct source file listed. If you have the wrong one in there it doesn't matter what's on the screen. It assembles the one listed there anyway and if the one on screen is different it gets ignored. I've made that mistake and spent 20 minutes cursing as it assembled a the wrong program over and over, ignoring my frantic changes to the onscreen source.
 
Last edited:
OK I got the switches at 010111, I went through the process step by step, and I have the pot all the way up almost, and it's running

Three of them go red, but ADRESH/L stay black
 
If, after selecting PicKit2, you go to Debugger->Settings, you can select "Program after successful build" and "Run after a successful program" options. Your code will automatically program and run when you hit F10.

Mike.
 
OK I got the switches at 010111, I went through the process step by step, and I have the pot all the way up almost, and it's running

Three of them go red, but ADRESH/L stay black
Either you're still doing it wrong, or your Firefly has a hardware problem. Did you assemble yourself?

Switch to VR1. Both of them can't be bad. :p You'll have to modify your code and change the dip switch to 100111.

Three of them go red, but ADRESH/L stay black
They won't go red if there is no change. Black means no change. Move that pot every time you Run To Cursor.

Oh ya, hit F5 (refresh) often when reading my posts. I edit a LOT. If you don't, you'll miss things. :D
 
Last edited:
OK will try to go to RA1

No I bought it assembled...

LEDs 1+2 are on,

I did measure the voltage on pin RA3 and it reads OK, so there is input.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top