Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

project help

Status
Not open for further replies.

ulot

New Member
Hello

i'm working on a project at school and i need to program 2 serial interfaces on a PIC to communicate between a computer another device.
This is a summary of my project:

i want to create a Power line communication interface to enable 2 computers communicate via the seria port and over the 220V AC power line.

So i need an RS232 interface with the PIC (using a MAX232) to enable the PIC receive 8N1 (8 data bits and 1 stop bit) from the PC and transmit it over the power line to the receiving PC.

A the PIC sends the serial data over the power line through a Power line Modem chip. But the problem is i have to add some preamble to my data (as adviced a technical personal from the company i got the power line chip from) before i send it over the Power line through the Power line modem to prevent me loosing some of my data during reception.
So i need to send/receive 8bit data from/to the PC and send/receive about 24bit data to/from the power line modem

i know i'll implement my two serial interfaces using a hardware UART of the PIC16F877 and a software UART using any other pin. But how best do i implement this.

My major area of challenge is this

1. if i have to receive more than 8bits of data say from the PC, how do implement this? Or must i restrict the maximum amount of input bytes i can get at a time or can i send out each byte as i receive it

2. secondly what kind of pramble can i use? because due to the nature of entire system, i will loose some of my input data before actual reception begins so how can i ignore the preambel and collect just my data?


3. which interface would be better to implement the software and Hardware UARTs, the PIC to PC interface or the PIC to modem interface?


I'll appreciate all the help i can get. Thank you.
 
Use the hardware USART to the PC, and the software one for the power line (as it's much more versatile). I would suggest you use some kind of packet system, Manchester coding might be a good idea as well, check my tutorials for an example.
 
1. if i have to receive more than 8bits of data say from the PC, how do implement this? Or must i restrict the maximum amount of input bytes i can get at a time or can i send out each byte as i receive it

Better than ask is to learn by yourself, i can help you, check the datasheet before doing anything, as you may find that the USART has an depth, this depth is the number of bytes it receives, then there are interrupts that will help to process this data buffer before new data overwrites the old data, i don't remember this, but i think the depth is of 8bytes, i guess that this is enough for any common project, it gives a total 64bits, or in other therms, an Int64 / long / qword variable !

More digested, you need to use interrupts to process the data has it comes.
I sugest you send the data from the PC and count the Bytes on the PIC, 24bits give you 3 Bytes, so, count 3 interrupts of Byte received and on the 3rd Byte read the 24bits at once.
This is the easyest way.
OR
Send 8bits of data then just confirm the 8bits, sending another 8bits will allow you to avoid errors by comparing all the 3bytes and searching for common bits on the 3 of them and building 1 byte from those 3 bytes.

Did i wrote too much ?... :p
 
thanks alot im greatful. i'll read up on all these, try my hand on some code and let you all know how far. thanks
 
time per cycle

please i'm having a bit of a problem in understanding delay routines. how do i calculate the time per cycle for each instruction when i'm using a 20MHz clock?
 
time per cycle

please i'm having a bit of a problem in understanding delay routines. how do i calculate the time per cycle for each instruction when i'm using a 20MHz clock? or any other clock speed
 
please i'm having a bit of a problem in understanding delay routines. how do i calculate the time per cycle for each instruction when i'm using a 20MHz clock? or any other clock speed
It's Fosc/4. 20MHz is 20 million cycles per second. Divide that by four and you have 5MHz, or 5 million instructions per second. So each instruction except the few multi-cycle ones takes 200nS with a 20MHz clock.

A nanosecond (nS) is a billionth of a second. 1000nS = 1 microsecond (uS) or millionth of a second. 1000uS = 1 millisecond (mS) or thousandth of a second. Did I miss one there? :p I don't think I did.
 
Last edited:
Okeedokee, welllll...I suggest using a timer (possibly the 16-bit one, TMR1 I think it was?) to make the software USART more accurate. To receive more than 8 bits at a time to use in the PIC, it might be a good idea to set the Receive Buffer Full interrupt and some subroutines to make a buffer in the general purpose registers.
 
Last edited:
Hello
My major area of challenge is this

1. if i have to receive more than 8bits of data say from the PC, how do implement this? Or must i restrict the maximum amount of input bytes i can get at a time or can i send out each byte as i receive it
Stop thinking in terms of bits, think in bytes.
Use the PIC hardware UART and an interrupt service subroutine to handle the data coming from the PC.
On each interrupt read the byte in the receive buffer and save it, until you detect the crlf code, if you are using ASCII data transmission
.

2. secondly what kind of pramble can i use? because due to the nature of entire system, i will loose some of my input data before actual reception begins so how can i ignore the preambel and collect just my data?
What data are you transferring to and from the PIC to PC.?

3. which interface would be better to implement the software and Hardware UARTs, the PIC to PC interface or the PIC to modem interface?
Hardware interface.

QUOTE]

