Serout problem


Closed Thread
Results 1 to 40 of 95

Thread: Serout problem

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    ok here the code:

    Include "modedefs.bas"
    DEFINE OSC 20 '20Mhz Oscillator was used

    ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT
    ADCON1=7
    CMCON = 7 'COMPARATORS OFF
    TRISB = %00000000 'PORTB OUTPUTS

    START:
    serout portb.2,n2400,[$AA]
    Pause 100
    GOTO START

    When I change the serout to serout2 , its worst. I am not getting a lot out the output pin, I also tried pin9 for output.

    I have a outpu 20Mhz crstal on port 15 and 16
    MCLR with a resistor to Vdd
    Vdd on 14
    ground on 5
    wire from 8 to input of TX module

    ken




    I see the problem right away. Remember when I said that the receiver needs to be trained (take a bit of time and read back there somewhere)? Well, you're sending one character, waiting 100ms, then sending another, waiting another 100ms...etc.
    That 100ms is WAYYYY too long. Change that pause to less than 5ms, and then look at your datastream at the receiver.

    Try this-----


    START:
    serout portb.2, n2400, [ $aa, $aa, $aa, $aa, $aa ]
    Pause 1
    serout portb.2, n2400, [ $0F, $F0 ]
    Pause 1
    GOTO START

    The 4 $AA's will take 16.6ms to transmit and probably won't match the transmitter output very well. Do not worry about that, it's ok, that's why we're training the receiver. It's completely normal.

    After a few cycles, the $0F and $F0 should be clearly visible and practically match the transmitter output (because we've trained the receiver). The $0F and $F0 will take about 8.3ms to complete, then there will be a 1 ms pause, then the sequence will start over.

    You should be able to see an obvious difference between the $AA's and the $0F and $F0.
    This should work just fine. Let me know what happens...
    JDG
    Last edited by skimask; - 1st December 2006 at 03:10.

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    yes its working, Thank You !!!
    I just assumed that because I dont have a receiver chip i did not need the training session .
    I tried it without just to see and it works, But I will use it.

    Also , I did not see any pause in your code
    serout2 dataout , 84 , [ REP key \ 2 ] 'serout2
    how does yours work ?
    also i wandered around on google and did see anyone using a pause that long. Like here, they use 1 sec pause:http://www.imagesco.com/articles/lcd/05.html

    Ken

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    O my !
    I just realize there button edit on this site
    I was sure you put this pause
    PauseUS 1660 '<----notice the change to pauseUS
    and I could not see it anymore, then I saw the edit button,
    I thought for a while I was in an episode of the twilight zone..
    unless you did not edit it....

    k

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur
    yes its working, Thank You !!!
    I just assumed that because I dont have a receiver chip i did not need the training session .
    I tried it without just to see and it works, But I will use it.

    Also , I did not see any pause in your code
    serout2 dataout , 84 , [ REP key \ 2 ] 'serout2
    how does yours work ?
    also i wandered around on google and did see anyone using a pause that long. Like here, they use 1 sec pause:http://www.imagesco.com/articles/lcd/05.html

    Ken

    The first pause is just to let the LCD startup, you only need it once. The second one is there for no reason other than to be there and provide a bit of delay so you can see what is going on.
    As far as the code goes, what you see is what you get. I don't have anything hidden in there, nothing special is going on...
    JDG

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I,,
    I was looking at your receiving code, and I could not see any serial in command. What are you using instead ?

    ken

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    Anyway here is the code I am using at the receiver:
    I will be putting a lcd on the circuit to see how the pic is reading the input.
    Beside the test led input at the begining the rest is not functioning, I suppose it has to do with the data coming is in one format and I am treating it in another.

    DEFINE OSC 20 '20Mhz Oscillator was used

    Include "modedefs.bas" ' Include serial modes

    ADCON0 = 0 'AD MODULE OFF & CONSUMES NO CURRENT
    ADCON1=7
    CMCON = 7 'COMPARATORS OFF
    TRISA = 0 'outpu
    TRISB = 1 'input

    B0 var byte

    porta.0 =1 'testing leds output
    pause 500
    porta.1 =1
    pause 500
    porta.2 =1
    pause 500
    porta.3 =1
    pause 500

    start:
    serin PORTB.3,n2400,[B0]
    pause 1
    if B0 = $aa then led1
    if B0 = $aa then led2
    if B0 = $5a then led3
    if B0 = $5a then led4

    goto loop

    led1:
    porta.0 =1
    pause 200
    goto start

    led2:
    porta.1 =1
    pause 200
    goto start

    led3:
    porta.2 =1
    pause 200
    goto start

    led4:
    porta.3 =1
    pause 200
    goto start

    loop:
    porta.0 =1
    pause 200

    goto start
    end

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    A couple of notes:

    TRISA = 0 'outpu <------ might only set porta.0 as an output(?)
    use TRISA = %00000000 to make sure

    TRISB = 1 'input <------ will only set portb.0 as an input
    use TRISB = %11111111 to make sure all
    of port B is set to input

    start:
    serin PORTB.3,n2400,[B0]
    pause 1 <------ don't pause here, you want to read the serial
    and get done what you want done and get
    back to reading the serial port as quick as
    possible

    if B0 = $aa then led1
    if B0 = $aa then led2
    if B0 = $5a then led3
    if B0 = $5a then led4

    goto loop

    led1:
    porta.0 =1
    pause 200 <----------- take out all these pause 200 lines
    goto start

    led2:
    porta.1 =1
    goto start

    led3:
    porta.2 =1
    goto start

    led4:
    porta.3 =1
    goto start

    loop:
    porta.0 =1

    goto start
    end[/QUOTE]


    And you last post, 'where is the serin command?'. I'm using the hardware serial port driven by the 'on interrupt' command. Read the PBP manual a bit on it, then read the datasheets on the serial port and interrupts.
    Give me a few minutes. I'll rework your code into something useful.
    JDG
    Last edited by skimask; - 2nd December 2006 at 16:53.

  8. #8
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    wow, ok some improvements to be done.
    I will try this tonight when I get home, I might leave early...

    ken

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default serial wireless receiver code

    Ok, this should work. Ingest the code, understand the manchester encoding method.
    And your other program only turned LEDs on, it never turned them off. And it never cleared B0.

    'RECEIVER CODE

    DEFINE OSC 20 '20Mhz Oscillator was used

    Include "modedefs.bas" ' Include serial modes

    ADCON0 = 0 : ADCON1 = 7 'AD MODULE OFF & CONSUMES NO CURRENT
    CMCON = 7 'COMPARATORS OFF
    TRISA = $00 : TRISB = $FF 'all porta is outputs, all portb is inputs

    B0 var byte

    'testing led outputs
    porta.0 = 1 : pause 200 : porta.0 = 0
    porta.1 = 1 : pause 200 : porta.1 = 0
    porta.2 = 1 : pause 200 : porta.2 = 0
    porta.3 = 1 : pause 200 : porta.3 = 0

    start:
    B0 = 0 'empty B0 because the program doesn't
    serin PORTB.3,n2400,[B0] 'if n2400 doesn't work, try t2400
    if B0 = $aa then training 'manchester encoded $f
    if B0 = $55 then training 'manchester encoded $0
    if B0 = $56 then led1toggle 'manchester encoded $1
    if B0 = $59 then led2toggle 'manchester encoded $2
    if B0 = $5A then led3toggle 'manchester encoded $3
    if B0 = $65 then led4toggle 'manchester encoded $4
    if B0 = $66 then ledson 'manchester encoded $5
    if B0 = $69 then ledsoff 'manchester encoded $6
    if B0 = $6A then ledswing 'manchester encoded $7
    'still have $8-$e free to use
    goto start

    led1toggle:
    if porta.0 = 1 then
    porta.0 = 0
    else
    porta.0 = 1
    endif
    goto start

    led2toggle:
    if porta.1 = 1 then
    porta.1 = 0
    else
    porta.1 = 1
    endif
    goto start

    led3toggle:
    if porta.2 = 1 then
    porta.2 = 0
    else
    porta.2 = 1
    endif
    goto start

    led4toggle:
    if porta.3 = 1 then
    porta.3 = 0
    else
    porta.3 = 1
    endif
    goto start

    ledson:
    porta.0 = 1 : porta.1 = 1 : porta.2 = 1 : porta.3 = 1
    goto start

    ledsoff:
    porta.0 = 0 : porta.1 = 0 : porta.2 = 0 : porta.3 = 0
    goto start

    ledswing:
    porta.0 = 1 : pause 10 : porta.0 = 0
    porta.1 = 1 : pause 10 : porta.1 = 0
    porta.2 = 1 : pause 10 : porta.2 = 0
    porta.3 = 1 : pause 10 : porta.3 = 0
    goto start

    end


    Redo your transmitter code to match the receiver code. Put a few buttons on it to transmit the codes above needed to turn your leds on and off, etc.

    Do you have a couple of buttons on the transmitter or is it just a free running PIC without any outside input?

    JDG

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Strange SerOut Problem
    By masosi in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 23rd April 2007, 06:06
  5. Replies: 11
    Last Post: - 13th July 2005, 19:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts