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.
Thanks, I think it's the compiler, the AD program was fine on yours, yet it didn't register on mine. Now this definitely seem to indicate a problem with either the compiler or the programmer.
 
Works as expected. PortB toggles between $3f and $00 (bits 6 and 7 are PGD and PGC, so they can't be written while attached to the debugger).

You're obviously not using the debugger correctly.

List in detail how you're using it, from assembling the program to when you step through the program.
 
Last edited:
Thanks, I think it's the compiler, the AD program was fine on yours, yet it didn't register on mine. Now this definitely seem to indicate a problem with either the compiler or the programmer.
I use the exact same assembler as you (MPASM in MPLAB). Same programmer too, I think (PICkit 2 or Junebug?), not that that would make any difference.

Do you assemble the program and reprogram the chip in debug mode from the Debugger menu before stepping through it? If you don't, it won't work properly.
 
Last edited:
I put the switch to tutor, then assemble the program, then establish contact, then download the program. Then go into debugger, start "animation" start "view" special function registries, the registries vary when it goes through the animation, STATUS, and ADCON0 toggle the GO bit...

OK I restarted MPLAB, and now the PORTB toggles... but the LEDs don't light up.

OK the LEDS are on PortA, so I changed it, and it still doesn't light up.


Baby steps are frustrating... and the registry doesn't change either.

From the debugger menu.... NO I assemble from the top of the page.
 
Last edited:
When I look at the disassembly, I see that TRISA is given the address 0x05, instead of 0x85. Maybe that's the problem.

Code:
   000    1683     BSF 0x3, 0x5                   9:     	banksel	TRISA
   002    3000     MOVLW 0                        10:    	movlw	0x00
   003    0085     MOVWF 0x5                      11:    	movwf	TRISA
   004    1283     BCF 0x3, 0x5                   12:    	banksel	PORTA
                                                  13:    
                                                  14:    start
   006    30FF     MOVLW 0xff                     15:    	movlw	B'11111111'
   007    0085     MOVWF 0x5                      16:    	movwf	PORTA
                                                  17:    	
   008    200D     CALL 0xd                       18:    	call delay 
                                                  19:    	
   009    3000     MOVLW 0                        20:    	movlw	B'00000000'
   00A    0085     MOVWF 0x5                      21:    	movwf	PORTA
                                                  22:    	
   00B    200D     CALL 0xd                       23:    	call 	delay	
   00C    2806     GOTO 0x6                       24:    	goto 	start
                                                  25:    
                                                  26:    delay
   00D    3006     MOVLW 0x6                      27:    	movlw	B'00000110'
   00E    00A0     MOVWF 0x20                     28:    	movwf	count		;set count register
                                                  29:    loop
   00F    0BA0     DECFSZ 0x20, F                 30:    	decfsz	count,F		;count 6 tocks
   010    280F     GOTO 0xf                       31:    	goto	loop
   011    0008     RETURN                         32:    	return
 
Last edited:
I used the BSF status,5 command to change banks, and the registers now follow correctly. Seems I can't be using bankselect command.

Let's see if that does it on further experiments.

Thanks FUTZ for your patience....
 
but the LEDs don't light up.

OK the LEDS are on PortA, so I changed it, and it still doesn't light up.
You understand that the Firefly's LEDs are charlieplexed, right? They won't work properly if you don't understand that part. Look closely at the schematic. RA0, RA6 and RA7 as well as their TRIS bits must be toggled correctly to get the LEDs you want lit up.
 
I get a stack overflow error... ?!?!

I got the LEDs to light up with bsf PORTA,6
 
Last edited:
And instead of getting 11111111 on PORTA, I get 11010000 ...?

on the toggle, I programmed 11111111, yet the register toggles between 00000000 and 11010000.... how is that?
 
Last edited:
Same as before... with a different delay routine.
I put a 2 tocks delay in the routine so it goes through the debugger quickly. For a 1 second delay it's 200 tocks in both timers.

Code:
	list	p=16F88
	include <p16f88.inc>
	__config _CONFIG1, _WDT_OFF & _INTRC_IO & _MCLR_ON & _LVP_OFF

cblock	0x20
	count
	TIMER1
	TIMER2
	endc

	bsf     STATUS,5
	movlw	0x00
	movwf	TRISA
	bcf		STATUS,5
	clrw

start
	movlw	B'11111111'
	movwf	PORTA
		

	call delay 
	
	movlw	0x00
	movwf	PORTA
	
	
	call 	delay	
	goto 	start

delay
	MOVLW   D'2'          
    MOVWF   TIMER1          
               
DELAY2
	MOVLW	D'2'			
	MOVWF	TIMER2
	DECFSZ  TIMER2,F        
	GOTO    $-1             
               
	DECFSZ	TIMER1,F		
	GOTO	DELAY2				
	RETLW   0			


	end
 
Last edited:
I've been on this all day... :eek:
Fun, huh? :D

Your problem was that you forgot to configure your PortA pins as all digital. Add this while you're switched to bank 1:
Code:
	clrf	ANSEL
Bit-5 still isn't switching. I have to refresh my foggy memory on why exactly. But your main problem was forgetting that on reset all PortA bits are configured as analog by default.

EDIT: Well duh! Bit-5 is MCLR. As long as the debugger is in control, that can't be played with.
 
Last edited:
OK That works... the register toggles between 11011111 and 00000000.

I'll try to get all my working registers to toggle so I know they work.

Then back to the AD converter, why is the ADRESH/L not getting any values.... that's going to be tomorrow though, I've had enough for today.
 
Last edited:
Baby steps can be very frustrating....
I'm sorry to put you through this... ;)
Everybody goes through this stage where everything is confusing. And it always seems like it must be the tools at fault. It isn't. It's you. :D It really is! MPLAB is remarkably bug free. There are some, but you haven't seen them yet.

Keep at it and you'll be up to speed in no time. And all this confusion will disappear. Then you can finally get some cool things done.

You learned some good lessons today though... Practice, practice, practice. It gets easier with more practice. You can only learn to program by writing programs. Lots and lots of programs! Even if they're crap, you need to practice to get better at it. Reading books won't help unless you write tons of programs while reading.
 
I think I have to set ANSEL correctly for AD to work... !

ANSEL 00001000

Yes, I know it's me... :eek: I have to keep plugging at it, and I can only thank you for your patience futz, I do need someone to help me through my baby steps. ANd that's why I write these baby step programs like flashing a LED and turning on registers. I intend to do a lot of cool things with this newfound hobby, maybe even quit trucking and get into this as a way to make money. I do have a couple of projects to do and customers waiting for me to deliver, so I have no choice but to forge ahead.
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top