Hi,

Give more information regarding the data..:)

To calculate the execution time of one instruction divide the crystal freq/4
One or two types of instructions, take two execution cycles.

What delays are you wanting.?
Look here:

, which PIC type.?
 
Last edited:
The PIC24FJ16GA002 etc have two USARTs if you can use a 16 bit processor. You can even chose which pins the USARTS connect to.

There are some 8 bit PICs with two USARTs, but only in surface mount packages.

The PIC18F24J11 is not yet available but it will have two USARTs.
 
Thanks Alot

Thanks alot for all the advice.
I can't easily lay my hands on any PIC i want, i had to order the 16F from abroad, they're not available in my country so i'm stuck with the 16F877.

I get the gist about the cycle time now.

I guess i'll be transfering ASCII characters from PC to PC basically, just to see how the serial communication works although i might also need to send binary data in some cases because the chip i'm using with my PIC has a 24bit (8bytes) programmable register which controls the operation of the chip.

I read about the use of the TMR0 timer in RB4/TMR0 pin for software UART implementation, using the timer overflow interrupt and the two operation modes of the pin. i saw an application note on it at microchip. when i'm done with all these i'll post my code for "debugging" . thanks for all your help an advice i'll appreciate a whole lot more.
 
I guess i'll be transfering ASCII characters from PC to PC basically, just to see how the serial communication works although i might also need to send binary data in some cases because the chip i'm using with my PIC has a 24bit (8bytes) programmable register which controls the operation of the chip.

Perhaps you might have misunderstood me back there, 24bits = 3 Bytes because 1Byte = 8bits also 8Bytes = 64bits...

24 bits make 3 Bytes

Have fun!
 
I guess i'll be transfering ASCII characters from PC to PC basically, just to see how the serial communication works
Will you be using the PIC between the two remote PC's, just so they can exchange data.?
If yes, why is the PIC in the link.?


although i might also need to send binary data in some cases
You will have to set the UART's in the PC's to handle binary data as well as ASCII data.
Are you writing the PC's program.?


because the chip i'm using with my PIC has a 24bit (8bytes) programmable register which controls the operation of the chip.
What is this programmable register and whats it going to do.?

I read about the use of the TMR0 timer in RB4/TMR0 pin for software UART implementation, using the timer overflow interrupt and the two operation modes of the pin. i saw an application note on it at microchip. when i'm done with all these i'll post my code for "debugging" . thanks for all your help an advice i'll appreciate a whole lot more.

Hi,
If you are using ASCII and Binary transmission via the RS232 you should program prefix and sufix codes
to identify the start and end of a string.

If the data integrity is critical, you should use Parity and a CRC check code.

Tell us what the data is going to be.:)
 
Last edited:
sorry i understood the byte and bit stuff, i just made a mistake there. The aim of the project is simply to test the how well data can be transmitted over a power line. the data i send is not the problem. but i think i'll send ASCII characters just to see if i can send an "A" and receive an "A" on the other end. like i said i could also transmit single or byte data also not necessaritly ASCII, is there much of a diffrence so long as it is binary data?
 
