• AVR Freaks

Hot!PIC16F690 EUSART Receive baud rate simulation problem and questions

New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2020/02/14 11:49:04
  • Location: 0
  • Status: offline
2020/03/01 07:53:47 (permalink)

PIC16F690 EUSART Receive baud rate simulation problem and questions

This problem is closely related to the EUSART TXIF simulation problem but I thought it warranted a separate entry because of the questions it raises.
Knowing that the EUSART baud rate simulation is broken in PIC16Fxxx_DFP version 1.1.23, it did not surprise me that the receive simulation is broken too.
I have been using the stimulus option to inject data from a file into the receive register.  My baud rate is set to 9600 so I would expect an RCIF interrupt roughly every 1 ms.  The receive flags and interrupt mechanism all work correctly but the receive interrupts are occurring every ~ 70 us so my six byte checksummed data packet gets received in 0.42 ms instead of roughly 6 ms.
Being aware of this, I didn't think there would be a problem but my simulated code worked while the same code didn't work on real hardware.
When I receive the first byte of a packet, I start a timer so that if the entire packet isn't received in time, the partial packet is discarded and the receive mechanism reset.  Due to a missing BANKSEL (grrr), my timeout duration went from a period of 13 ms to just 3 ms.  Because the simulated packet was always received in just 0.42 ms, the bug was not revealed on the simulator.
Eventually I found the bug the old-fashioned way with real hardware, some I/O lines and an oscilloscope.
Anyway, to verify I had fixed the problem, I altered my stimulus file to this style to work around the bad baud rate simulation and simulate a delayed data packet:

wait 1 ms
wait 1 ms
wait 14 ms

Unfortunately, I only ever receive an "A" in my receive register.
So my question is, "Can I only have a single string injected?".
My follow-up question is, "How do I send a double quote?".
My code actually uses binary packets so I had to use a hex editor to insert my data bytes into the string.  What happens if I need to send an ASCII 34 or 0x22 which can easily happen?
Which brings me to a suggestion for the stimulus file injection.  I think it could be very useful if it could support the following format:

wait 1 ms
wait 1 ms
send datafile1.txt
wait 14 ms
send datafile2.txt
wait 1 ms
send "B"

This would allow timed strings to be sent as they currently are but would also allow the injection of binary data files into the receive register.  The "wait"s would allow simulation of real data streams and create a mechanism to deliberately create a known broken stream which, in my opinion, is vital in testing code.  I want to test that the code works when presented with bad data as well as with good.  Lastly, the "stop" would allow the simulated sequence to be injected just once rather than looping forever.  Maybe a "stop 5" to allow it to stop after 5 loops might be useful.
I hope your work with the baud rate simulation repair is going well and I look forward to your reply.
I am happy to test any updated DFP you create.
Best regards,
Nicholas Redgrave

2 Replies Related Threads

    New Users
    • Total Posts : 58
    • Reward points : 0
    • Status: offline
    Re: PIC16F690 EUSART Receive baud rate simulation problem and questions 2020/06/23 18:13:22 (permalink)
    Can you post your code here?
    • Total Posts : 1268
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: PIC16F690 EUSART Receive baud rate simulation problem and questions 2020/06/24 08:27:51 (permalink)
    A lot going on here.
    1.  I'm pretty sure that the stimulus injection file you presented should work as expected.  At least it's worked for years, and nobody has changed anything.  1 ms of simulator time can be a long time in real time, especially with SCL running.  I'm wondering if it is possible you didn't wait long enough, or some other issue short circuited stimulus, such as Watchdog timer.

    2.  You can inject hex numbers too, something like...
         0AA 055 05A 0A5
    3.  I believe the good old '\' meta char will serve as expected...
         "Injected data with a \" in it"
    Jump to:
    © 2020 APG vNext Commercial Version 4.5