CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pic 16f887 and Srf04 ???

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

Pic 16f887 and Srf04 ???
PostPosted: Tue Apr 07, 2015 9:55 am     Reply with quote

Hello everybody
I have a project combine Pic 16f887 with 3 ultrasonic sensor (srf04) to detect object...Whether i can use features ext on-change RB0 interrupt and timer 1 interrupt ???
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 07, 2015 12:42 pm     Reply with quote

What driver are you using for the SRF04 ? Post a link to it.
We can look at the driver to see if it can tolerate interrupts.
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 2:49 am     Reply with quote

thank so much for your reply
actually i don't have a driver for srf04, I just use pic control srf04 like this page http://www.robot-electronics.co.uk/htm/srf05tech.htm
when i use pic with just one srf04 to measure distance, everything is ok... i use on-change b interrupt and timer 1.....But my problem is i want to control 3 srf04 by this way and i failure...whether i can use on-change b interrup for 3 srf04 and just one timer 1 to count time
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 3:10 am     Reply with quote

You're not giving us much to work on.

Please:-

1) Show (or describe) your schematic.
2) Explain how you are trying to use the three sensors.
3) Post some code.

Mike
talamahahahe



Joined: 15 Feb 2015
Posts: 39

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 5:51 am     Reply with quote

oh i fogot, sorry everybody
now, i will show use shematic and my code

like a picture srf04 have 4 pin, 2 pin for vcc and gnd, 2 pin for trigger and echo. i connect pin trigger of srf04 A to pin_C0,and srf04 B to pin_c1. pin echo of srf04 A to pin b0 and pin echo srf04 B to pin B1.
first,pic make a pulse >10us for pin trigger of srf04, srf04 will pull up echo pin...distance is a time when echo is high.
this is a timing diagram

and this is code....i use on-change RB and timer ,ì use 1 srf04,it's ok,...but when i use 2 srf04, it not run right

Code:

#INCLUDE <16F887_REG.C>
#INCLUDE <16F887_LCD.C>
INT16 DATA1=0,DATA2=0;

#INT_RB
VOID RB_ON_CHANGE_INTERRUPT()
{
   
   IF((INPUT(PIN_B0)==1))        {TMR1H=0;TMR1L=0;TMR1ON=1;}            //IF ECHO PIN OF SRF04 A GO TO HIGH THEN TURN TIMER1 ON
   ELSE IF((INPUT(PIN_B0)==0))                                          //ELSE IF ECHO PIN GO TO LOW THEN TURN TIMER1 OFF AND CALCULATE DISTANCE FROM DATA1
   {
      TMR1ON=0;
      DATA1=TMR1H<<8;
      DATA1=DATA1|TMR1L;
      DATA1=DATA1/58;
   }
   
   IF((INPUT(PIN_B1)==1))         {TMR1H=0;TMR1L=0;TMR1ON=1;}           //IF ECHO PIN OF SRF04 B GO TO HIGH THEN TURN TIMER1 ON
   ELSE IF((INPUT(PIN_B1)==0))                                          ////ELSE IF ECHO PIN GO TO LOW THEN TURN TIMER1 OFF AND CALCULATE DISTANCE FROM DATA2
   {
      TMR1ON=0;
      DATA2=TMR1H<<8;
      DATA2=DATA2|TMR1L;
      DATA2=DATA2/58;
   }
}

VOID MAIN()
{
   LCD_INIT();
   TRISB=0XFF;
   TRISC=0X00;
   IOCB=0XFF;
   GIE=1;PEIE=1;RBIE=1;RBIF=0;
   TMR1ON=0;TMR1CS=0;T1CKPS1=1;T1CKPS0=0;TMR1GE=0;
   TMR1H=0;TMR1L=0;
   WHILE(TRUE)
   {
      OUTPUT_HIGH(PIN_C0);                   //MAKE A FULSE TRIGGER >10US TO ACTIVE SRF04 A                           
      DELAY_MS(15);
      OUTPUT_LOW(PIN_C0);
     
      OUTPUT_HIGH(PIN_C1);                   //MAKE A FULSE TRIGGER >10US TO ACTIVE SRF04 B 
      DELAY_MS(15);
      OUTPUT_LOW(PIN_C1);

      LCD_GOTOXY(0,0);
      LCD_WRITE(DATA1/100 +0X30,1);
      LCD_WRITE(DATA1%100/10 +0X30,1);
      LCD_WRITE(DATA1%10 +0X30,1);
     
      LCD_GOTOXY(13,0);
      LCD_WRITE(DATA1/100 +0X30,1);
      LCD_WRITE(DATA2%100/10 +0X30,1);
      LCD_WRITE(DATA2%10 +0X30,1);
   }
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 7:37 am     Reply with quote

This is not very helpful.
Quote:
and this is code....i use on-change RB and timer ,ì use 1 srf04,it's ok,...but when i use 2 srf04, it not run right

1) Tell us what's going wrong.
2) What values you're expecting, and the ones you're getting.
3) Tell us what tests you've done.
4) What happens say if you just remove the pulse for sensorA but leave the detection part in place.
5) ................

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19457

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 7:46 am     Reply with quote

My guess would be cross pickup....

Think about it. He is showing all the sensors using interrupt on change on the single port, and all enabled.

When he triggers the first transmission, and waits, he will get a little later the other sensors picking up the outgoing pulse, and then all three picking up the return. You can't use multiple ultrasonic receivers like this. You have to disable the ones you don't want to use.

Feed the inputs from all three sensors, through a 4 to 1 line multiplexer. Connect the output from this to a single interrupt. Then select the unit you want to use using the multiplexer, pulse it's transmitter, and handle the return just as for a single unit. Then when this has been done, switch the multiplexer, and use the second unit, and so on.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group