Since i'm better on programming than analog electronics, i can give a little tip on this, well by convension, any String sequence is ended with an "invisible" character wich is the '\0', this is the same as the ASCII value 0, in other words, it means nothing LOL, you don't need to detect an String start because you know when it ends !
One last thing, this one last tip is used in a many protocols that use RS-232 as an transmittion channel, since you will send Strings, send all kinds of data as String, convert all numbers to Strings, that way it will be easy to decode and parse the values on the other side :)

One example of one know protocol that do things this way is the NMEA0183 for GPSs :)

(don't complicate something as simple as this...)

Have Fun !
 
sorry i understood the byte and bit stuff, i just made a mistake there. The aim of the project is simply to test the how well data can be transmitted over a power line. the data i send is not the problem. but i think i'll send ASCII characters just to see if i can send an "A" and receive an "A" on the other end. like i said i could also transmit single or byte data also not necessaritly ASCII, is there much of a diffrence so long as it is binary data?
hi,
From what you are saying, its just for demonstrating data transimission using the local power lines,
I would suggest ASCII coding would be easier to use as a starting point.
By using ASCII you will be able to use a simple program in your PC, something like the free version of Procomm,
there are lots of free Comms programs on the web.

Terminate the transmitted byte/character with a CRLF code, thats your data, then 0Dh and then 0Ah.
Some PC programs will wait for this CRLf before they display the data/string.

For the Binary data, intially use say 4800,N,8,1 the 8 is the width of the byte [number of bits that make the byte]
The PC program will have to be able to decode the binary data and print the corresponding character.
Note: byte from 0d thru 31d are control characters.

With Binary data transmission you cannot use CRLF as a terminator.
 
Last edited:
The power line modem IC is the ST7540 FSK modem.
It simply receives binary data, modulates it using the FSK modulation scheme and transfers the data over the power line. In receiving mode, the chip demodulates the FSK signal and recovers the digital signal, transmitting it back to a receiving PC or any device.

the problem is that the chip takes some time to analyse the FSK signal before it starts to demodulate it. within this time, some of the data modulates will be lost. this is why a preamble must be added to the actual data so that none of the data is lost. The technical suport from the manufacturer recormends about 2bytes of preamble to be sent with the data

so i need a microcontroller to manage the communication between the PC and the chip, not to mention the fact that it chip has a select pin that changes its mode from transmission to reception and well as a configurable register.

the register selects which kind of transmission mode, (Sync or Async), channel frequency, baud rate with which to expect incoming serial data and many other functions.

i already have a PC program to send ASCII characters over the serial port which i intend to use to test the power line interface.

so i guess thats it about the kind of data i'm using and why the preamble is needed.
 
The power line modem IC is the ST7540 FSK modem.
It simply receives binary data, modulates it using the FSK modulation scheme and transfers the data over the power line. In receiving mode, the chip demodulates the FSK signal and recovers the digital signal, transmitting it back to a receiving PC or any device.

the problem is that the chip takes some time to analyse the FSK signal before it starts to demodulate it. within this time, some of the data modulates will be lost. this is why a preamble must be added to the actual data so that none of the data is lost. The technical suport from the manufacturer recormends about 2bytes of preamble to be sent with the data

so i need a microcontroller to manage the communication between the PC and the chip, not to mention the fact that it chip has a select pin that changes its mode from transmission to reception and well as a configurable register.

the register selects which kind of transmission mode, (Sync or Async), channel frequency, baud rate with which to expect incoming serial data and many other functions.

i already have a PC program to send ASCII characters over the serial port which i intend to use to test the power line interface.

so i guess thats it about the kind of data i'm using and why the preamble is needed.

hi,
The preamble for the string is so that the FSK circuit can lock onto to the incoming FSK, you have answered this part.:)

You could try having a fixed length data string, say 2 bytes of preamble, 12bytes of data and CRLF, a total of 16 bytes.

In the PC program save all the received bytes in a string, get the length of the string, which may vary on how well the FSK locked on during the preamble.
You could use a ASCII Control code for the two pre bytes.

Use the right 14 bytes of data in the string as 'valid' data.

Which part do you require a more detailed explanation.?:)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top