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.

My Junebug switches go high before I even press them. EMF?

Status
Not open for further replies.

Fordy

New Member
Spooky thing happened the other day. I was pretty tired, so I figured it was a coincidence. Kept trying over and over - same results. Tried again just now, same results.


I made a really simple program and flashed it to my Junebug's 18F1320, just to test this out.

The program has some LEDs on solid when input low, and on high they start flashing and the rest come on solid.



They start flashing when my finger approaches the switch.

Any of the switches. But they're brighter if it's the correct switch.


I tested this several times to make sure I wasn't seeing things. Then I noticed something even weirder:


If I actually press the switch, they all go off. Nothing in my program should cause that. Not even EMF would explain that as far as I'm aware.

Same results if I grounded myself (crudely, by holding a nearby PC). Same results with several different (but simple) programs.



Unless these are some funky type of switch I don't know about, I have no idea what's going on.


Grateful for any input.
 
Do you have a sufficient pull up/down on the switch? This should not occur if you do. You might want to debug your code, there could be an error in it somewhere that you're missing.
 
Last edited:
It might help to post your code and take a pic of your Junebug, showing the DIP switch settings.
 
It sounds to me like you don't have any pull-up/pull-down resistors. Depending on the application, 2.2K-10K pullup/down resistors are needed to hold it low or high until the switch is pressed/toggled. Otherwise, any electrostatic discharge, RF noise, EMF pulse, etc. is likely to set it off.
 
Spooky thing happened the other day. I was pretty tired, so I figured it was a coincidence. Kept trying over and over - same results. Tried again just now, same results.
I made a really simple program and flashed it to my Junebug's 18F1320, just to test this out.
The program has some LEDs on solid when input low, and on high they start flashing and the rest come on solid.
They start flashing when my finger approaches the switch.
Any of the switches. But they're brighter if it's the correct switch.
I tested this several times to make sure I wasn't seeing things. Then I noticed something even weirder
If I actually press the switch, they all go off. Nothing in my program should cause that. Not even EMF would explain that as far as I'm aware.
Same results if I grounded myself (crudely, by holding a nearby PC). Same results with several different (but simple) programs.
Unless these are some funky type of switch I don't know about, I have no idea what's going on.
Grateful for any input.

The schematic / manual for the Junebug is here: https://www.electro-tech-online.com/custompdfs/2011/12/bre-junebug-assembly-instructions.pdf
The switch inputs are on port B, and you should probably use the internal weak pull-ups and sense when the line goes low.
I wrote an asy program to flash the led's with the switches and it works fine, if I can find it I will post it for you.
Mike.
 
As already mentioned, you need to turn on the weak pull-ups.

You don't mention which language you are using, in C18 you need
Code:
    INTCON2bits.RBPU=0;         //enable port b weak pullups

Mike.
 
Ok, It's not pretty, but it works, wrote it a long time ago. Hope this helps..

;******************************************************************************
; This file is a basic template for creating relocatable assembly code for *
; a PIC18F1320. *
;******************************************************************************
; Files required: P18F1320.INC *
;******************************************************************************
LIST P=18F1320, F=INHX32 ;directive to define processor and file format
#include <P18F1320.INC> ;processor specific variable definitions
;******************************************************************************
;Configuration bits
;; Oscillator Selection:
CONFIG OSC=INTIO2,LVP=OFF,WDT=OFF
;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used.
; More variables may be needed to store other special function registers used
; in the interrupt routines.
;
UDATA
;
WREG_TEMP RES 1 ;variable in RAM for context saving
STATUS_TEMP RES 1 ;variable in RAM for context saving
BSR_TEMP RES 1 ;variable in RAM for context saving
;
UDATA_ACS
;
EXAMPLE RES 1 ;example of a variable in access RAM
;
;;
cblock 0x01
d1
d2
d3
endc
;;
;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

RESET_VECTOR CODE 0x0000

goto Main ;go to start of main code

;******************************************************************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.

HI_INT_VECTOR CODE 0x0008
bra HighInt ;go to high priority interrupt routine

;******************************************************************************
;Low priority interrupt vector
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.

LOW_INT_VECTOR CODE 0x0018
bra LowInt ;go to low priority interrupt routine

