Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 1st July 2009, 01:28 AM   #1
Thumbs down Bizarre problem with Junebug LEDs

Here's the code I'm running
Code:
list p=18F1320
include <p18F1320.inc>
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

org 0x000			; RESET vector
; INIT
INIT 	movlw b'01111110'
		movwf TRISA
		movlw b'00000001'
		movwf PORTA
		movlw b'11000000'
		movwf TRISB
		movlw b'11111111'
		movwf PORTB			; Set pullups

; MAIN
MAIN	
		btfsc PORTB,RB2 ; Test button 2
		goto MAIN
		movlw b'10000000' ; Once it's been pressed switch the led and leave it
		movwf PORTA
		goto MAIN

END
it was working fine, but I changed it to use the other button (RB5). Then instead of lighting LED6 it would light LED 1 and 3, LED 6 would flicker a bit, then after about 20 seconds it would switch, 1 and 3 would go out then 6 would go on. It still responded to button presses as expected. Switching back to RB2 the problem remained.

Does anyone have any idea what's going on? Looking at the diagram I understand why 1 and 6 are on.. if RA6 is disconnected, 1 is on and 7 is off, I would expect 1, 3 AND 6 to go off, and clearly it's something to do with those three. What am I missing?

Thanks
Gfaja is offline  
Old 1st July 2009, 01:44 AM   #2
Default

Try this:
Code:
list p=18F1320
include <p18F1320.inc>
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

org 0x000			; RESET vector

INIT 	
	movlw b'01111110'
	movwf TRISA

	movlw b'00000001'
	movwf PORTA

	movlw b'00100101'    ;Proper port tris setup now (1 = input)
	movwf TRISB
	
	movlw    0x80        
	movwf    INTCON2     ; Set pullups
	movlw    0x7F
	movwf    ADCON1      ; Set to all digital 

MAIN	
    btfsc PORTB,RB2 ; Test button 2
    goto MAIN
    movlw b'10000000' ; Once it's been pressed switch the led and leave it
    movwf PORTA
    goto MAIN

END
Info in datasheet:



Using the above note from datasheet you can see to enable pullups:
Code:
	movlw    0x80        
	movwf    INTCON2     ; Set pullups
OR
Code:
	bsf    INTCON2,RBPU     ; Set pullups
And since RB4:RB0 are auto set to ANALOG on startup it will always read as a 0 until you set it as digital:
In datasheet and junebug manual:
RB0 = SW1
RB2 = SW2
RB5 = SW3
Now to figure how to set ADCON1 you have to find this:

I edited the image so you can see how the registers line up so you can see which PortB pins have what name in ADCON1 register. So you can then:
Code:
	movlw    0x7F
	movwf    ADCON1      ; Set to all digital
or just set the ones you need RB0, RB2, RB5:
Code:
	movlw    b'00100101'
	movwf    ADCON1      ; Set RB0, RB2, RB5 digital for button input.
Attached Thumbnails
Bizarre problem with Junebug LEDs-pullup.jpg  

Last edited by AtomSoft; 1st July 2009 at 02:06 AM.
AtomSoft is online now  
Old 1st July 2009, 06:39 PM   #3
Default

Ahh shit.. I even read up on adcon, but I guess I was too used to my arduino.
Why is it adcon1, and not just adcon?

And thirdly.. New code makes perfect sense, except why aren't we setting bit 7 in adcon1?

And finally.. I'm still not exactly sure why the junebug was acting like it was.. it still doesn't really make sense to me and the inconsistency is the weirdest. What does writing to an input pin do?

Thanks
Gfaja is offline  
Old 1st July 2009, 06:42 PM   #4
Default

Most PIC registers are named so to be consistant across the family line.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 1st July 2009, 06:58 PM   #5
Default

Quote:
Originally Posted by Gfaja View Post
Ahh shit.. I even read up on adcon, but I guess I was too used to my arduino.
Why is it adcon1, and not just adcon?

And thirdly.. New code makes perfect sense, except why aren't we setting bit 7 in adcon1?

And finally.. I'm still not exactly sure why the junebug was acting like it was.. it still doesn't really make sense to me and the inconsistency is the weirdest. What does writing to an input pin do?

Thanks
Why is it adcon1, and not just adcon?
From the datasheet section 17:
17.0 10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE

Quote:
The ADCON0 register, shown in Register 17-1,
controls the operation of the A/D module. The
ADCON1 register, shown in Register 17-2, configures
the functions of the port pins. The ADCON2 register,
shown in Register 17-3, configures the A/D clock
source, programmed acquisition time and justification.
So basically it is the registers name.

ADCON has to do with the Analog to Digital Conversion(ADC). And selecting which pin to read.

