I am using a PIC18F4320 and have been trying to solve a very strange problem..
I have configured an interrupt using Timer1 which fires every 1ms. In that interrupt an ascii character gets sent, and is incremented, every time. Also, every 79 interrupts another section of the code gets executed, which just sends a '%' and resets the ascii code to '1'.
Nothing else is going on AT ALL in the program (i.e. no main routines at all). There are NO other interrupts running, just this one. The PIC is running at 40MHz and the serial comms are at 115,200 baud. Looking at the output on hyperterminal, it works fine streaming these lines of
79 ascending ascii characters and then a '%' then periodically, about every 13 lines of this some characters get missed. Its really odd.Changing the baud rate makes no change at all to the problem. Changing the interrupt rate even just the tiniest bit either makes the problem never occur or occur much much less often. Changing the clock rate also makes the problem disappear (from 40MHz to 10MHz). I literally have been stripping the program down to find the problem and its just one interrupt routine now, sending this data - note I even got rid of the context saving at the start and end to see if that helped...:
int btfsc PIR1,0 ; check if its the timer goto int_timer1 ; in which case service the interrupt goto int_end ; else go to the end int_timer1 ; comes here every 1.0002ms incf SPECIAL movf SPECIAL,W addlw 0x30 ; so we are in numbers movwf TXREG movlw Timer1L ; setup the timer period again movwf TMR1L ; movlw Timer1H ; movwf TMR1H ; bcf PIR1,0 ; clear the flag decfsz INTDIV1 ; divide the interrupt by 10 goto int_end int_timer2 clrf SPECIAL movlw '%' movwf TXREG movlw IntDiv movwf INTDIV1 ; int_end ; retfie ; return from int
Any suggestions? I couldn't paste the output from hyperterminal in here because the wrapping messed it up - go here for a screen shot:
you can see the weird glitch happening three times in that window.
Hope someone can help! I could of course just change the interrupt rate which solves it, but I would like to know the cause of the problem,
Cheers,
Reuben