November 23, 2024, 10:07:36 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


serout question

Started by Raisin-Toe, July 01, 2009, 01:09:45 PM

Previous topic - Next topic

Raisin-Toe

I want to get my home-made fader board to work with the basic stamp, but it needs a start, and a stop bit for asyncronos comunication. In the help menue of the basic stamp editor, it says that the Prop-1 only has a stop bit with 8 bits of data. Is there realy not a Start bit sent from the prop-1?

JonnyMac

The BASIC Stamp (BS1 in Prop-1, BS2 in Prop-2) start each serial byte with a start bit, followed by eight data bits, and one stop bit (10 bits total).  Keep in mind that a stop bit isn't really a bit, but a bit-wide delay with the serial line placed in the idle state.  You can extend the "stop bit" by padding the time between output bytes.
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

July 02, 2009, 07:20:58 PM #2 Last Edit: July 02, 2009, 08:08:56 PM by Raisin-Toe
To make my fader board work, I send the Address first, and then the Data.

Should this code work, If the baud type is right? I am not sure what Baud type to use, but the baud rate is 2400.


' {$STAMP BS1}

SYMBOL    Tpin    =     7
SYMBOL    BAUD    =     OT2400
SYMBOL    Address =     B0
SYMBOL    Data    =     B1
SYMBOL    Loop0    =     B2
SYMBOL    Loop1    =     B3

Reset:
  Address = 0
  Data    = 10

Main:
  FOR Loop0 = 0 TO 5
    FOR Loop1 = 10 TO 86
      SEROUT    Tpin, Baud, (Address, Data)
      Data = Data + 1
      PAUSE  250
    NEXT
    Address = Address + 1
  NEXT
  GOTO  Reset

Raisin-Toe

I have tried all of the different baud modes, and it hasn't worked on any of them. Is there something wrong with my code?

JonnyMac

Do you have link to details on the board you're trying to talk to?
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

I made the board from scratch, and programmed the chip for it. The chip is from Microchip, (PIC16F87).
The baud rate is running at 2400.
The idle state is high, I think.

The way it works is, I send the channel number first (0 to 5), then send the data for that channel, (resolution of 10 to 86). I know it works, I tested it with a simple controller on my breadboard.

What is the idle state for the Prop-1?

JonnyMac

For True modes the idle state is high but if you're using OT (Open True) then you need a pull-up on the serial line.  Since you're just talking to the one board and it doesn't talk back you should use T2400.
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

Hmm . . . I don't know wats wrong, it still isn't working.

JonnyMac

July 03, 2009, 09:12:21 AM #8 Last Edit: July 03, 2009, 09:14:43 AM by JonnyMac
I'm confused... you said you tested it with a simple controller on your breadboard; what controller?  Can you post that code?

Here's how I'd restructure your program; there is a subtle addition at the beginning that may help your device.

' {$STAMP BS1}

SYMBOL  TX      = 7

SYMBOL  Baud    = T2400

SYMBOL  addr    = B2
SYMBOL  level   = B3


Reset:
  HIGH TX                               ' set tx to idle
  PAUSE 5

Main:
  FOR addr = 0 TO 5
    FOR level = 10 TO 86
      SEROUT TX, Baud, (addr, level)
      PAUSE 250
    NEXT ' level
  NEXT ' addr

  GOTO Main


You realize, of course, that the Prop-1 is sending raw bytes (two per transmission).  Is this what your device expects?... or is it expecting something formatted? (e.g., decimal ascii string)  How does your test program send bytes?

Or... maybe your device needs a bit of time between bytes: 

Main:
  FOR addr = 0 TO 5
    FOR level = 10 TO 86
      SEROUT TX, Baud, (addr)
      PAUSE 1
      SEROUT TX, Baud, (level)
      PAUSE 250
    NEXT ' level
  NEXT ' addr
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

July 03, 2009, 10:59:38 AM #9 Last Edit: July 03, 2009, 11:04:37 AM by Raisin-Toe
I used a PIC18F4420 for a controller. I added an LED dispay to PORTB, and an anolog controll on PORTA pin 0.

I used assembley code. I just set the config bits outside of the code, that is why they are behind comment marks.

