Hi T,At 9600 baud each bit time is approx 104us.
The max error for a UART is about 5%, so that only allows for about a 5us variation in the bit timing, which at 32MHz translates to 20 ASM instructions. That's probably eaten up by the 'Save System' alone.
With all those other interrupts going on I can't see a software uart working, even one driven by a timer.
What's wrong with the hardware UART?
EDIT - strick some of that timing above. The output is generated by a periodic intr, so as long as the isr time doesn’t exceed half the bit time you'll probably be OK. Still, that could be a problem...
Yes, I incorrectly thought the CCP2 module could use any 16 bit timer as it can on many other pics - one of the problems of not being able to test it. I'll look at the code later to see if it can be salvaged. Busy with other code ATM.I haven't been following along, but it looks like you're trying to use TMR5 along with CCP2 to generate a bit-banged UART (for what ever reason).
On that device, CCP2 can't use TMR5 as a clock source. In capture/compare modes the CCP peripherals can only use TMR1.
TMR5 is a special beast... it has it's own period register (PR5H : PR5L) and the TMR5IF interrupt bit is in PIE3/PIR3 bit 0
This doesn't matter, the bits are relative to the start bit so if ALL bits are delayed by 1 hour (instead of 5uS) then it'll still work. Edit, I see your edit now, I'm assuming that the time for 9 bits (start+8data) cannot exceed 1/2 a bit error I.E. 50uS total so ~10uS per bit. I don't count stop bits as they are a low value and intrinsic to the code.The max error for a UART is about 5%, so that only allows for about a 5us variation in the bit timing, which at 32MHz translates to 20 ASM instructions. That's probably eaten up by the 'Save System' alone.
Seems it's used for something else!!!What's wrong with the hardware UART?
Hi M,Yes, I incorrectly thought the CCP2 module could use any 16 bit timer as it can on many other pics - one of the problems of not being able to test it. I'll look at the code later to see if it can be salvaged. Busy with other code ATM.
This doesn't matter, the bits are relative to the start bit so if ALL bits are delayed by 1 hour (instead of 5uS) then it'll still work. Edit, I see your edit now, I'm assuming that the time for 9 bits (start+8data) cannot exceed 1/2 a bit error I.E. 50uS total so ~10uS per bit. I don't count stop bits as they are a low value and intrinsic to the code.
Seems it's used for something else!!!
Mike.
I see. I went back and read through some of the thread. Sorry I didn't see that.The UART RX is used for the GPS input, and the UART TX is an SS/CS input for the SPI. I hope that's not a conflict?
Hi T,I see. I went back and read through some of the thread. Sorry I didn't see that.
So this PIC has to be an SPI slave also? I would think that's another interrupt to deal with, although sync'ing an SPI slave and master can be very tricky (I see it's just polled in some of the original code). The slave needs to know when a new packet begins/ends, and on the master side it never knows if the slave is ready to receive a byte.
Hi M,I just realised, software UART could be done with uS accuracy using CCP2. Timer 1 is already running at 2MHz.
I'll have a go later.
Mike.
Edit, yes, 500nS accuracy.
If you're already using TMR1 then I don’t think that'll work. To get a periodic timer you have to use Compare mode special event trigger, which will reset the timer.I just realised, software UART could be done with uS accuracy using CCP2. Timer 1 is already running at 2MHz.
I'll have a go later.
Mike.
Edit, yes, 500nS accuracy.
Or compare and set/reset output pin. This is what the servo output uses which leaves timer 1 free running. Adding n to CCPR will generate an interrupt n/2 instructions later.If you're already using TMR1 then I don’t think that'll work. To get a periodic timer you have to use Compare mode special event trigger, which will reset the timer.
The compare mode used is one of the two that set/reset the output pin,
Or, if no change desired then the 1010 mode to just generate the interrupt. It should be interesting if I can get this software (or is it semi-hardware) UART to work.
Can you just cut/paste it here? I went looking for #446 etc but just got lost.Earlier I came up with an idea!
Hi M,Can you just cut/paste it here? I went looking for #446 etc but just got lost.
What is the idea?
This is a link to #446. Are you suggesting having a frame variable again? This is already implemented.
Mike.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?