HSEROUT with Timer2 Interrupt


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2014
    Posts
    16

    Wink HSEROUT with Timer2 Interrupt

    I am using a PIC18F87K22 micro. I have timer2 setup with PR2 to generate an interrupt 250 times per second
    'setup timer2
    'Fosc/4 with prescaler=16 AND postscaler of 16 yields 62,500 Hz, count of 250 gives interrupt every 250th of a second
    '64mhz/4 = 4 mhz............16mhz/256 = 62500 hz.....use for 64 Mhz clock
    PR2 = 249 'Timer2 Period Register
    T2CON = 111110
    PIE1.1 = 1 'enable the timer2 interrupt

    Both UARTS are set to 19,200 baud (actually 19,230)

    Each UART will generate an interrupt if a character arrives and I can read both serial ports without any issues whatsoever.

    It is when I send characters where it appears that the UART timing seems to go screwy and the receiving
    computer gets strings with incorrect or missing characters

    If I transmit an array this way
    HSEROUT2 [STR SENDBUFF\30]
    It does not work. But if I disable the timer2 interrupt it works fine.

    However if I use assembly the timer2 interrupt does not affect it at all.

    FOR I = 0 TO 29
    SENDCHAR = SENDBUFF(I)
    GOSUB SENDCOM2
    NEXT I

    SENDCOM2:
    ;MOVFF source, destination = move source reg to dest reg
    @MOVFF _SENDCHAR,TXREG2
    CHECKCOM2:
    @MOVFF TXSTA2,_SENDCHAR
    IF SENDCHAR.1 = 0 THEN GOTO CHECKCOM2 'wait until transmit buffer is empty
    RETURN

    Suggestions?

  2. #2
    Join Date
    Nov 2014
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT with Timer2 Interrupt

    Finally found out the answer, needed to save and restore the Bank Select Register in the assembly interrupt routine.
    Upon entering the interrupt:
    ;save critical registers
    MOVFF STATUS,_SSAVE ;save STATUS
    MOVFF WREG,_WSAVE ;save W
    MOVFF FSR0L,_FSAVELOW ;save FSR0 lowbyte
    MOVFF FSR0H,_FSAVEHIGH ;save FSR0 highbyte
    MOVFF BSR,_BSRSAVE ;save bank select register

    Upon exiting:
    ;restore critical registers
    MOVFF _FSAVELOW,FSR0L ;restore FSR0 lowbyte
    MOVFF _FSAVEHIGH,FSR0H ;restore FSR0 highbyte
    MOVFF _BSRSAVE,BSR ;restore bank select register
    MOVFF _WSAVE,WREG ;restore W
    MOVFF _SSAVE,STATUS ;restore STATUS
    RETFIE ;return from the interrupt

Similar Threads

  1. Timer2 Interrupt, 16F1823
    By Dick Ivers in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd April 2014, 23:55
  2. LAB-X1 Timer2 Clock
    By Bruce in forum Code Examples
    Replies: 0
    Last Post: - 25th July 2010, 02:03
  3. PWM pic16f873a(can i use timer2?)
    By Jadavjd in forum General
    Replies: 3
    Last Post: - 3rd April 2007, 20:44
  4. HSerOut 16F877 Interrupt Driven
    By BigH in forum Serial
    Replies: 2
    Last Post: - 15th January 2006, 00:09
  5. Timer2
    By swordman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th September 2004, 12:50

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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