Connecting two PICs to each other?

dchapma1

New Member
Hi all,

I am new to this forum but not new to micros - just PICS. All previous experience was with the Parallax stamp but they are simply too expensive.

So a basic question about connecting two PIC 18X chips together. Pic 1 will be an infrared receiver and will place values it receives from the remote on its outputs 0 - 6. Pic two will read those data lines after it gets a data strobe using an interrupt.

Question 1
My basic question is: Can I directly connect the pins of PIC 1 to PIC 2 without any pull up/down resistors or current limiters?

Question 2:
Do unused I/O pins need to be pulled up/down or can they float?

Thanks
 

kranenborg

Senior Member
Hello,

Let me first answer the questions directly, and then make a remark about your setup.

Ans1: In general, you can connect two picaxe i/o pins directly if at least one of them is always defined as an input. The PICAXE-18X has a predefined layout with fixed inputs and outputs so that will work in this case. However be aware that most picaxes have flexible I/O pins and thus there is always the risk that two outputs get connected (for example, you may make a mistake when programming). If then one output is low and the other gets high a short-circuit situation occurs destroying both output ports immediately. Therefore it is often wise to include a 1k resistor for safety reasons.

Ans2: Unused outputs can be left floating. Formally it is not needed to tie unused inputs to ground, however due to EM field pickup the inputs will see fast switching high and low levels (50Hz) and thus the power consumption will increase rapidly (more than 200uA, see also the following discussion: http://www.picaxeforum.co.uk/showthread.php?t=2292).

You indicate that you want to let the 18Xes communicate using a parallel approach with strobing using a separate interrupt. I would highly recommend a serial approach instead (and the 18X does not have 7 inputs, so your approach is not feasible here). The best approach is to use hippy's "serial interrupts" (http://www.hippy.freeserve.co.uk/picaxesi.htm) approach which uses a single pin for both interrupting and subsequent serial communication. Many on this forum use this approach very often and it frees up many i/o pins for other use.

A last tip: Don't forget to tie the reset input high (because of Ans2) !

Good luck and keep us informed

/Jurjen
 

dchapma1

New Member
Thanks for the reply. I did read through all three manuals but it never really indicated whether the I/O pins needed clamping like the stamp does. Although basic good practice.

I have the infrared working just fine. It is to bad that the infrain command just sits there and waits for a signal. Ideally the infrain command would set up an interrupt so the PIC could go on doing other things then gosub when it get an infrared signal.

Hmmm, now that I think about it, could I set up an Interrupt on the infrared pin and have it the gosub to read the IR? Something like this:

18X Picaxe


Set interrput on input pin 0
Go about doing other things
Incoming IR triggers the interrupt
gosub where the first command in the sub is infrain
read the IR and go do something else
return
reset the interrupt.

Anyone tried anything like this?

Just read the second reply. Thanks for the good tips!
 
Last edited:

kranenborg

Senior Member
Hello,

Setting an interrupt on the infrared input pin has crossed my mind earlier also but I don't think it will work; there are many other sources of IR light that will trigger the IR receiver to generate the interrupt, and then the INFRAIN2 command will wait again until a true command has been received (note however that the newest picaxes (28X1/40X1) have an IRIN command with time-out which should make the approach feasibe, as long as the IR transmitter repeats sending IR messages several times, as most remote controls do).

A very useful approach is then to use a distributed processing approach using a cheap extra PICAXE-08M controller to do the IR command reading for you (exactly like you do now with your 18X). Best order a five-pack of them directly because they are so extremely flexible, small and useful.

I would highly recommend to go through hippy's Q&A webpage (http://www.hippy.freeserve.co.uk/picaxeqa.htm) in detail, as it is a true goldmine of ideas and applications that are not in the PICAXE manuals. You will find also the 08M idea in the IR interfacing section.

/Jurjen
 

SD2100

New Member
Just watch for stray IR causing an interrupt then it will hang on the infrain.

You can use IRIN on the 28x1's witch have a timeout
 

dchapma1

New Member
Great. I iwll use an 08 as the receiver and serial over to the secondary PIC using the Serial Interrput example.
 

kranenborg

Senior Member
Some final tips:

You may want to first test the 08M IR functionality separately using an extra SERTXD command after you trigger the interrupt and send the serial command to the intended output port (do use a short pause (maybe 10ms may suffice) between the interrupt triggering and the SEROUT command to allow the receiving PICAXE to handle the interrupt properly before it starts to wait for the serial message).

If tested properly you can use the 08M in your system without a separate download circuit, just pull the 08M SerialIn input low.

/Jurjen
 

kranenborg

Senior Member
A last remark, really,

In serial interrupts applications as proposed by hippy I have verified that a pause of only 8ms between the interrupt triggering and serial message output (SEROUT) is sufficient for proper operation (I use this value in the network stacks of my SerialPower network concept when a message is put on the network, http://www.picaxeforum.co.uk/showthread.php?t=7694). Hippy used a 20ms pause but correctly indicated that this pause may be shorter if proven by experimentation.

/Jurjen
 

adub

New Member
Great. I iwll use an 08 as the receiver and serial over to the secondary PIC using the Serial Interrput example.
Using an interrupt to jump to infrain2 on an 08m works fine. In my house at least.

A Sony remote is modulated and using an IR rx module (38kHz) I was able to make a small tank steer robot using two servos modified for continuous rotation as motors. It was fun.

Would have taken pictures and post it but the new forum hadn't been put up yet.

Code:
#rem

                    Picaxe 08M
                     .-- --.
                +V -o|1 U 8|o- 0V
         Serial In -o|2   7|o- Output0/Serial Out/Infraout
     In4/Out4/ADC4 -o|3   6|o- In1/Out1/ADC1
    Input3/Infrain -o|4   5|o- In2/Out2/ADC2
                     '-----'

#endrem
#picaxe 08m
symbol lmotor     = 1
symbol rmotor     = 2
'symbol LastInfra = b3
dirs = %00010110
setint %00000000,%00001000 ' low on pin3

b0 = 0

main:
  pause 100
  ' other code can continue 
  ' while the interrupt will 
  ' handle remote control functions
goto main

interrupt:
  infrain2 'wait for new signal - on Input3 only on 08M
'  sertxd("LastInfra=",#LastInfra,"  infra=",#infra,13,10)

' lastInfra allows you to check for previous button push
' and not have to make a change to the current action if
' its the same as the previous button push.
' lastInfra = infra

 select infra
  'MY Sony Remote Control
  ' case 20 ' mute
  '   toggle 4
  '   pause 250
    case 101,21,11  ' power...only turns off the motors
      high rmotor,lmotor ' all stop
    case 116 ' Menu +
      high 4:servo rmotor,200:servo lmotor,80 ' full forward
    case 117 ' Menu -
      high 4:servo lmotor,200:servo rmotor,80 ' full back
    case 16 ' channel +
      servo lmotor, 80:high rmotor ' left forward
    case 17 ' channel -
      servo lmotor,200:high rmotor ' left back
    case 18  ' volume +
      servo rmotor,200:high lmotor ' right forward
    case 19  ' volume -
      servo rmotor, 80:high lmotor ' right back
  endselect
  pause 100 ' allows me to take my finger off the button
  setint %00000000,%00001000 ' low on pin3
return
 

kranenborg

Senior Member
Hi,

I have tested Arvin's suggestion (i.e. infrain after interrupt generated by an IR signal, or in other words, no waiting for infain needed) on a project that I had available, namely the light-seeking microbug with brains (http://www.picaxeforum.co.uk/showthread.php?t=8122).

It appears that "false interrupts" (i.e those that are not generated by the remote control as intended) are created only if fluorescent tubes or energy saving lamps are either switched on or off. Normal (old-fashioned) bulbs and halogen lamps (and probably other lamps with a glow wire that need some time to change their intensity during switching) do not generate an interrupt with switching. With the lamp continuously on, no false interrupt is created, whatever the lamp type and the distance between the lamp and the IR receiver.

If a false interrupt has occurred, using the remote control always functions in order to proceed. Thus it may be useful to define a no-operation key (or any key that is not used for a specific function) on your RC in order to handle the false interrupt without any consequences and return to the main body immediately. Note that the iR receiver generates a low-level interrupt.

Thus, depending on the requirements you have on the project, it may actually be feasible to do it all with a single picaxe. Thanks Arvin for bringing up the issue.

/Jurjen
 
Last edited:

BCJKiwi

Senior Member
@Arvin

Would you please advise how you made your code post as you have managed to retain formatting which I have not mastered

Thanks.
 

dchapma1

New Member
This has been an interesting conversation and I have learned a lot in a short time due to it.

Experimenting last night and I have the whole thing working using two PICs. Today I will try doing it on 1 pic and see what happens.

This first project is to control all the lights on a large scale model of the Enterprise from Star Trek. Not too exciting but I have never seen one of these models controlled by a remote. All examples I can find have switches or all the lights on at once. It is a large model, 1 meter long, .5 meters wide and will take me a long time to complete but I wanted to get all the electronics designed before starting it.

I'll keep you posted on the single chip method.

Thanks
Don
 

BCJKiwi

Senior Member
@Hippy,
That's what I do but I don't get ascii art or other indentation or spacing as tabs or multiple spaces are all dumped when you post. You can go back and edit afterward but apart from it being very tedious the font is not fixed in the forum editor so nothing really lines up properly.

Have I missed some settings somewhere for the forum/editor? the same thing happens if I compose the post in a text editor with a fixed width font - it just gets changed when posted.
 

hippy

Technical Support
Staff member
I create my ASCII art and code in Notepad or more usually an MS-DOS Editor which uses fixed-space fonts and automatically converts tabs to hard spaces. Open the .TXT file then cut and paste to between the code tags.
 
Top