;******************************************************************************
;High priority interrupt routine
; The high priority interrupt code is placed here.

CODE
HighInt:
; *** high priority interrupt code goes here ***
retfie FAST
;******************************************************************************
;Low priority interrupt routine
; The low priority interrupt code is placed here.
; This code can be removed if low priority interrupts are not used.
LowInt:
movff STATUS,STATUS_TEMP ;save STATUS register
movff WREG,WREG_TEMP ;save working register
movff BSR,BSR_TEMP ;save BSR register
; *** low priority interrupt code goes here ***
movff BSR_TEMP,BSR ;restore BSR register
movff WREG_TEMP,WREG ;restore working register
movff STATUS_TEMP,STATUS ;restore STATUS register
retfie
;******************************************************************************
;Start of main program
;The main program code is placed here.

Main:
;
clrf LATB; clear output latch
movlw 0x7f
movwf ADCON1; set port b for digital inputs
bcf INTCON2, RBPU ; turn on soft pullups
;
;
BURP:
btfss PORTB, RB0; check for button #1 pressed
call BUTT1
btfss PORTB, RB2; check for button #2 pressed
call BUTT2
btfss PORTB, RB5; check for button #3 pressed
call BUTT3
;
goto BURP
;
L1:
LED1 bcf TRISA,0 ; RA0 output
bcf TRISA,6 ; RA6 output
bsf TRISA,7 ; RA7 tristate (open)
bsf LATA,0 ; RA6 High (5V)
bcf LATA,6 ; RA7 Low (GND)
call DubDelay
return
L2:
LED2 bcf TRISA,0 ; RA0 output
bcf TRISA,6 ; RA6 output
bsf TRISA,7 ; RA7 tristate (open)
bcf LATA,0 ; RA6 Low (GND)
bsf LATA,6 ; RA7 High (5V)
call DubDelay
return
L3:
LED3 bsf TRISA,0 ; RA0 tristate (open)
bcf TRISA,6 ; RA6 output
bcf TRISA,7 ; RA7 output
bsf LATA,6 ; RA6 High (5V)
bcf LATA,7 ; RA7 Low (GND)
call DubDelay
return
L4:
LED4 bsf TRISA,0 ; RA0 tristate (open)
bcf TRISA,6 ; RA6 output
bcf TRISA,7 ; RA7 output
bcf LATA,6 ; RA6 Low (GND)
bsf LATA,7 ; RA7 High (5V)
call DubDelay
return
L5:
LED5 bcf TRISA,0 ; RA0 output
bsf TRISA,6 ; RA6 tristate (open)
bcf TRISA,7 ; RA7 output
bcf LATA,0 ; RA0 Low (GND)
bsf LATA,7 ; RA7 High (5V)
call DubDelay
return
L6:
LED6 bcf TRISA,0 ; RA0 output
bsf TRISA,6 ; RA6 tristate (open)
bcf TRISA,7 ; RA7 output
bsf LATA,0 ; RA7 High (5V)
bcf LATA,7 ; RA6 Low (GND)
call DubDelay
;
return
;bra LED1 ; repeat
bra Main
;; END


;******************************************************************************
DubDelay
movlw 0xf0
movwf d1
movlw 0xf0
movwf d2
Del_1
decfsz d1, f
goto $+4
decfsz d2, f
goto Del_1
goto $+2
nop
return
;******************************************************************************
;******************************************************************************
;******************************************************************************
; Some test code
;
; clrf LATB; clear output latch
; movlw 0x7f
; movwf ADCON1; set port b for digital inputs

; btfss PORTB, RB0; check for button #1 pressed
; call BUTT1
; btfss PORTB, RB2; check for button #2 pressed
; call BUTT2
; btfss PORTB, RB5; check for button #3 pressed
; call BUTT3
;;
BUTT1
movlw 0x03
movwf d3
B11
call L1
call L2
call L3
call L4
call L5
call L6
decfsz d3, f
goto B11
bsf TRISA,0
bsf TRISA,6
bsf TRISA,7
return
BUTT2
movlw 0x03
movwf d3
B22
call L1
call L2
call L3
call L4
call L5
call L6
call L5
call L4
call L3
call L2
decfsz d3, f
goto B22
bsf TRISA,0
bsf TRISA,6
bsf TRISA,7
return
BUTT3
movlw 0x03
movwf d3
B33
call L3
call L4
decfsz d3, f
goto B33
bsf TRISA,0
bsf TRISA,6
bsf TRISA,7
return

END
 
As already mentioned, you need to turn on the weak pull-ups.

You don't mention which language you are using, in C18 you need
Code:
    INTCON2bits.RBPU=0;         //enable port b weak pullups

Mike.

Ah, sorry, I'm using assembly.

It might help to post your code and take a pic of your Junebug, showing the DIP switch settings.

I've tried several different programs, to same result, as stated in OP.

What's the correct settings on DIP switch? I've tried with both how it appears on front of manual, and all to the right. No difference.


Thanks.
 
In asm it's

bcf INTCON2, RBPU

On the Junebug, just switch the three "tutor" switches on (away from the pic chip) and the others off.

Mike.
 
In asm it's

bcf INTCON2, RBPU

On the Junebug, just switch the three "tutor" switches on (away from the pic chip) and the others off.

Mike.

Okay, thanks Mike. The position of my switches is correct; I'll try again later (work in a minute) with that line - I should put it right at the start, correct, and then just leave it alone?

Out of 'noob' interest, what's the use of it being user controlled - ie, I assume there's a scenario when you'd use bcf INTCON2,RBPU ?


Thanks again.
 
Mike(Pommie) for future if the OP doesnt specify a language simply say something like:

INTCON2 Register Bit RBPU has to be cleared to enable port b weak pullups

Fordy, if a signal is IDLE low then a pullup would be wrong I think.. Would cause the signal to IDLE high. I think its there mostly if the need arises for it.. like if you need a IDLE high situation for one project you can enable it and if not disable it. This saves the PCB the need for a external resistor and traces for it.
 
Last edited:
I haven't gotten around to testing yet - but I'm stunned no-one thinks it's odd that they turn on when my finger hovers over?

I literally can hold them on without pressing the button, remove my finger and their off - finger back over, and they're on again. Not turning on weak pull-ups really turns momentary switches into hover sensors eh? Is it electromagnetic do you think, or what?
 
Its totally normal thats why no one is stunned. What that is called is a FLOATING PIN... if you leave it floating it will change from HIGH to LOW depending on its surroundings
 
Its totally normal thats why no one is stunned.

I figured it was either that or you didn't believe me.. Suppose that's a preferable answer!

I'm aware of floating pins, I just didn't realise it could occur in the circumstances I've described, ie a finger hovering over a button. I thought it was more random without press/pseudo-flashing on button press.


Thanks again.
 
With careful loading of the pin you could turn it into a cap active touch switch =)
 
Your body is picking up the 50/60Hz mains hum and switching the pin at the same frequency.

Just in case it is a problem with your Junebug, here's some simple code that will latch an LED when a button is pressed.
Code:
		#include <P18F1320.INC>
		config	OSC=INTIO2,LVP=OFF,WDT=OFF

		org	0
		movlw	0x7f
		movwf	ADCON1
		bcf	INTCON2,RBPU
Main		btfss	PORTB,RB0
		call	LED1
		btfss	PORTB,RB2
		call	LED2
		btfss	PORTB,RB5
		call	LED3
		goto	Main

LED1		bcf	TRISA,0
		bcf	TRISA,6
		bsf	TRISA,7
		bsf	LATA,0
		bcf	LATA,6
		return

LED2		bcf	TRISA,0
		bcf	TRISA,6
		bsf	TRISA,7
		bcf	LATA,0
		bsf	LATA,6
		return

LED3		bsf	TRISA,0
		bcf	TRISA,6
		bcf	TRISA,7
		bsf	LATA,6
		bcf	LATA,7
		return

		end

HTH

Mike.
 
Your body is picking up the 50/60Hz mains hum and switching the pin at the same frequency.

Just in case it is a problem with your Junebug, here's some simple code that will latch an LED when a button is pressed.

<snip>

HTH

Mike.


Works a treat.

Thanks Mike; everyone.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top