Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 11th June 2008, 01:12 PM   (permalink)
Default project help

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.
ulot is offline   Reply With Quote
Old 11th June 2008, 01:17 PM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now   Reply With Quote
Old 11th June 2008, 02:08 PM   (permalink)
Default

thanks i'll work on that
ulot is offline   Reply With Quote
Old 11th June 2008, 02:32 PM   (permalink)
Default

Quote:
Originally Posted by ulot View Post
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
__________________
Best Regards,
Tiago Silva.
TiagoSilva is offline   Reply With Quote
Old 11th June 2008, 08:35 PM   (permalink)
Default

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
ulot is offline   Reply With Quote
Old 11th June 2008, 10:10 PM   (permalink)
Default

I don't know how this works, but feel free to add me some reputation :P
Keep us updated so that we may know what you have done and still need to do.
Have fun!
__________________
Best Regards,
Tiago Silva.
TiagoSilva is offline   Reply With Quote
Old 12th June 2008, 02:25 PM   (permalink)
Default 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?
ulot is offline   Reply With Quote
Old 12th June 2008, 02:26 PM   (permalink)
Default 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
ulot is offline   Reply With Quote
Old 12th June 2008, 02:33 PM   (permalink)
Default

Quote:
Originally Posted by ulot View Post
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? I don't think I did.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 12th June 2008 at 02:41 PM.
futz is online now   Reply With Quote
Old 12th June 2008, 02:37 PM   (permalink)
Default

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.
__________________
<-- Feel free to IM me for random chit-chat and PIC assembly talk
Adobe After Effects lets you save your work before it crashes, now THAT'S user-friendly.

Last edited by ArtemisGoldfish; 12th June 2008 at 02:41 PM.
ArtemisGoldfish is offline   Reply With Quote
Old 12th June 2008, 02:45 PM   (permalink)
Default

[quote=ulot;319105]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:
Delay Code Generator
, which PIC type.?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 12th June 2008 at 02:56 PM.
ericgibbs is online now   Reply With Quote
Old 12th June 2008, 09:29 PM   (permalink)
Default

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.
Diver300 is offline   Reply With Quote
Old 13th June 2008, 09:38 AM   (permalink)
Default 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.
ulot is offline   Reply With Quote
Old 13th June 2008, 11:45 AM   (permalink)
Default

Quote:
Originally Posted by ulot View Post
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!
__________________
Best Regards,
Tiago Silva.
TiagoSilva is offline   Reply With Quote
Old 13th June 2008, 12:01 PM   (permalink)
Default

Quote:
Originally Posted by ulot View Post

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.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 13th June 2008 at 12:01 PM.
ericgibbs is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
project ideas for final year project! AceOfHearts Electronic Projects Design/Ideas/Reviews 3 24th April 2007 05:42 PM
need suggestions on uni project. (mechatronics project) konzen General Electronics Chat 16 13th March 2006 11:56 AM
electronics project for btech mini project sujith123 Electronic Projects Design/Ideas/Reviews 4 23rd September 2005 11:28 PM
i need a project idea\concept for a 10 month project..... mackoy General Electronics Chat 3 21st February 2005 11:27 PM
biomedical project(electronic project) naguru Electronic Projects Design/Ideas/Reviews 1 2nd November 2004 11:07 AM



All times are GMT. The time now is 02:58 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.