View previous topic :: View next topic |
Author |
Message |
ela_vasiliu
Joined: 18 Jun 2010 Posts: 3
|
PIN input read at a certain frequency |
Posted: Thu Aug 19, 2010 11:21 pm |
|
|
Hy,
It is the first that I'm working with PICC Compiler and I need some help.
I want to read the input signal on C7 PIN of PIC18F452 at a certain frequency using rs232. Can anyone help me with some example code.
Thanks.
Ela _________________ Ela |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Aug 20, 2010 7:56 am |
|
|
Are you trying to read a serial byte with the usual Start & Stop bits, or do you want to read an arbitrary string of bits? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Aug 20, 2010 8:03 am |
|
|
Not sure what you want to do:-
Do you want to read pin C7 every second via RS232 or do you want to read the frequency of the signal on pin C7 via RS232 ? |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Fri Aug 20, 2010 10:03 am |
|
|
The design specs seem a little vague. |
|
|
ela_vasiliu
Joined: 18 Jun 2010 Posts: 3
|
|
Posted: Mon Aug 23, 2010 2:24 am |
|
|
So, I want to read the signal on C7 Pin via rs232. My signal has the frequency of 1200Hz and i want to make 16 or 32 readings in each period of the signal.
Sorry if I'm not that explicit but as I've said before I'm a beginner.
Thanks _________________ Ela |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Mon Aug 23, 2010 5:17 am |
|
|
You will need to find out the RS232 properties (baud-parity-stop bits) of the device that is sending the data so you can set up the PIC properly.
You also must match the devices electrical specs. Usually to communicate with an RS232 device you will need something like a MAX232 chip to match signal voltage levels, unless the other device is putting out a TTL level signal.
Then you need to interpret the data coming in. Is it one byte? two bytes? 100 bytes?
Start by looking up the #USE RS232 directive in your manual. Then you can ask more specific questions. |
|
|
ela_vasiliu
Joined: 18 Jun 2010 Posts: 3
|
|
Posted: Mon Aug 23, 2010 6:09 am |
|
|
My signal is serial bus of bits, they come in groups of 9 or 18 bits _________________ Ela |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Mon Aug 23, 2010 6:50 am |
|
|
ela_vasiliu wrote: | My signal is serial bus of bits, they come in groups of 9 or 18 bits |
So, still use #USE RS232 and set bits=9
And, like pmuldoon said, make sure you match the electrical specs of the other device. RS232 is +- 15V typically where as TTL is 0-5V. A MAX232 chip can solve this. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Aug 23, 2010 9:18 am |
|
|
ela_vasiliu wrote: | My signal is serial bus of bits, they come in groups of 9 or 18 bits |
That is a rather odd signal. Can you give a link to the datasheet of the source of this signal, or a scope shot of several examples? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Mon Aug 23, 2010 9:33 am |
|
|
It may not even be a valid RS232 signal. It may just be a string of bits.
Maybe it randomly determines whether to send 9 or 18 bits. Maybe they're half-bits with positive or negative spin. See what happens when I'm left to my imagination! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Aug 23, 2010 11:26 am |
|
|
It should work, if you set the USART to synchronous Master Mode with continuous reception. Consult the PIC18F452 datasheet for details.
From the CCS doc, it can be expected that #use rs232 with SYNC_MASTER_CONT option is supporting the intended operation. |
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Mon Aug 23, 2010 11:39 am |
|
|
Quote: | It should work, if you set the USART to synchronous Master Mode with continuous reception. |
That would require a clock line, also. Wouldn't it? I don't know that there is one in this design. |
|
|
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Mon Aug 23, 2010 11:52 am |
|
|
pmuldoon wrote: | Quote: | It should work, if you set the USART to synchronous Master Mode with continuous reception. |
That would require a clock line, also. Wouldn't it? I don't know that there is one in this design. |
Yes, it does require a clock line.
We really need the OP to clarify what hardware they're working with. |
|
|
|