CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sending a code between 2 pic's mcu..

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
john098
Guest







sending a code between 2 pic's mcu..
PostPosted: Tue Oct 07, 2008 12:02 pm     Reply with quote

Hi

I am interested in sending a code(word), of 8 bits from one pic to another.
I have an idea of how to transmit it, but how do I check what is the bits
length ? Lets say I need to check if a bit is 50ns length, how do I check it?
I heard something about bits counter ? Someone have code ? Idea ?
My goal is to transmit it via RF or IR...=remote control.

I use the pic16f877. I will be happy to get all kinds of information about it.

Thanks a lot !!
john098
Guest







PostPosted: Wed Oct 08, 2008 2:38 am     Reply with quote

Hi.

Someone can give me direction about it ? Please?

Any kind of information about receiving a code would help....


Thanks a lot !
Ttelmah
Guest







PostPosted: Wed Oct 08, 2008 3:34 am     Reply with quote

Seriously, your question is so vague, that nobody has any idea what you are asking....
The normal way to send a byte between two chips, is asynchronous serial (sometimes called RS232, but this is actually the name of the signalling standard, not the data transmission, and is not what is being used, if you just connect 'logic' lines directly between the PICs).
The way this works, is very simple. Te line used to send, sits 'high', till you want to send a byte. You have a definition of the bits per second rate to be used (look at #use RS232). When a character is to be sent, the line drops for one bit time, and then the bit pattern is sent sequentially 'bit at a time' on the line. The whole sequence is synchronised from the initial falling edge. So (for instance):
Code:


#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

//This specifies the rate, and what pins to use. Note that C6, and C7,
//Have _hardware_to automatically perform the transmission and
//reception, and are the 'best' pins to use on your chip, for this reason.

putc('A'); //This sends the bit pattern for the letter 'A'

putc(100); //This sends the bit pattern for the number '100'

//At the other end

while (!kbhit()) ; //This will _wait_, till the bit pattern is seen
//You can do other jobs while waiting, by adding code inside the 'while'

val=getc(); //This will get the number that has been received.

val2=getc(); //This will automatically _wait_ for the second byte.


Now, this is 'pseudo code', it needs the fuses statement, and variables declared, and to be inside a 'main' routine to be used, but shows how easy it is. The chip hardware, automatically outputs the initial 'low', and then the eight data bits, and then a single 'high' bit as a 'stop', taking 0.104mSec for each (this is defined by the 'bps' number). At the receiving end, once the falling edge is seen, the data is sampled 0.15625mSec latter (the centre of the first data bit), and then every 0.104mSec for the eight data bits.
There are also software routines to do the same, if you use other pins, called exactly the same way. However these then _require_ you to be sitting waiting for the byte to arrive. The hardware will receive the byte automatically, even if you are doing something else.
If you just sent the byte, without the 'start' bit, you would never know where exactly it started.

Best Wishes
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 08, 2008 3:50 am     Reply with quote

Quote:
I need to check if a bit is 50ns length, how do I check it? I heard something about bits counter
.
.
My goal is to transmit it via RF or IR


Do you want to implement a bit counter, or a bit-length counter? To measure the length of the bit (which is what I think you want to do) you can use the external interrupt provision along with a timer. The timer starts counting when an external interrupt is received.

50ns is a bit too short for a PIC to measure, unless you use a very high end PIC. This is an excerpt from the datasheet of the '877 about timer0, Section 5.2
Quote:
When no prescaler is used, the external clock input is the same as the prescaler output. The synchronization of T0CKI with the internal phase clocks is accomplished by sampling the prescaler output on the Q2 and Q4 cycles of the internal phase clocks. Therefore, it is necessary for T0CKI to be high for at least 2Tosc (and a small RC delay of 20 ns) and low for at least 2Tosc (and a small RC delay of 20 ns). Refer to the electrical specification of the desired device.

Thus the minimum HIGH or LOW time is 2*Tosc + 20ns.

Also look at the section "TIMER0 AND TIMER1 EXTERNAL CLOCK REQUIREMENTS" in the DC Specifications of the datasheet.

The '877 has a maximum execution speed of 5 MIPS @ 20MHz, ie a 200ns instruction cycle. So even if you use a prescaler you will be pressed for time when measuring consecutive bits.

There are several RF modules available - the plain-vanilla RX/TX433 pair doesn't usually get any faster than 4800 baud (the fastest I've heard of is 9600 baud). At 4800 baud each bit will be 0.208ms long. This is well within the limits of the timer's capabilities. IR can be faster, but again, it will be within the PIC's capabilities.

