Need help, high speed D/A converter, see code


Closed Thread
Results 1 to 7 of 7
  1. #1
    rpatel's Avatar
    rpatel Guest

    Question Need help, high speed D/A converter, see code

    I can't get the HSERIN to work on simple PIC asynchronous transmit and recieve

    *Running at 115200bps
    (using 22.1184MHz xstal, for 0%error baud rate)
    *transmitter is a PIC18F252
    *reciever is a PIC18F252

    Transmitter:

    'HARDWARE DECLARATIONS (defines and port settings)
    Define OSC 20 '0% baud error with 22.1184Mhz xstal
    Define HSER_RCSTA 90h 'PIC Hardware Serial Port Receiver define
    Define HSER_TXSTA 24h 'PIC Hardware Serial Port Transmit
    define HSER_SPBRG 11 'Zero error SPBRG integer value
    define ADC_BITS 8 '8 bit sampling ADC define
    define ADC_SAMPLEUS 5 'Analog data sample time
    TRISA = 255 'Set PORTA to all input
    ADCON1 = 0 'PORTA set to analog use for ADC
    'VARIABLES
    wilma var byte '[3] 'Variable for Accelerometer data
    I var byte 'Variable for counter label
    'PROGRAM
    i = 0
    wilma = 0
    Pause 5000
    '************************
    Start:
    ADCIN 0, wilma'
    wilma=(wilma*3)-50
    hserout [wilma]
    pause 10
    goto Start
    End
    '************

    Reciever:
    'HARDWARE DECLARATIONS (defines and port settings)
    Define OSC 20
    Define HSER_RCSTA 90h 'PIC Hardware Serial Port Receiver
    Define HSER_TXSTA 24h 'PIC Hardware Serial Port Transmit using "20h"
    define HSER_SPBRG 11 'Zero error SPBRG integer value
    'VARIABLES
    Fred Var byte
    'PROGRAM
    '**********************
    Start:
    hserin [bin Fred] 'Hardware Rx Pin C.7 (pin #18) on PIC18F252
    hpwm 1, Fred, 20000 'Hardware HPWM Pin CCP1 (pin #13) on PIC18F252
    goto start
    End
    '**************************

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i'm not sure how PBP will handle this baudrate crystal with a define osc of 20MHZ... i guess everything will run 22.1184/20 time faster SO, SPBRG must be 22.1184/20 = 1.10592 slow

    SPBRG=10 'should be 9.946...

    Or maybe i'm totally wrong there...

    BUT, can you try 20MHZ one with a simple

    DEFINE HSER_BAUD 115200

    instead of setting SPBRG to test only! if nothing is different try at a slower baudrate, let's say 2400.

    suggest to include this line in your receiver too to avoid buffer overrun...
    DEFINE HSER_CLROERR 1


    BUT, what happen when you connect via MAX232 to your PC. Can you receive/transmitt correctly???

    P.S wilma=(wilma*3)-50.... and wilma is a BYTE ?!? Should be word IMO.
    Last edited by mister_e; - 19th December 2004 at 13:10.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    rpatel's Avatar
    rpatel Guest


    Did you find this post helpful? Yes | No

    Talking baud rate

    I simply used the equation sets given in the picbasic pro manual for figuring xstal and spbrg for a needed baud rate.
    See attached Excel spreadsheet.
    I found another similar calculator(Excel) at this forum.
    (don't fret that variable wilma has some math to it, its a byte)
    ..
    Also, I have successfully communicated to a PC, and verified input data thru VB6 coding (at 115200 bps).
    ..
    And, verified bit timing and logic level voltages on a O-scope.
    ..
    SEE ATTACHED FILES.
    ..
    It seems as if there are other issues with HSERIN in the forum, and some are solved by watching the RCIF flag and then loading the RCREG into a byte variable., this didn't work for me.
    ..
    IS there anyplace that explains the HSERIN command completely?..
    ..
    I don't understand a few things about the command:
    my interpretation of Pic basic pro manual:
    HSERIN (parity) , (timeout goto label), [variable to load into]
    ..
    but from what I have seen in the forum, its actually:
    HSERIN (time in ms for timeout), (timeout goto lable), [variable to load into]
    ..
    Much appreciated thanks for anyone's help!!
    ..
    Attached Files Attached Files

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what about if you remove *bin* modifier in HSERIN?
    hserin [Fred] 'Hardware Rx Pin C.7 (pin #18) on PIC18F252
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    rpatel's Avatar
    rpatel Guest


    Did you find this post helpful? Yes | No

    Default yeap.

    tried:
    hserin [fred]
    hserin [dec fred]
    hserin [dec3 fred]
    hserin [bin fred]
    hserin 100, Nope, [fred]
    ...
    etc....
    I must have reprogrammed the PIC over 100 times.
    ..
    regards,

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Your settings are O.k.

    How do you interface your PIC to PC, PC to PIC ???
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    rpatel's Avatar
    rpatel Guest


    Did you find this post helpful? Yes | No

    Default pc interface

    I have done several things, with respect to this project, I have serial HSEROUT(0-5v) to a rs232 transciever-6 to +6v) to a pc.

Similar Threads

  1. High Resolution Timer & Speed Calculator
    By WOZZY-2010 in forum Code Examples
    Replies: 4
    Last Post: - 7th February 2010, 16:45
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Someone help me to simplify this
    By thrix in forum General
    Replies: 4
    Last Post: - 21st February 2004, 05:01
  5. Help wanted..
    By thrix in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th February 2004, 23:44

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