HighSpeed A/D and Baud Rates


Closed Thread
Results 1 to 3 of 3
  1. #1

    Default HighSpeed A/D and Baud Rates

    Long time reader first time poster.

    Right now I am running a PIC 16F688 at 20Mhz. I'm taking the AD of a 1 Khz 50% duty cycle signal and sending it at 1250000 baud out to a serial terminal on a PC. Yes, my 232 converter is capable of this speed.

    Could someone help me with the math involved in the approximate time it is taking to do a conversion and then send the data. This is what I have come up with:

    1/1250000 = .8 us per bit

    Im sending HSEROUT [ bin ADRESH,Bin ADRESL," "] Is this 3 bytes of data total or 6 bytes?

    I seemed to have read somewhere in PBP manual that serout can send up to 65535 dec which would be a word.

    Assuming its 6 bytes of data and a stop and start bit for each word for the serial com gives 6*18 + 3*2 = 54 bits per result sent.

    54*.8 us = 43us

    The AD conversion is around 20 us according to datasheet.

    Now is this conversion happening at the same time as the HSEROUT is? Or is it 20 us for the conversion and then 43 us to send it? I think they can happen at the same time.......

    Ok, now the 1 Khz square wave has a duty cycle of 1 ms

    1ms/43us = around 23 samples per duty cycle. I seem to get around 4 or 5.

    Can anyone enlighten me on where the extra ~800 something us are going each cycle? Or how my math is wrong.

    Thanks!

    Here is my code:

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 1/12/2010 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    @ __config _HS_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
    DEFINE OSC 20

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 0 ' 1250000 @ 20MHz

    GoDone VAR ADCON0.1

    ADCON1 = %00100000 ; Fosc/32
    ADCON0 = %10010101 ;Right Justified, ch5(AN5), A/D on

    loop1:

    GoDone = 1 ;start conversion

    loop2:

    if GoDone = 0 Then ; is conversion done?

    HSEROUT [ bin ADRESH,Bin ADRESL," "] ;spit out answer

    else
    goto loop2 ; go back and check if A/D is done if it wasn't before

    endif


    goto loop1 ;do forever

  2. #2
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Im sending HSEROUT [ bin ADRESH,Bin ADRESL," "] Is this 3 bytes of data total or 6 bytes?
    No.
    It's actually 17 bytes. The "BIN" qualifier sends one byte for each bit, either "0" or "1". If you want 3 bytes, you need to delete the two "BIN":

    HSEROUT [ ADRESH, ADRESL," "]

    BTW, If you want fast a/d, then you need to start the new a/d conversion as soon as the last one was finished--don't wait until after your serial is sent.
    Last edited by tenaja; - 13th January 2010 at 23:51. Reason: add sample

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    The way to really get some speed is to send two bytes only. The TXregister is copied to the transmit shift register one clock cycle after you load the TX register, then the TX register can be loaded immedately again. Your routine can proceed while the bytes are being sent.

    If you send more than two bytes, your routine has to wait until all but the last two bytes are shifted out.

    Sending two bytes takes only microseconds (in program time), while sending more than two bytes takes those same microseconds + ((number of bytes - 2)* byte send time).

    Another way to make things go fast - as Tenaja has said, don't use the ADCIN command. Instead, do it manually.

    1. Set up the ADC channel and start the conversion.
    2. Send some data.
    3. Read the result of the conversion you started in step 1.
    4. Set up the ADC channel and start the conversion.
    5. Send some data.
    7. Read the result of the conversion your started in step 4.
    8. Go back to step 1.
    Charles Linquist

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. DEBUG baud rates
    By btaylor in forum Serial
    Replies: 6
    Last Post: - 23rd January 2006, 12:00
  3. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 02:17
  4. Faster baud rates with SEROUT commands
    By TurboLS in forum PBP Wish List
    Replies: 1
    Last Post: - 19th February 2005, 10:05
  5. Baud Rate and Timing Calculator
    By picnaut in forum General
    Replies: 3
    Last Post: - 23rd January 2004, 16:48

Members who have read this thread : 1

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