Rohit
Guest








PostPosted: Wed Oct 08, 2008 5:33 am     Reply with quote

thank you so much for answer me !

so i understand that the best way to send a word between 2 pics is RS232.

i have 2 questions:
1. if i simply connect 2 pics with a short line (no need TTL chip), and send a word- i can simply receive it in another pic as you show me?

2. RS232 is the way they used to send data in remote control, and alarm systems?
can i send it via RF and IR or ULTRASONIC ? or there are baud limitations?
is that the way they send data in remote controls ?
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 08, 2008 5:54 am     Reply with quote

Quote:
so i understand that the best way to send a word between 2 pics is RS232.

RS232 need not necessarily be the best way to send data, but it certainly is one of the easiest. You need to take into account the distance that you need to transmit data, the carrier medium (light, radio waves, cable, etc), available power / current, etc to decide which is the best method for data transmission.

The answers to your questions:

1:
Say you have two PICs - PIC-a and PIC-b, all you need to do is connect the TX pin of PIC-a to the RX pin of PIC-b, and the RX of PIC-a to the TX of PIC-b. Confused? Make sure RX goes to TX in either case. You may want have a look at the CCS examples as well.

2:
In general, IR data is not direct RS232 data. IR is usually modulated with a carrier wave of 38KHz to prevent interference from ambient light sources. The protocols used in IR data vary. TV remotes use different protocols depending on the manufacturer; common protocols are SIRC (Sony), RC5, RC6 (Phillips), JVC, etc. PDAs, laptops and computers usually use the IrDA protocol for data transfer.

I have not heard of ultrasonic being used for data transfer, though it is used extensively for rangefinding.

Rohit
Guest








PostPosted: Wed Oct 08, 2008 6:59 am     Reply with quote

Thanx a lot again !
2 more questions please:

1.so in RF remote controls- (for cars) companies used to transmit RS232 ?
2. if picA send few words one after another- to picB , how do picB can
save each word and distingwish between them ? example code?

thanx again and sorry for my english...
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Oct 08, 2008 8:25 am     Reply with quote

Radio controlled models use a pulse width protocol, not binary words. The width of the first pulse controls the first servo, the second pulse the second servo, etc. Pulses vary from 1ms to 2ms to determine the value.

Serial binary protocols usually use one character such as $ to indicate the start of a message.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Oct 08, 2008 10:44 am     Reply with quote

Quote:
so in RF remote controls- (for cars)

SherpaDoug, I think he meant RKE (Remote Keyless Entry) systems for vehicles, and not RC toys. Confused

Anyway Guest (john098?), most of us use the term 'RS232' pretty loosely to mean 'serial transmission, that uses a waveform similar to the EIA/TIA RS232 specifications'. This pseudo-RS232 communication greatly simplifies circuit design.

This is a copy-paste from Craig Peacock’s Interfacing the Serial / RS232 Port V5.0 - http://www.beyondlogic.org/serial/serial.pdf :

Quote:
The electrical specifications of the serial port is contained in the EIA (Electronics Industry Association) RS232C standard. It states many parameters such as -
1. A "Space" (logic 0) will be between +3 and +25 Volts.
2. A "Mark" (Logic 1) will be between -3 and -25 Volts.
3. The region between +3 and -3 volts is undefined.
4. An open circuit voltage should never exceed 25 volts. (In Reference to GND)
5. A short circuit current should not exceed 500mA. The driver should be able to handle this without damage. (Take note of this one!)

Above is no where near a complete list of the EIA standard. Line Capacitance, Maximum Baud Rates etc are also included. For more information please consult the EIA RS232-E standard. It is interesting to note however, that the RS232C standard specifies a maximum baud rate of 20,000 BPS!


RS232 bytes are bound by 'frames'. A frame consists of a Start bit, 8 data bits, and a stop bit. A parity bit may also be included. PICs with UART automatically detect the bytes and put them into a receive buffer.

RKE systems typically use a Manchester encoded bitstream transmitted over radio waves using ASK or FSK modulation. This is not RS232.

Rohit
Guest








PostPosted: Wed Oct 08, 2008 11:01 am     Reply with quote

Yes I meant RKE.
I don't understand why they dont use the rs232 for vehicles, and alarm systems, or systems who care about security.

But thanx for the answers -now I can see the picture and try the RS232 on my pics.

Thanx.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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