Serout2 and Interrupts 16F88


+ Reply to Thread
Results 1 to 15 of 15
  1. #1

    Default Serout2 and Interrupts 16F88

    I have a routine running in the background generating a 2khz pwm using TMR0.

    I want to use Serout2 to send out some data but the interrutps corrupt the flow of data going out on Serout2.

    To make it work I am having to disable the interrupt driven pwm, send the data then restart the pwm as in the below.

    Code:
    TMR0IE = 0                'Disable TMR0 interrupt enable bit (0 = Disabled)    
    serout2 AssistLed,16390,["DATA,TIME,",#Volts,",",AmpSign,",",#Amps,",",#Soc,",",#TempAvg,13]    'Sends logging data at 38400 baud
    TMR0IE = 1                'Enable TMR0 interrupt enable bit (1 = enabled)
    The problem is now the stopping of the 2khz pwm is causing problems in the associated hardware, it is noticing the missing pulses. To minimise that i have reduced the data I'm sending to the bare minimum, but the gap in pwm is still slightly noticeable. What I wanted to do is move the data I need to send into an array and then send one byte at a time which would allow the pwm to continue virtually unaffected as the many small gaps would be absorbed rather than the one big gap in the pwm stream i have now. Any ideas on how to get the formatted data from my Serout2 into an array or some other RAM location.

    I can't use HPWM that is already in use driving an LCD.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: Serout2 and Interrupts 16F88

    You have a 16F88.
    Use the USART with HSEROUT to send serial data.
    It will not be affected by interrupts.
    DT

  3. #3

    Default Re: Serout2 and Interrupts 16F88

    Already in use driving LCD sorry forgot to mention that. I need to break up the data into single bytes to send via Serout2 somehow.

    I meant HSEROUT in my first post not HPWM of course Duh!! <roll>
    Last edited by retepsnikrep; - 25th August 2011 at 15:40.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: Serout2 and Interrupts 16F88

    Can't you move the LCD pins?
    DT

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

    Default Re: Serout2 and Interrupts 16F88

    Well, there's still the Synchronous method, but you need another I/o and must modify the receiver... maybe not a that good idea
    Steve

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

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

    Default Re: Serout2 and Interrupts 16F88

    You might be able to play some 'tricks'. The LCD won't respond to anything on it's pins unless the ENABLE pin is low. Hopefully, you have HSEROUT connected to a DATA pin or the R/W pin.
    HSEROUT takes over a in when the port is enabled. Set SPEN high, Transmit your byte(s), wait one byte time for the last byte to be transmitted, and disable SPEN. Put a resistor between TXout and your MAX232. Connect an unused pin (call it the "blocking pin") to the junction of the resistor and the MAX232. Drive the pin high as soon as you get done transmitting the last byte, and tristate the pin before you send any data. Setting the blocking pin high will stop any garbage from going out on RS-232 while you write to the LCD.

    So, before you send a character using HSEROUT

    Tristate the blocking pin
    Enable SPEN
    Write the data
    Wait one byte time
    Set the blocking pin high
    Disable SPEN

    I haven't tried it, but it just may work.
    Charles Linquist

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

    Default Re: Serout2 and Interrupts 16F88

    Oh, and next time - ALWAYS use the hardware UART, and 18F parts!
    Charles Linquist

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: Serout2 and Interrupts 16F88

    Quote Originally Posted by Charles Linquis View Post
    Tristate the blocking pin
    Enable SPEN
    Write the data
    Wait one byte time
    Set the blocking pin high
    Disable SPEN
    Oooooo, I... like it.
    Sort of.
    DT

  9. #9

    Default Re: Serout2 and Interrupts 16F88

    I'm using a serial lcd at 9600 baud and if i move the lcd to another pin and drive it with a software serial routine that gets corrupted by the interrupt instead of the data out.

    If i can break the data I'm sending via the software serial routine down to byte size chunks the effect on my pwm is negligible. I can disable the interrupt for one byte at a time and use a subroutine to transmit it from some sort of ram buffer.

    I had thought of using the hserout for both devices by using a switch like a HCT4053 to change it from one to the other but my pcb won't allow that.

    I quite like that idea charles but when I'm transmitting data the lcd will display it as well which i don't want.

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

    Default Re: Serout2 and Interrupts 16F88

    I was thinking you were driving the LCD in 4 bit parallel mode. In your case, I would run my 16F88 at 20MHz and use DEBUGOUT at 57600 baud for one of the serial ports. DEBUGOUT has way lower overhead than SEROUT2. It takes less time to set up for the write and also allows you to run at
    higher baud rates than SEROUT2.
    Charles Linquist

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

    Default Re: Serout2 and Interrupts 16F88

    And before I shut up tonight, with a little ASM, you wouldn't have to turn off interrupts at all.

    Just download and include one of the (fairly) easy to find RS-232 ASM routines. Run it at 57600 baud. Set up a one-byte buffer. Have the PWM ISR check for a "buffer full" flag. If set, it jumps to the RS-232 routine and sends the byte, and when that routine is done sending the byte, it clears the "buffer full" flag. Since your PWM ISR is running at 2Khz, you have 500uSec between interrupts. But you can send a byte (at 57600) in 180uSec. Plenty of time.


    Your main program loop could then just check the buffer full flag. If it wasn't set, it would write a byte the the buffer.

    No stopping interrupts, and no corrupted data.
    Charles Linquist

  12. #12

    Default Re: Serout2 and Interrupts 16F88

    Thanks for the ideas all. What is the max baud rate for debug? can it do 115200? It seems to compile ok i could not find a supported baud rate list.

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

    Default Re: Serout2 and Interrupts 16F88

    Dave
    Always wear safety glasses while programming.

  14. #14
    Join Date
    Jul 2003
    Posts
    2,405

    Default Re: Serout2 and Interrupts 16F88

    Can't you use hardware PWM?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  15. #15

    Default Re: Serout2 and Interrupts 16F88

    Quote Originally Posted by Bruce View Post
    Can't you use hardware PWM?
    Already in use doing a seperate 20khz signal.

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