Shop OBEX P1 Docs P2 Docs Learn Events
sx48 proto board and noise — Parallax Forums

sx48 proto board and noise

CapdiamontCapdiamont Posts: 218
edited 2007-08-01 06:45 in General Discussion
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

Comments

  • BeanBean Posts: 8,129
    edited 2007-07-30 12:32
    PLP_B = 255 actually turns the pullups OFF. PLP_B = 0 would turn them on. (I know it's not the way you would think it works).
    Your best bet is to use the PIN definition.

    I have modified the program to what I THINK you are looking for.
     
    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 20 
    Pressed   CON 1
    
    ' -------------------------------------------------------------------------
    ' 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
        PAUSE 1
      LOOP
    
    ' -------------------------------------------------------------------------
    ' Subroutine Code
    ' -------------------------------------------------------------------------
    SUB OnMode
      Pump = 1
      IF delayTemp >= MaxDelay THEN
        TOGGLE Light
        delayTemp = 0
      ENDIF
      INC delayTemp
      ' DelayTemp = 255
      ' Return
    ENDSUB
    
    


    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
    ·
  • CapdiamontCapdiamont Posts: 218
    edited 2007-07-30 14:30
    I have cut and pasted your code in, but it doesn't seem to work. give me some time to look through things, gota go to work.

    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?
  • CapdiamontCapdiamont Posts: 218
    edited 2007-07-30 14:32
    also I thought plp worked like pullup, 1 to enable. That is why I thought plp_b should of been 255.
  • BeanBean Posts: 8,129
    edited 2007-07-30 15:07
    Yeah if you button is connected to ground then change PRESSED to 0.

    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
    ·
  • CapdiamontCapdiamont Posts: 218
    edited 2007-07-30 16:34
    The reason I asked is that after getting the RB pullups actually on, the RB show up as high, and thus in order to change state, I have to now make the button connect to ground in stead of +5.

    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.
  • BeanBean Posts: 8,129
    edited 2007-07-30 18:29
    Capdiamont said...
    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.
    You're Welcome, and I wish. I live in PA (not by choice).

    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
    ·
  • CapdiamontCapdiamont Posts: 218
    edited 2007-07-31 05:01
    Actually I was thinking you all seem to live inside the board.

    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
  • CapdiamontCapdiamont Posts: 218
    edited 2007-08-01 01:12
    I've been thinking, about it seeming to hang on the pause statements. I don't understand why it would do that. Is there a way to further troubleshoot that?

    The reason I ask, it seems like a good part of the debounce code you put in.
  • BeanBean Posts: 8,129
    edited 2007-08-01 02:23
    If you are using "step" or "walk" in the debugger, the pause commands will take FOREVER because the code is running like 0.001% of it's normal speed.

    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
    ·
  • CapdiamontCapdiamont Posts: 218
    edited 2007-08-01 06:45
    ok, put the debounce pauses back in, put it in run, and oh my! Too fast even when delay time was 16,000+. Moved freq from 4mhtz, to 32khz, and delay to 2,000. Works good now. It is all assembled, and working. Thanks!

    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.
Sign In or Register to comment.