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

Display time of Input pulse on LCD

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



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

Display time of Input pulse on LCD
PostPosted: Sun Aug 22, 2004 5:46 pm     Reply with quote

Hi..
I want to find out the time of a single pulse input
to the PIC16F877 and display it on LCD. I want to
count it on 16bit counter. I have the example
program: EX_PULSE.c that is given with CCS C PCM
3.202 compiler.

In the code of this file they have used timer0 of 8bit.
I have changed the same code for Timer 1. And apply the
external clock on port B1. When I connect the battery
it is displaying some values on LCD. After that I start
the input signal on port b1 but now this displayed value
does not change. If I apply the signal before to connect
the battery. It does not display anything.

My code is as follows..
---------------------------------------------------------

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#include <lcd.c>


void wait_for_low_to_high() {

while(input(PIN_B1)) ;/* if it's high, wait for a low */

delay_us(3); /* account for fall time */

while(!input(PIN_B1)); /* wait for signal to go high */
}

void wait_for_low() {

delay_us(3); /* account for rise time */

while(input(PIN_B1)); /* wait for signal to go high */
}

void main() {

// BYTE time;
long time;

set_tris_b(0xFF);

lcd_init();
delay_ms(6);

while(TRUE){

// setup_counters( RTCC_INTERNAL, RTCC_DIV_2 );
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);


wait_for_low_to_high();
// set_rtcc(0);
set_timer1(0); // start counting


wait_for_low_to_high();

//setup_timer_1(T1_DISABLED);
//time = get_rtcc();
time=get_timer1(); // get the time


printf(lcd_putc,"\fTime = %U ",time); //and print frequency
delay_ms(500);

}
}

------------------------------------
Any help appriciated........

Thanks...
Prashant
Guest
Guest







Display time....
PostPosted: Mon Aug 23, 2004 10:31 am     Reply with quote

Prashant -

What number do you see on the display? What does your input signal look like: how long high, how long low, etc? Can you send and display a constant number on your lcd to narrow it down to an lcd versus input issue? Could just be a wiring/connection issue, but can't tell based on this information....

Thanks!
Prashant Patel



Joined: 19 Jul 2004
Posts: 33

View user's profile Send private message

LCD value does not change sometime....
PostPosted: Mon Aug 23, 2004 3:14 pm     Reply with quote

Hi..

We are applying square wave input...
Actually I want to display the RPM of the input sinal.
Its range is 0 Hz to 500 Hz. I have tried the simplest
way like below. Now it is working. But if we keep the
same frequency for some seconds then after it does not
change the displayed value on the LCD.
What can be the problem..??
And When we connect the power suppy to the circuit, some
time it is displayed fine and some time it does not displayed
anything on LCD. We can see this time LCD activated.
This method is responding slow.
-------------------------------------------------------------
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#include <lcd.c>


void main() {

// BYTE time;
int time;
double frpm;

lcd_init();
delay_ms(6);

while(TRUE){

setup_timer_1(T1_EXTERNAL);

set_timer1(0); // start counting
delay_ms(1000);
time=get_timer1(); // get the time

frpm = 60.0*(float)time;

printf(lcd_putc,"\fRPM=%05.0f",frpm);

delay_ms(1000);

}//while(TRUE)
}//main
-------------------------------------------------------------
Thanks...
Prashant
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