ADCON1 has to do with setting the PINs to Digital or ANALOG.

ADCON2 has to do with the timing of the ADC.

Why not set bit 7 of ADCON1:
because this is its purpose: "Unimplemented: Read as ‘0’"

It has no use. Its not used.


Writing to a INPUT pin: i have no clue what would happen... i assume nothing

arduino is more of a shortcut thing i think. You miss out on a lot i suppose. Like the basic stamp. You never get full control. Like of every register. Of course its harder this way but way more satisfying and precise.

Last edited by AtomSoft; 1st July 2009 at 07:01 PM.
AtomSoft is online now  
Old 2nd July 2009, 06:45 AM   #6
Default

Yeah I'm using the arduino for simple robotics and stuff but using pics for smaller more integrated things as well as to make something w/out feeling like I cheated. Arduinos are TOO easy.
Gfaja is offline  
Old 9th July 2009, 04:24 AM   #7
Default

Hm now it started randomy switching to LED 5 immediately after starting up now, when it should be LED 6 until I hit the button

Code:
; *** Junebug 18F1320 LED sequencer demo ***
; Flashes LEDs1 thru 6 from left to right forever
; DIP Switch (SW6) must have TUTOR on (SW6-1,2,3) all other switches off
list p=18F1320
include <p18F1320.inc>
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF

org 0x000			; RESET vector
; INIT
INIT	movlw b'01111110'
		movwf TRISA
		
		movlw b'00000001'
		movwf PORTA		

		movlw b'00100101'
		movwf TRISB

		bsf   INTCON2,RBPU     ; Set pullups

		movlw 0x7F
		movwf ADCON1      ; Set to all digital 


; MAIN
MAIN	
		btfss PORTB,RB2
		goto MAIN
		movlw b'10000000'
		movwf PORTA
		goto MAIN

END
Gfaja is offline  
Old 19th July 2009, 10:00 PM   #8
Default

Have to bump this.

Haven't touched my junebug in a while, so it's running the code in the above post.
It won't connect anymore, resetting gets the right LED lit but plugging it in make it quickly switch to what should be lit only after pressing the button. Program also completely ignores button presses. Maybe I screwed up soldering in.

Video is posted and pictures of my soldering job. Any ideas what I could have done wrong?
Video
1
2
3
Video 2

Last edited by Gfaja; 19th July 2009 at 10:16 PM.
Gfaja is offline  
Old 20th July 2009, 04:42 AM   #9
Default

For self running turn off DIP1-1.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 20th July 2009, 02:04 PM   #10
Default

The video shows that his Junebug will not connect to MPLAB.
Try reloading the firmware using the bootstrap loader button (small button near the 18F2550).

I have to run... will finish this latter.
3v0
__________________
Please post questions to the forums. PM's are for personal communication.

BCHS/3v0's Tutorials
Junebug USB PIC programmer kit., USB Bit Whacker,
The 15 Minute Printed Circuit Board! (+drill time)
3v0 is online now  
Old 20th July 2009, 03:01 PM   #11
Default

No luck with either. Got "Usb device not recognized" bubble in xp
Gfaja is offline  
Old 20th July 2009, 05:04 PM   #12
Default

Hold down the pushbutton while plugging in the USB. Does the red busy LED flash?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 21st July 2009, 01:19 AM   #13
Default

Nope. Yellow is dimly lit. Now I consistently get the USB not recognized message when plugging it in.
Gfaja is offline  
Old 21st July 2009, 02:01 AM   #14
Default

Hmm remove the 18F2550. Is there a color dot painted on the bottom?

A programmed Junebug only needs power & a working crystal (plus the pushbutton) to get the LED flashing.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 21st July 2009, 03:05 AM   #15
Default

sigh.... the chip was barely in the socket..
one of the indents is white?

put it back in and it flashed red and is updating its software right now. yellow is off.
Now have it running, but still have it so LED 5 is light a split second after LED 6 as if I had hit the button. That or it switches randomly/not when I press the switch. So basically the videos are still accurate other than the programming problem. Any ideas?
Gfaja is offline  
Reply

Tags
junebug, led, pic

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Junebug Problem 3v0 Micro Controllers 29 14th January 2009 09:16 AM
Problem with junebug and mplab 8.10 jerryf Micro Controllers 12 1st December 2008 01:48 PM
Problem with junebug jerryf Micro Controllers 6 30th November 2008 04:44 PM
Junebug INT2 problem futz Micro Controllers 9 15th November 2007 03:32 AM
Junebug tutor LEDs futz Micro Controllers 5 11th November 2007 05:24 AM



All times are GMT. The time now is 12:21 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker