PDA

View Full Version : Cascading two PICs together



shaiqbashir
- 18th May 2006, 17:46
Hi guys!

well! im using PIC16F84 in my robot system. What im doing is using two of them simultaneously. Now let me tell u that how i want to do this:

Supposing PIC # 1 is connected with my sensors, when sensors cause interrupt in it, it sends signal to PIC #2 and then the PIC#2 operates the motors connected with it.

I want to ask you that how can i program such a system.

I have one idea, i dont know whether its correct or not,

If i make coding in such a way that PIC #1 when gets interrupted it makes its one pin lets say portB.1=high and then make one pin of PIC #2 as an input to detect that high state of portB.1.

Plz tell me how can i program this:

i shall be thankful to u for this act of kindness.

take carez

Good Bye

sougata
- 21st May 2006, 16:55
Hi Shaig,

I don't understand why you want to use interrupts on the first PIC and then let the second one detect it. Please elaborate it.

sayzer
- 22nd May 2006, 05:57
Also, why don't you use one F877 instead of two F84s?

What is the idea behind having two PICs? Are they far away from each other?


----------------------------------------

shaiqbashir
- 24th May 2006, 02:04
very sorry for making a late reply. well here is the scenario in which i want to use this cascading.


I have made a robot in which there will be two drive wheels, each supported by a separate DC motors. So in total there will be two DC motors for TWO drive wheels. I want to control each of them through PWM. SO that i can control their revolutions. Like if i want my right wheel to take 3 revolutions and then stop, i can do that with the help of command of PWM:

PWM portB.0, 250, 100

the no of cycles i can vary to get the desired revolutions. Isnt it so?


Now i have certain other things to operate in my robot as well. Like running other motors from time to time. Lets say i have to lift a ball up while my robot is moving towards the target basket. SO it means that i have to use certain parallel processing. While PIC16F84A can allow u to have sequential processing only. SO that is the reason why i want to use two PICs simultaneously. Here is what my mind is saying to me: plz check it out:


PIC#1 connected with two Drive motors
PIC#2 connected with two white line tracking sensors, one lifter motor, two solenoids for closing and openeing some windows.


Both pics are PIC16F84A.

Now what i want to do is like this

PIC#1 starts functioning, there is a point B on the white line which i have to detect, so wheels start moving straight and when it reaches point B, the PIC#2 gives the signal to PIC#1 that i have detected the point B. The PIC#1 gets interrupted due to this signal and then wheels now stop moving straight and PIC#1 jumps to a new programming routine. Then PIC#1 will signal the PIC#2 that lift the balls up. PIC#2 will recive the signal and start the motor connected with it to lift the ball and all this.....


I hope u r getting my point. Now please tell me any solution with some examples that how can i do it. I shall be very very thankful to u for this act of kindness. And one thing more, that i have a very very short time left for the competition so please make ur replies as quickly as possible.


I thank u very very much in anticipation.

take carez

Best REgards

mister_e
- 24th May 2006, 02:19
personnally i would prefer to choose a single PIC with two internal PWM channel and simply poll the sensor. That will just make things really really easy. Internal PWM module run in background. You start HPWM and then you can do anything else without causing any problem to the PWM signal... this isn't the case with software PWM. Even your task is possible with a single PIC without any internal PWM module like the 16F84 or else other... it's just a bit much tricky.

As they're not much expensive than the 16F84 AND add much fun, PIC16F873, 16F876,18f242,18f252,18f2220,18f2320 and tons of other could be choose.

As i can't know all PIC in the whole world but just those i use(d), you can also look at the microchip website and do a search for a PIC with 2 internal PWM module ( also called CCP )

my 2 cents.

shaiqbashir
- 24th May 2006, 03:30
Thanks for ur precious helo Mister.

but one reason that is just stopping me from using this sorts of PICs is this that i donot know how to program HPWM in the way in which i want.


Lets take an example. Im programming in COde Studio rite..

I know that there is a command in it called HPWM in which u have to specify the channel, the frequency and duty cycle. Rite?

Now there are two things which i donot know how to make:


1) there is no "cycles" option given, so how im going to control the revolutions by specifying the cycles as i wass doing it in PWM command.

2) During my whole operation, i have to stop the motors, run the motors with variable speed and then stop and all that. SO can u plz give me an example of coding with HPWM.


I know using HPWM is highly effective but i request u to provide me with some code examples so that i can fully understand how to do it. Please use COde studio in ur examples.

I shall be thankful to u for this act of kindness.

take carez

Good Bye!

mister_e
- 24th May 2006, 14:08
interesting point. But let's assume 1KHZ a frequency. a cycle should be 1mS right?



HPWM 1,127,1000
pause 1 ' one cycle
pause 1 ' two cylce
pause 1 ' three cycle
CCP1CON=0 stop PWM


rought and nasty example. Now you have to implement your tests during those cycles.. mmm


HPWM 1,127,1000 ' Start Motor1
Hpwm 2,127,1000 ' Start Motor2
For Msec=0 to 300
PauseUS 10 ' 10uSec * 300 = 3mSec = 3 Cycles
If SensorX=Something then Doplahplah
If sensorY=Somethingelse then DoAnotherPlahPlah
next


But there's some other way to use only High/LOW on specific Motor pins then using Pause/Pauseus (or loop of) to do the same thing and do your test within a loop.



For Msec=0 to ((Cycle*100)*2)
Toggle Motor1
Toggle Motor2
PauseUS 5
If sensor...
If sensor...
next

This will create a 50% duty cycle 'PWM' of a XCycle

Should be something to play 'round.

Now, if it was me, i would use HPWM to generate both signal to the motor, then use 2 sensor to monitor the revolution of the wheel using interrupts or internal counter. It add flexibility and also if a motor is burn or else, you'll be able to know it.

shaiqbashir
- 24th May 2006, 15:17
That was just tremendous Mister.

Im very very thankful to u for this.

Now im getting that this is really possible to control the cycles in HPWM.

Now i have some important questions prevailing in my mind rite now.Hope u would not mind answering them.


HPWM 1,127,1000 ' Start Motor1
Hpwm 2,127,1000 ' Start Motor2
For Msec=0 to 300
PauseUS 10 ' 10uSec * 300 = 3mSec = 3 Cycles
If SensorX=Something then Doplahplah
If sensorY=Somethingelse then DoAnotherPlahPlah
next


About this coding, i want to ask u that no matter that our sensors will be working while the motor is runnig. But if we take the scenario apart from my sensors. and come towards running a third motor in between then what would u say???

I mean that this is the scenario:

my both motors are running with HPWM command, let us suppose they are made to make 3 revolutions.


now in between those three revolutions, if i want to run a 3rd motor (not thru HPWM) so how i would be using this??????

I mean should i use it like this that



HPWM 1,127,1000 ' Start Motor1
Hpwm 2,127,1000 ' Start Motor2
For Msec=0 to 300
PauseUS 10 ' 10uSec * 300 = 3mSec = 3 Cycles
If SensorX=Something then Doplahplah
If sensorY=Somethingelse then DoAnotherPlahPlah
next
CCP1CON=0 'stop PWM 1
CCP2CON=0 'stop PWM 2

HPWM 1,127,1000 ' Start Motor1
Hpwm 2,127,1000 ' Start Motor2
For Msec=0 to 300
PauseUS 10 ' 10uSec * 300 = 3mSec = 3 Cycles
pwm portB.0, 127, 2000 ' run the motor connected on portB.0 with pwm
next
CCP1CON=0 'stop PWM 1
CCP2CON=0 'stop PWM 2





Now what im saying that dont u think that it is working still sequentially.

I think im just unable to make u understand thru coding that what im trying to make. Because im still in the process of learning.

I can present to u a scenario.

here it is:

I HAVE PROGRAMMED MY BOTH DRIVE MOTORS TO TAKE THREE REVOLUTIONS. NOW DURING THESE THREE REVOLUTIONS I WANT TO START A THIRD OPERATION LETS SAY STARTING A THIRD MOTOR WITH NORMAL PWM COMMAND. hOW I WILL DO THIS?

if u will post a code example, i shall be able to understand it quickly and will be greatly thankful to u.

Thanks in advance!