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 CCS Technical Support

Will this work?

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



Joined: 27 Sep 2008
Posts: 22

View user's profile Send private message

Will this work?
PostPosted: Sat Jan 16, 2010 12:13 pm     Reply with quote

Hello everyone,

My 'C' is rusty. I need to set a signal and wait for a response. Here is my function:
Code:
void getSonar (void)
{
   output_high(TRIGGER);  //Initiate the Sonar sequence
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_2); //Start counting, 0.4uS tick time
   while (!echo_rcvd){}  //Wait for echo
   printf("Range = %lu inches\n\r",range/185);  //Print range
   //Need to check if 185 is the right number; not so sure.
   output_low(TRIGGER);
   
   
}


Its the While statement I'm not sure about. Do I need the braces? I have the ECHO line tied to RB5 as in IOC. The ISR will SET 'echo_rcvd' to TRUE'
I'm running this on a PIC16F882, compiler 4.093.

Thanks,
Duane
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 3:03 pm     Reply with quote

You should do the setup timer routine at uC init not in this function. In the function you just call set_timer1(0);

while (condition) {} <--- Is OK, it just waits in that spot until your condition is met.
Core2



Joined: 27 Sep 2008
Posts: 22

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 5:21 pm     Reply with quote

Thanks for the info. Will move the Timer setup.

What command actually makes the timer start?


Duane
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 5:52 pm     Reply with quote

Core2 wrote:
Thanks for the info. Will move the Timer setup.

What command actually makes the timer start?


Duane
Timer will be running all the time, you'll just set the timer1 to 0 with that command. So you'll be able to get time measurement.
Core2



Joined: 27 Sep 2008
Posts: 22

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 6:01 pm     Reply with quote

Gotcha. Thanks!
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