16F690 or whatever SEROUT to PC


Closed Thread
Results 1 to 15 of 15
  1. #1
    xnihilo's Avatar
    xnihilo Guest

    Smile 16F690 or whatever SEROUT to PC

    Hi,

    I'd like to send an array of 70 bytes to a PC using the serial port.

    Hardware connection:

    I plan to connect PIC pin RA5 to DB9 pin 2 (RX) of the pc via an inline 1K resistor.
    (By the way, my pic pin RA5 has a 100K weak pull down because of the way I use the pin when not using it to transfer data).

    I put the following line at the top of the code:

    Code:
    Include "modedefs.bas"
    
    'Predef config at flashing time
    
    @        device  pic16F690, intrc_osc_noclkout, BOD_OFF, PWRT_OFF, wdt_off, mclr_off, protect_off
    I also use:

    Code:
    DEFINE OSC 8			'set OSC value to 8MHz for instructions PAUSE, PAUSEus and SOUND (instead of default 4MHz)
    
    DEFINE CHAR_PACING 1000
    and:

    Code:
    CLEAR
    
    INTCON = 0      'disable interrupts and clear int flags
    
    OSCCON = %01110001      'set osc to internal, HS 8MHz
    'SETTINGS  for this register:
    'bit 7: not used: 0
    'bits 6-4: IRCF bits: 8MHz internal oscillator: 111 (after a reset: auto sets to 110 = 4 MHz)
    'bit 3: OSTS bit: device is running from one of the two internal sys clocks (HFOSC or LFOSC): 0
    'bit 2: HTS bit: high freq 8MHz-125KHz status bit: shows if HFINTOSC is stable or not: 0
    'bit 1: LTS bit: low freq 31Khz status bit: shows if LFINTOSC is stable or not: 0
    'bit 0: SCS bit: sys clock selection bit: internal  oscillator is used for system clock: 1
    
    '''''''CMCON0 =  %00000111			'comparators OFF, val = 7
    
    CM1CON0.7 = 0   'disable comparator1
    CM2CON0.7 = 0   'disable comparator2
    
    ANSEL = %00000000     'choose digital i/o, val = 0
    ANSELH = %00000000	   'PIC16F690 specific		
    
    ADCON0.0 = 0            'turn adcon off (is already off by default)
    
    
    OPTION_REG = %01111111		'enable porta weak pullups (no weak pull-up available for porta.3), p12
    'bit7: pull ups are enabled by individual port latch values
    
    '-------------------------------------------------------------------------------
    TRISA = %111111 				'all porta pins are set to input (high impedance) (portA.3 is always input pin, datasheet p5), beware of floating pins
    '-------------------------------------------------------------------------------
    
    'RA5 is used in default as an input, LOW (100K ext WPD) because it waits for a +5V pulse to bring it HIGH
    
    TRISB = %0000
    
    TRISC = %00000000 				'all portc pins are set to output mode, PWM starts if CCP1CON is enabled
    
    '-------------------------------------------------------------------------------
    WPUA =  %011111 			'enable internal weak pull ups resistors individually on portA pins to bring them HIGH internaly, except for porta.3 for which the pullup is auto set if pin is enabled as MCLRE (Ra3 can be set as mclr or as i/o port with config words)
    '-------------------------------------------------------------------------------
    WPUB = %0000
    
    
    'enable for RA0-4,(RA3 has an external 10k WPU, no internal WPU is available except automaticaly if used as MCLR)
    'RA5 is LOW as default, it has an external 100k WPD (input as default).
    
    'MEMO: when pic powers up all ports are set to inputs
    
    '-------------------------------------------------------------------------------
    PORTA = %011111              'set pins logic
    '-------------------------------------------------------------------------------
    PORTB = %0000
    PORTC = %00000000 			'set pins logic
    'All are set to low by default, pins with pullups are brought automaticaly HIGH anyway
    and just before the ON INTERRUPT I have:

    Code:
        'set as output low
        TRISA.5 = 0
        PORTA.5 = 0
        FOR i = 128 to 197
            read i,hits_count    'get the number of times player was hit by this opponent
            SEROUT PORTC.5,T9600,[hits_count]
        NEXT i
        'restore as input low
        TRISA.5 = 1
        PORTA.5 = 0
    What will be output? RS232 level so I can connect it directrly to the PC or should I use MAX232 chip???

    Thanks!
    Last edited by xnihilo; - 30th May 2008 at 20:52.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What will be output? RS232 level so I can connect it directrly to the PC or should I use MAX232 chip???
    if the distance is not to far, maybe less than 10 feet a 232 chip is not need . Just make sure you are using inverted mode for the serial.
    Dave
    Always wear safety glasses while programming.

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by mackrackit View Post
    if the distance is not to far, maybe less than 10 feet a 232 chip is not need . Just make sure you are using inverted mode for the serial.
    Hello,

    What is the output of the pic? TTL or RS232?
    It should be less than 10 feet.

    What is exactly the inverted mode?
    I should be using N9200 instead of T9200 then?

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


    Did you find this post helpful? Yes | No

    Default

    N9600 would work IF AND ONLY IF the internal OSC is accurate enough.

    High likely i would use DEBUG instead, much more, i would use HSEROUT and a max232, max233 or whatever else RS232 driver.

    You can reduce the in serie resistor if you want.
    Steve

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

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xnihilo View Post
    What is the output of the pic? TTL or RS232?
    RS232
    What is exactly the inverted mode?
    Just as the name implies. The signal is inverted. Up is down and down is up.

    HSEROUT is always TRUE. So the MAX232 or equal is needed for this.

    I agree with Steve, get an external OSC and save your headache for someplace else.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    AND as you use the bit banging solution, you should make sure your Serial pin idle to the right level before sending any data.

    true idle high
    Inverted idle low.
    Steve

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

  7. #7
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    I am using a 16F690 which has an USART, cool, but all pins are used, not cool... I can use RA5 before the program uses it for communicating with another pic.

    Using Hserout would be nice and adding an external osc too but I don't have the pins available for that.

    Well, so I am confused.

    The only pin I have is RA5, what should I do...
    Use SEROUT, right?
    And use a max232 (in this case what benefit to I have if the pic is already outputing RSR232 level signal?).
    Whith what setting for SEROUT if not N9200?
    And can I or can I not use an external OSC?

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xnihilo View Post
    The only pin I have is RA5, what should I do...
    Re-design your project.
    Use SEROUT, right?
    Or DEBUG or SEROUT2
    And use a max232 (in this case what benefit to I have if the pic is already outputing RSR232 level signal?).
    In your case there is not a benefit. If you were sending a longer distance or using HSEROUT then you would need it.
    Whith what setting for SEROUT if not N9200?
    SEROUT -- N9600
    SEROUT2 ---16468
    DEBUGE --- DEFINE DEBUG_MODE 1
    And can I or can I not use an external OSC?
    If you mean internal...Maybe.
    Temperature change can cause the internal to vary. It may work on the bench but not in a finished application.
    Dave
    Always wear safety glasses while programming.

  9. #9
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    The project is still my lasergame equipment.

    When the "body" module is powered up, it will send 70 bytes to the PC (scores).
    It will not have the time to heat too much do you think I still can use internal OSC at 8MHz, without a MAX232, with serout, N9600, a 1k inline resistor between pic RA5 and PC pin 2? Redesigning the project is unfortunately almost impossible now.

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    All I can say is to give it a try. Maybe in your case it will not be to much of a problem if communications do not work every time. Just try sending the score again??

    The MAX232 will not help you.

    If you find it works part of the time, you may try 2400 baud. Sometimes a slower signal is more reliable and more tolerant.

    I am not sure, the internal on your chip might be able to be calibrated. Some one else will have to help you if it can or needs to be.
    Dave
    Always wear safety glasses while programming.

  11. #11
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    thank you for your answers

  12. #12


    Did you find this post helpful? Yes | No

    Default int osc

    My experience with newer PIC's w/8mhz int osc is they can be counted on for good enough freq for serial stuff....!!??

    don
    amgen

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


    Did you find this post helpful? Yes | No

    Default

    The 8Mhz internal oscillator in most 18F PICs will work fine with SEROUT/SEROUT2 at up to 9600 baud. If you use DEBUGOUT, you can extend that to at least 19.2Kbaud.

    Amazingly enough, I have used the 8MHz internal oscillator on an 18F2221 to communicate with another PIC at 38.4Kbaud (using DEBUGOUT). This worked across 16 parts, and all were tested to be fully operational while running in a temperature chamber -20C to +85C.

    And as far as whether to use a MAX232 or not - the level coming out of a PIC does not meet RS-232 specs. While it usually works, I would never sell a product that way.
    Charles Linquist

  14. #14
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    The 8Mhz internal oscillator in most 18F PICs will work fine with SEROUT/SEROUT2 at up to 9600 baud. If you use DEBUGOUT, you can extend that to at least 19.2Kbaud.

    Amazingly enough, I have used the 8MHz internal oscillator on an 18F2221 to communicate with another PIC at 38.4Kbaud (using DEBUGOUT). This worked across 16 parts, and all were tested to be fully operational while running in a temperature chamber -20C to +85C.

    And as far as whether to use a MAX232 or not - the level coming out of a PIC does not meet RS-232 specs. While it usually works, I would never sell a product that way.
    Fine, RS232 levels out of the pic is not right. Can I use a MAX232 chip to boost the signal then? Is there a post with the recommended connexion? I have the datasheet with a "typical application" circuit...

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


    Did you find this post helpful? Yes | No

    Default

    Just use the connections shown in the MAX datasheet. If you are using SEROUT/SEROUT2 make certain you use the "TRUE" settings (idle high), because the MAX chip inverts the signal. Tx of the PIC to T1in of the MAX. R1out of the MAX to Rx of the PIC.
    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. 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. 16f690 crashes
    By Lincoln S. in forum Serial
    Replies: 8
    Last Post: - 26th November 2008, 08:32
  5. Replies: 4
    Last Post: - 7th September 2005, 14:11

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