sx48 proto board and noise
Capdiamont
Posts: 218
I have a sx48 protoboard with sx key. The code seems to work great in debug with no hardware attached, until i added a button.
pull up resistor is enabled, but watching the pin in debug, it goes crazy. The lead to the button is about 1 to 2 feet. I want to install this in to an old UPS case, I thought the long lead would make it easier. Long day working with my mistakes, 1st sx program.
code:
DEVICE SX48, OSC4MHZ
IRC_CAL IRC_4MHZ
FREQ 4_000_000
'
' IO Pins
'
' PORT RA 4 bit reserve for serial on all programs, unused set to outout low
' port rb 8 bit, input
' port rc 8 bit, output
' port rd and re 8 bit, unused set to output, low
'
' Constants
'
'flash delay time, wait period between on/off, word size
MaxDelay CON 1000
'
' Variables
'
'delaytemp, wait time counter, word size
DelayTemp Var Word
'mode, on/off bit size
ModeTemp Var Bit
watch DelayTemp
watch ModeTemp
'
' INTERRUPT
'
'ISR_Start:
' ISR code here
'ISR_Exit:
' RETURNINT ' {cycles}
' =========================================================================
PROGRAM Start
' =========================================================================
'Pgm_ID:
' DATA "LightHouseVbeta0.01", 0
'
' Subroutines / Jump Table
'
' OnMode SUB 0
OnMode:
rc.1 = 1
if DelayTemp >= MaxDelay then
toggle rc.0
DelayTemp = 0
endif
DelayTemp = DelayTemp + 1
' DelayTemp = 255
' Return
goto Main
'
' Program Code
'
Start:
' initialization code here
TRIS_A = %0000 'outputs %=bitwise
TRIS_B = 255 'input dec
TRIS_C = 0 'output dec
TRIS_d = 0 'output dec, unused
TRIS_e = 0 'output dec, unused
PLP_b = 255 'MAKE rb port PINS PULLUP RESISTOR ON
' ST_B = 255 'make rb port pins schmitt trigger
ra = 0 'set putput low
rc = 0 'set output low
rd = 0 'set output low
re = 0 'set output low
' on/off swtich =rb.0
' lighthouse = rc.0
' pump = rc.1
Main:
' main code here
' modetemp/delaytemp/maxdelay
if rb.0 = 1 then
toggle ModeTemp
endif
if ModeTemp = 0 then
rc.0 = 0
rc.1 = 0
endif
if ModeTemp = 1 then goto OnMode
GOTO Main
pull up resistor is enabled, but watching the pin in debug, it goes crazy. The lead to the button is about 1 to 2 feet. I want to install this in to an old UPS case, I thought the long lead would make it easier. Long day working with my mistakes, 1st sx program.
code:
DEVICE SX48, OSC4MHZ
IRC_CAL IRC_4MHZ
FREQ 4_000_000
'
' IO Pins
'
' PORT RA 4 bit reserve for serial on all programs, unused set to outout low
' port rb 8 bit, input
' port rc 8 bit, output
' port rd and re 8 bit, unused set to output, low
'
' Constants
'
'flash delay time, wait period between on/off, word size
MaxDelay CON 1000
'
' Variables
'
'delaytemp, wait time counter, word size
DelayTemp Var Word
'mode, on/off bit size
ModeTemp Var Bit
watch DelayTemp
watch ModeTemp
'
' INTERRUPT
'
'ISR_Start:
' ISR code here
'ISR_Exit:
' RETURNINT ' {cycles}
' =========================================================================
PROGRAM Start
' =========================================================================
'Pgm_ID:
' DATA "LightHouseVbeta0.01", 0
'
' Subroutines / Jump Table
'
' OnMode SUB 0
OnMode:
rc.1 = 1
if DelayTemp >= MaxDelay then
toggle rc.0
DelayTemp = 0
endif
DelayTemp = DelayTemp + 1
' DelayTemp = 255
' Return
goto Main
'
' Program Code
'
Start:
' initialization code here
TRIS_A = %0000 'outputs %=bitwise
TRIS_B = 255 'input dec
TRIS_C = 0 'output dec
TRIS_d = 0 'output dec, unused
TRIS_e = 0 'output dec, unused
PLP_b = 255 'MAKE rb port PINS PULLUP RESISTOR ON
' ST_B = 255 'make rb port pins schmitt trigger
ra = 0 'set putput low
rc = 0 'set output low
rd = 0 'set output low
re = 0 'set output low
' on/off swtich =rb.0
' lighthouse = rc.0
' pump = rc.1
Main:
' main code here
' modetemp/delaytemp/maxdelay
if rb.0 = 1 then
toggle ModeTemp
endif
if ModeTemp = 0 then
rc.0 = 0
rc.1 = 0
endif
if ModeTemp = 1 then goto OnMode
GOTO Main
Comments
Your best bet is to use the PIN definition.
I have modified the program to what I THINK you are looking for.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
I had the tris in the pins section of the template before, but when doing say rc = 255 it wouldn't make the pins go high. When putting the tris after the start it made rc = whatever to work as expected.
Looking at your code through debug, it makes rb = 255 / all pins high. Does this mean ispressed needs to be 0 and rb.0's button gets hooked to vss(ground)?
using version 3.2.3 of editor
is there any modifications of the board I should do?
do i need to pass variables to the OnMode sub, such as DelayTemp?
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
Note I'm at work, just couldn't resist. Will have to wait until after 5pm California time, for further diag.
Thank you for your time, you have been above outstanding. Seems like many of you live here.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
Code seems to work fine as below, but weird thing is it seems to hang on the pause statements in debug, thus commented them out.
Next to connect the SSR's to the output.
'
' Device Settings
'
DEVICE SX48, OSC4MHZ
IRC_CAL IRC_4MHZ
FREQ 4_000_000
'
' IO Pins
'
' PORT RA 4 bit reserve for serial on all programs, unused set to outout low
' port rb 8 bit, input
' port rc 8 bit, output
' port rd and re 8 bit, unused set to output, low
RAUnused PIN RA OUTPUT
RBUnused PIN RB INPUT PULLUP
RCUnused PIN RC OUTPUT
RDUnused PIN RD OUTPUT
REUnused PIN RE OUTPUT
Switch PIN RB.0 INPUT PULLUP
Light PIN RC.0 OUTPUT
Pump PIN RC.1 OUTPUT
'
' Constants
'
'flash delay time, wait period between on/off, word size
MaxDelay CON 1000
Debounce CON 1
Pressed CON 0
'
' Variables
'
'delaytemp, wait time counter, word size
DelayTemp Var Word
'mode, on/off bit size
ModeTemp Var Bit
watch DelayTemp
watch ModeTemp
'
' INTERRUPT
'
'ISR_Start:
' ISR code here
'ISR_Exit:
' RETURNINT ' {cycles}
' =========================================================================
PROGRAM Start
' =========================================================================
'Pgm_ID:
' DATA "LightHouseVbeta0.01", 0
'
' Subroutines / Jump Table
'
OnMode SUB 0
'
' Program Code
'
Start:
' initialization code here
' ST_B = 255 'make rb port pins schmitt trigger
RA = 0 'set putput low
RC = 0 'set output low
RD = 0 'set output low
RE = 0 'set output low
' on/off swtich =rb.0
' lighthouse = rc.0
' pump = rc.1
Main:
DO
' main code here
' ModeTemp/DelayTemp/MaxDelay
IF Switch = Pressed then
TOGGLE ModeTemp
' PAUSE Debounce
DO
LOOP UNTIL Switch <> Pressed
' PAUSE Debounce
ENDIF
IF ModeTemp = 0 THEN
Light = 0
Pump = 0
ENDIF
IF ModeTemp = 1 THEN
OnMode
ENDIF
LOOP
'
' Subroutine Code
'
SUB OnMode
' OnMode:
Pump = 1
IF DelayTemp >= MaxDelay THEN
TOGGLE Light
DelayTemp = 0
ENDIF
INC DelayTemp
' DelayTemp = 255
' Return
ENDSUB
' goto main
The reason I ask, it seems like a good part of the debounce code you put in.
You can change Debouce to zero, then no code will get generated for the "PAUSE Debounce" lines.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Teacher: What is the difference between ignorance and apathy ?
Student: I don't know and I don't care
Teacher: Correct !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
Guess I'll have to do a completed project now, recieved the sx, key, and ssr's all on last friday. The project is for the local county fair, inside the poultry fair, is a large model 4 to 5' tall of a lighthouse. The pump, just so we don't have to plug it in, or out for on/off. Oh, the pump is for the waterfall.
The inputs are now schmitt type, just to prevent problems.