|
|
View previous topic :: View next topic |
Author |
Message |
fadeout
Joined: 28 Jan 2004 Posts: 15
|
How to loose USART data: a choice (PIC16F870). |
Posted: Fri Jan 30, 2004 1:19 pm |
|
|
Hi, I'm quite new to PICs and very very new to CCS. I'm working on an application that has to Aquire data from the A/D every second and ask something on Serial Port every 3 seconds. Considering that
1) The serial response has non-deterministic timing
2) The A/D conversion is much more important
I have to be sure that a Serial Data don't breaks my A/D. I thought to disable USART during acquisition. Now comes the question:
If I receive chars on USART while this is not enabled what happens? I read in the Datasheet that i can see and have to clear the Overrun Bit, otherwise "no further data will be received". Is this true ? How can I ignore some data coming from USART ?
I would like a method to say:
*"Ok, now I'm not longer interested in receiving data: if something arrives just trash it, I have to do something else for the next three seconds!" and then, after three seconds, send a string and receive again serial data for one second and.... GOTO "*" !
Thanks a lot for your attention,
Best Regards
Paolo |
|
|
Darren Rook
Joined: 06 Sep 2003 Posts: 287 Location: Milwaukee, WI
|
|
Posted: Fri Jan 30, 2004 1:28 pm |
|
|
You can disable the UART completely by using the function SETUP_UART().
SETUP_UART(FALSE) disables the UART.
Basically, it clears the SPEN bit and another bit so it won't even be receiving data anymore.
If you are using streams,
SETUP_UART(FALSE,STREAMNAME) |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: How to loose USART data: a choice (PIC16F870). |
Posted: Fri Jan 30, 2004 4:18 pm |
|
|
fadeout wrote: | Hi, I'm quite new to PICs and very very new to CCS. I'm working on an application that has to Aquire data from the A/D every second and ask something on Serial Port every 3 seconds. Considering that
1) The serial response has non-deterministic timing
2) The A/D conversion is much more important
I have to be sure that a Serial Data don't breaks my A/D. I thought to disable USART during acquisition. Now comes the question:
If I receive chars on USART while this is not enabled what happens? I read in the Datasheet that i can see and have to clear the Overrun Bit, otherwise "no further data will be received". Is this true ? How can I ignore some data coming from USART ?
I would like a method to say:
*"Ok, now I'm not longer interested in receiving data: if something arrives just trash it, I have to do something else for the next three seconds!" and then, after three seconds, send a string and receive again serial data for one second and.... GOTO "*" !
Thanks a lot for your attention,
Best Regards
Paolo |
Why dont you read the analog input non stop and service the serial port non stop? What you have suggested will use under 1% of the resources available. |
|
|
Ttelmah Guest
|
Re: How to loose USART data: a choice (PIC16F870). |
Posted: Sat Jan 31, 2004 4:09 am |
|
|
fadeout wrote: | Hi, I'm quite new to PICs and very very new to CCS. I'm working on an application that has to Aquire data from the A/D every second and ask something on Serial Port every 3 seconds. Considering that
1) The serial response has non-deterministic timing
2) The A/D conversion is much more important
I have to be sure that a Serial Data don't breaks my A/D. I thought to disable USART during acquisition. Now comes the question:
If I receive chars on USART while this is not enabled what happens? I read in the Datasheet that i can see and have to clear the Overrun Bit, otherwise "no further data will be received". Is this true ? How can I ignore some data coming from USART ?
I would like a method to say:
*"Ok, now I'm not longer interested in receiving data: if something arrives just trash it, I have to do something else for the next three seconds!" and then, after three seconds, send a string and receive again serial data for one second and.... GOTO "*" !
Thanks a lot for your attention,
Best Regards
Paolo |
A lot depends on what else the chip has to do?.
One solution, would be to not use the RS232 interrupt. Instead have a 'timer' interrupt at (say) 256 uSec intervals, and use this to handle the AD. Use a 'clock' code similar to that posted here in the last few days. On the one second clock, call "read_adc(ADC_START_ONLY);", then on the next interrupt, call "read_adc(ADC_READ_ONLY);". Your ADC, will then be read over the period of a few uSec (depending on the ADC clock rate), starting at the timer tick. The timings involved in the 'seperated' ADC operations, are so short, that it is not a problem to call these in an interrupt.
In your main code, sit in a 'polling' loop, waiting for RS232 data (and doing any other 'housekeeping' tasks you need. Provided the loop time of the main code, plus the interrupt time for the ADC handler, does not exceed one byte time of the serial, both events will be handled happily, and your ADC, will be synchronous to the clock, and there is no need to disable the serial.
Equally, unless your need for synchronous events is to a few uSec level, you can perfectly well just handle the RS232 using an interrupt driven receive buffer, and the ADC, using similar timer loop, and all that will happen is that in the specific case of a serial character being received a few uSec before the ADC conversion would trigger, is that the conversion would be delayed by the 'handler' time for the serial. You don't say what processor clock you are using, but typically on a reasonably fast chip, this will only be perhaps 20uSec.
Best Wishes |
|
|
fadeout
Joined: 28 Jan 2004 Posts: 15
|
|
Posted: Sat Jan 31, 2004 11:26 am |
|
|
First of all thanks to you all.
Second... I'm taking to take just a little time to read better your posts and then I'll write again. |
|
|
fadeout
Joined: 28 Jan 2004 Posts: 15
|
I'll try |
Posted: Mon Feb 02, 2004 3:17 am |
|
|
Well, my clock is 4Mhz. In the next days I'll try to implement yours suggestions.
Thank you a lot.
Best Regards |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|