#include <p18f4420.inc>

   ;   CONFIG       _CONFIG1H = _OSC_XT_1H & _FCMEN_ON_1H & _IESO_OFF_1H
   ;   CONFIG       _CONFIG2L = _PWRT_ON_2L & _BOREN_OFF_2L
   ;   CONFIG       _CONFIG2H = _WDT_OFF_2H
   ;   CONFIG       _CONFIG3H = _MCLRE_OFF_3H & _LPT1OSC_OFF_3H & PBADEN_OFF_3H & _CCP2MX_PORTC_3H
   ;   CONFIG       _CONFIG4L = _STVREN_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
   ;   CONFIG       _CONFIG5L = _CP0_OFF_5L & CP1_OFF_5L
   ;   CONFIG       _CONFIG5H = _CPB_OFF_5H & _CPD_OFF_5H
   ;   CONFIG       _CONFIG6L = _WRT0_OFF_6L & WRT1_OFF_6L
   ;   CONFIG       _CONFIG6H = _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
   ;   CONFIG       _CONFIG7L = _EBTR0_OFF_7L & _EBTR1_OFF_7L
   ;   CONFIG       _CONFIG7H = _EBTRB_OFF_7H
      LIST
RA      =   0

      cblock   00
ADRES_BUF
STAT
      endc

;******************[Settings]*************************************
Start:

   movlw   0x05
   movwf   ADRES_BUF

   clrf   PORTB
   clrf   TRISB
   movlw   d'129'         ; BAUD = 20MHz/(64(129+1)) = 2403.846.
   movwf   SPBRG
   bsf      TXSTA,TXEN      ; enable transmit port.
   bsf      RCSTA,CREN      ; enable continuouse transmit
   bsf      RCSTA,SPEN      ; enable serial port

   movlw   b'00111101'      ; Set up the Anolog to digital converter
   movwf   ADCON2
   bsf      ADCON0,ADON      ; enable A/D converter.

;******************[Main Program]**********************************
TX_Loop:
   movf   ADRES_BUF,W      ; Get the address
   movwf   TXREG         ; Transmit the address
   decf   ADRES_BUF      ; select the next address
   btfsc   STAT,RA         ; Is it time to reset the address?
   call   Reset_ADRES      ; If it is, reset it.
   btfsc   STATUS,Z      ; Check if the ADRES_BUF has reached 0
   bsf      STAT,RA         ; If it has, then set the RA (Reset Address) status bit.
   btfss   TXSTA,TRMT      ; Is the serial transfer finnished?
   goto   $-1            ; No, keep testing

   call   A2D_Loop      ; Start the Anolog to Digital converter.
   movf   ADRESH,W      ; get the next Light level from the Anolog to digital converter.
   movwf   TXREG         ; transmit it.
   movwf   PORTB         ; Show it on my LED display
   btfss   TXSTA,TRMT      ; Is the transmit finished?
   goto   $-1            ; no, keep checking
   goto   TX_Loop         ; go back to the loop

;******************[Subroutines]************************************
A2D_Loop:
     nop                      ; wait for A2D amp to settle and capacitor to charge.
     nop
     nop
     nop
     nop
     bsf       ADCON0,GO      ; start conversion
     btfsc     ADCON0,DONE    ; this bit will change to zero when the conversion is complete
     goto      $-1
     return

Reset_ADRES:
   movlw   0x05         ; Set the addresss back to 5
   movwf   ADRES_BUF
   bcf      STAT,RA         ; clear the status bit.
   return

   end

JonnyMac

July 03, 2009, 01:12:06 PM #10 Last Edit: July 03, 2009, 01:15:04 PM by JonnyMac
Well, I don't do PIC assembly (SX I'm pretty good at) so that's not helping me -- especially since that PIC has a built-in UART.  I can see that you don't need a delay between bytes, but that's all I can tell.  Can you look at the output of your test program on a 'scope to make sure that it's True mode (likely) and not Inverted mode?
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Just a [possibly silly] question: You do have a common ground connection between the Prop-1 and your lighting board, right?
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

I changed something in my ISR (interrupt service routine), and now the basic stamp works great with it ;D! I have no idea how that fixed my problem though.

Cool, this is exiting! I havn't done anything like this before.

JonnyMac

Good news!  Happy 4th!

If you ever decide to give the SX a try I can show you lots of tricks.
Jon McPhalen
EFX-TEK Hollywood Office

Raisin-Toe

I need to increase the resolution, my fading looks choppy, but I will need a faster oscilator I think.