connect two pics


Closed Thread
Results 1 to 29 of 29
  1. #1
    Join Date
    Jun 2006
    Posts
    14

    Default connect two pics

    Hi to the forum!

    I already searched the forum about how to connect two pics, i found that many ppl suggesting using serin2 and serout2 commands.

    Iam builiding a robot for avoiding obstacles. One PIC16f877a is used for collecting data(actually the voltage is changing) with a/d channels from a sharp IR sensor and display them on a lcd, I want when the sensor gets a minimal voltage value (indicating the robot is close to an obstacle) then the second PIC 16f84 become active (with a l293d chip) to make the dc motors moves the way I want.

    Is there a simpler way to just make the second PIC enable for some minutes to just run the program with the dc motors, and then become inactive again without serial communication?

    I know the simplier solution is to put everything on PIC 16f877a but for some strange reason the big PICs dont work well with l293d and dc motors only the smaller ones like pic16f84 or pic16f628 do thats why i need 2 pics.

    Any help will be very much appreciated.

    Thank you very much.
    Last edited by soki; - 19th September 2008 at 15:09.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    SERIN or SERIN2 is about as simple as it gets.

    Why do you not want to use it?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Find the root cause

    Hi,

    You might want to find out why the big PIC doesnt want to work properly. Do you have a nice and clean supply voltage (or do you get spikes when you start and stop the DC motors)?

    Do you have enough power at all?

    Do you have capacitors close the the power pins of the pic?

    Do you have brown out enabled?

    PCB or a ball of soldered wires?

    X-tal, RC or external oscillator?

    I would reccomend you to try to solve this issue and then you would get a much easier project. There must be a reason for this so I think we keep the 2 pic design as Plan Z.


    What do you mean with "it doen't work well"?
    /me

  4. #4
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Thank you for your replies.

    When I say it doesnt work well I mean when I make a program for big PICs and I want for example rotate one dc motor right then pause 2 sec then rotate left pause 3 sec etc, it just dont work or work wrong, for example it will rotate only right and then stop working at all or if its a big loop it maybe stop in the middle of the program.With small pics it works like champion.


    Are there some examples with serial communication? I tried to find the "sixpics" project someone mention but there isn't in melabs program examples.

    Thank you very much.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by soki View Post
    When I say it doesnt work well I mean when I make a program for big PICs and I want for example rotate one dc motor right then pause 2 sec then rotate left pause 3 sec etc, it just dont work or work wrong, for example it will rotate only right and then stop working at all or if its a big loop it maybe stop in the middle of the program.With small pics it works like champion.
    Quite frankly, to me, that just doesn't make any sense. But, I'll bet, I'd just bet, if, and only if, you posted the code that you used in both PICs, the one that worked and the one that failed, you might, just might, get a quick answer as to why one works and the other one seems to fail.
    But that would be just too easy...

    Are there some examples with serial communication? I tried to find the "sixpics" project someone mention but there isn't in melabs program examples.
    Ya know what works for me?
    Typing 'Serial Communication between 2 PICs' in the Search box.
    Crazy how that works ain't it?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I agree with Jumper, find the problem.
    Maybe post the problem code??

    SERIAL-- really simple example . Much more to add, but the basic idea.
    SEND
    Code:
    SEROUT2, PORTX.X, MODE,[DEC 9]
    RECEIVE
    Code:
    SERIN2, PORTX.X, MODE,[DEC VAR]
    IF VAR = 9 THEN LABELX
    Last edited by mackrackit; - 19th September 2008 at 15:07.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default 877A doh :-)

    If you have connected anything on PORTA and you dont get the results you want.... this one I leave for Melanie to answer if needed :-)

    Show us your HW setup and some code, it should not be rocket science to rotate a DC motor with the 877A.

    So dont give into Plan Z just yet.

    /me

  8. #8
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    The program I put in both small and big pics are the same,not different programs! On small pics it work on big not well!

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by soki View Post
    The program I put in both small and big pics are the same,not different programs! On small pics it work on big not well!
    And there are hardware differences between the two PICs...
    Is there some reason why we shouldn't see your program? State secret or something?

  10. #10
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default The bigger PIC

    The bigger PIC has tons of nice functions and these needs to be disabled/enabled/taken care of/set up/deactivated......etc

    So tell us what you have connected where and all your regiter settings.. TRIS ADCON etc if you think your code it too big/secret to post here.

    But if you insist of doing a 2 pic project feel free. And if you do that.. why use serial communication when it should be enough to use 2 pins as input on the small pic... as long pin-xx is high rotate left, if pin-yy is high rotate right...

    but... naaah.... if you already have code working for a small pic... what PIC is that? It cant be a 16F84 since that has no A/D....

    the plot thickens

    /me
    Last edited by Jumper; - 19th September 2008 at 15:58.

  11. #11
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    You guys are great and have humor!

    Thank you for your answers!

    How wrong I can be with that simple program?

    TRISB = 0 ' PORTB is output
    PORTB.0 = 1 'enable1 of L293d is always high so input 1 and input 2 are available
    start:
    PORTB.1 = 1 'input1 of l293d goes high, so output 1 goes high so turns left
    PORTB.2 = 0 'input2 of l293d goes low, so output 2 goes low so turns left
    pause 2000
    PORTB.1 = 0 'the opposite, turns right
    PORTB.2 = 1
    pause 3000
    PORTB.1 = 0 'stop the dc motors
    PORTB.2 = 0
    goto start 'loop
    Last edited by soki; - 19th September 2008 at 16:34.

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    So what's the problem?

  13. #13
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    And the schematic, the l293d is also connected right(ground,vs,vss) but not shown on this schematic
    Attached Images Attached Images  

  14. #14
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    So what's the problem?
    not work well the last time I checked, and believe me I tried many times.

  15. #15
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default so..

    You say you have 2 pics, one small and one big and then you use the same code in both. In the small pic everything is dandy but with the 877A it is not working properly.

    the code.... I agree.. what can go wrong... so the answer is probably not in the lines you posted.

    What FQ do your run the pics on, and where do you get this one from?
    Maybe DEFINE OSC XX in the beginning could help ....

    Configurations bits... a long story.. and the bigger the pic.... the longer the story.. the best way to set configuration bits is by adding them to the code. How this is done depends if you use MPASM or not. Search the forum and add these bits into the top of your program... These have a significant effect on the pics behaviour.

    OSC XT HS RC LP
    Watchdog on off
    Brown out or not
    etc etc.. add all config bits you have for the device in the code

    all these you can find in the datasheet....


    And you still didnt answer how you power the pic and if you have caps close to the power pins.



    /me
    Last edited by Jumper; - 19th September 2008 at 16:57.

  16. #16
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    I will try again today to connect directly l293d with the pic1678777a, the available ports left are portC and portD, which one to use? Should I take care extra something? I can give seperate voltage to l293d from a different +5V source.

  17. #17
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Good

    OK,

    more questions... your 9V battery. What kind is that? Is that the normal small flat one or something with some real juice in?

    How many mA does the motor take in start up current?

    Nothing wrong with PORTB, this is a different problem.. but please power the L293D separetly. Add config bits to make sure at least brown out off and watchdog off.

    /me
    Last edited by Jumper; - 19th September 2008 at 17:03.

  18. #18
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Jumper View Post
    You say you have 2 pics, one small and one big and then you use the same code in both. In the small pic everything is dandy but with the 877A it is not working properly.

    the code.... I agree.. what can go wrong... so the answer is probably not in the lines you posted.

    What FQ do your run the pics on, and where do you get this one from?
    Maybe DEFINE OSC XX in the beginning could help ....

    Configurations bits... a long story.. and the bigger the pic.... the longer the story.. the best way to set configuration bits is by adding them to the code. How this is done depends if you use MPASM or not. Search the forum and add these bits into the top of your program... These have a significant effect on the pics behaviour.

    OSC XT HS RC LP
    Watchdog on off
    Brown out or not
    etc etc.. add all config bits you have for the device in the code

    all these you can find in the datasheet....


    And you still didnt answer how you power the pic and if you have caps close to the power pins.



    /me
    See the schematic attachment about how I power the PIC. I will try those configurations bits! Thanks!

  19. #19
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default Yepp

    Try to add caps (2* 0.1 uF) close to the power pins on the pic (one on each side).

    and was it a regular 9V battery or something more powerful?

    /me
    Last edited by Jumper; - 19th September 2008 at 17:34.

  20. #20
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Oh ya...
    If that's a regular ol' 9v battery (little flat one like Jumper said), that isn't going to work well at all, at least not for very long.
    Dropping the operating frequency of the PIC might help.
    And of course, as Jumper said, put extra cap's everywhere.
    Your PIC16F877A is probably brown-out resetting every time you start moving a motor (or maybe one motor or both or whatever). The smaller PICs might be a bit less sensitive to power dropoffs, or maybe they're LF versions whereas the '877A isn't an LF version.
    Who knows...
    One thing I do know is that the schematic shown above could use a bit of redesign to make it more reliable.

  21. #21
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Help guys Iam starting loose hair for this project

    I think the problem must be the normal 9V battery, what I can use as alternative? Will be an alcaline 9V battery or something else be better choice. I notice also in LCD screen somehow the 2 power sources (9V battery and the 4x1.5V AA batteries are interfacing) maybe is the L293D drive chip to blame and try another one?

    I also replace resonator 4mhz with crystal 4mhz with 33pf capacitors so can be more accurate. I also defined osc 4 in program. I also use pbp247 compiler and mpasmwin520 assempler(this is from Compile and Program Options) and I use an usb programmer I bought on ebay with the following settings when I program the chip the watchdog is disabled (see the first attachment).

    I connected l293d chip successful with RC ports so to have only one chip, but my problem is that after some loops the circuit stop working!

    See the complete schematic in the second attachment. Please help me to do it more reliable!

    The code of the program is:


    DEFINE OSC 4
    DEFINE LCD_DREG PORTB ' LCD Data bits on PORTB
    DEFINE LCD_DBIT 0 ' PORTB starting address
    DEFINE LCD_RSREG PORTB ' LCD RS bit on PORTB
    DEFINE LCD_RSBIT 5 ' LCD RS bit address
    DEFINE LCD_EREG PORTB ' LCD E bit on PORTB
    DEFINE LCD_EBIT 4 ' LCD E bit address
    DEFINE LCD_BITS 4 ' LCD in 4-bit mode
    DEFINE LCD_LINES 2 ' LCD has 2 rows
    '
    ' Define A/D converter parameters
    '
    DEFINE ADC_BITS 8 ' A/D number of bits
    DEFINE ADC_CLOCK 3 ' Use A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    Res Var Word ' A/D converter result
    Volts1 Var Word ' First part of result in mV
    Volts2 Var Word ' Second part of result in mV
    '
    ' Constants
    '
    Conv1 Con 19 ' 5000/256 = 19.53, this is the decimal part
    Conv2 Con 53 ' This is the fractional part
    TRISA = 1 ' RA0 (AN0) is input
    TRISB = 0 ' PORTB connected with lcd is output
    TRISC = 0 ' PORTC connected with l293d is output
    PORTC.0 = 1 ' l293d enable1 high
    PORTC.3 = 1 ' l293d enable2 high
    PAUSE 1500 ' Wait 1.5sec for LCD to initialize
    '
    ' Initialize the A/D converter
    '
    ADCON1 = 0 ' Make AN0 to AN4 as analog inputs,
    ' make reference voltage = VDD
    ADCON0 = %11000001 ' A/D clock is internal RC, select channel AN0
    ' Turn on A/D converter
    LCDOUT $FE, 1 ' Clear LCD
    AGAIN:
    '
    ' Start A/D conversion
    '
    ADCIN 0, Res ' Read Channel 0 data
    Volts1 = Res * Conv1 ' Multiply by 19
    Volts2 = Res * Conv2 ' Multiply by 53
    Volts2 = Volts2 / 100
    Volts1 = Volts1 + Volts2 ' Result in mV
    IF Volts1 > 1800 THEN DOKIM
    LCDOUT $FE,2,"V = ",DEC4 Volts1 ' Display result
    PAUSE 1000 ' Wait 1 second
    GOTO AGAIN ' Repeat
    DOKIM: ' move one dc motor for testing
    PORTC.1 = 1
    PORTC.2 = 0
    PAUSE 3000
    PORTC.1 = 0
    PORTC.2 = 1
    PAUSE 3000
    PORTC.1 = 0
    PORTC.2 = 0
    GOTO AGAIN
    END
    Attached Images Attached Images   

  22. #22
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    -Get rid of that 9v battery and make up another battery pack. Get a bunch of NiMH AA's and make another battery pack, anything but that stupid 9v battery.

    -Put decoupling cap's across Vdd and Vss on the PIC.

    -Turn off the brown out detect on the PIC in the config fuse options.

    -4Mhz osc - accuracy isn't going to help here. As long as it runs, it should be good.

    -USB programmer from eBay - spend the money and buy a PICKIT2. You'll be happier in the long run.

    -One power supply for the PIC, one power supply for the motors - good idea.... Separate grounds, not a good idea. Connect the grounds together.

    -Put low value inline resistors on the lines between the PIC and the L293D.

  23. #23
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Thumbs up

    Thank you skimask for your suggestions. I will try them! Thanx again!

  24. #24
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello soki,
    Read and understand this thread:
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    I think life will get easier for you if you do.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  25. #25
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Thanx Joe, I will read it

  26. #26
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Ok I changed the battery pack and already work well!

    For inline resistors 500 ohm will be ok?

  27. #27
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Smile

    Ok guys it finally works! I replace 9V battery with 6xAA battery pack all circuit use that power source, I put 500 ohm inline resistors between PIC and L293D and a 0.1uF decoupling capacitor across Vdd and Vss.

    Thank you all for your great help!

  28. #28
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by soki View Post
    Ok I changed the battery pack and already work well!
    Now you know all about internal impedance of a battery....

    For inline resistors 500 ohm will be ok?
    For situations like this, start high and work down, until something either works reliably and/or blows up.

  29. #29
    Join Date
    Jun 2006
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Now you know all about internal impedance of a battery....


    For situations like this, start high and work down, until something either works reliably and/or blows up.
    Thanks God it works fine from the start and nothing blowed up!

Similar Threads

  1. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  2. Retrieving infos from multiple PICs on a bus/chain
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th October 2007, 04:42
  3. connect 2 PICs
    By drama in forum mel PIC BASIC
    Replies: 1
    Last Post: - 4th October 2007, 16:55
  4. Multiple PIC's with 1 crystal
    By puma in forum Schematics
    Replies: 11
    Last Post: - 20th March 2007, 17:02
  5. Replies: 5
    Last Post: - 20th August 2006, 23:09

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts