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

probrem with detecting PWM width

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







probrem with detecting PWM width
PostPosted: Tue Dec 14, 2004 3:11 am     Reply with quote

Hello everyone.. Very Happy

Now I would like to detect PWM width without use CCP1 and CCP2

my plane is use hardware to detect ..

when input(PIN_A0)=1 // high-->set_timer1(0)

then....

input(PIN_A0)=0// low-->get_timer1

one PWM period is 10ms

but can't work.....It seems something wrong on my code...

plz help me to check....thank you very much

-------------------------------------------------------
#include <18f458.h>
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=16000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,stream=hostpc)
#use fast_io(A)

int width;

main()
{
setup_timer_1(T1_INTERNAL);
set_tris_a(0xff);

while(input(PIN_A0))
{
set_timer1(0);

while(input(!PIN_A0)) // wait signal until fall
{
width=get_timer1();
printf("pwm with is %d \n\r",width);
}
}

}
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Tue Dec 14, 2004 8:39 am     Reply with quote

Try this...
Code:

Main() {

   set_tris_a(0xFF);
   setup_timer1(T1_INTERNAL);
   
   while (TRUE) {
      while (!input(PIN_A0)) // wait for high
         ;

      set_timer1(0); // restart timer
      while (input(PIN_A0)) // wait for low
         ;

      width = get_timer1();
      printf("pwm width is %d \n\f", width);
   }

}



_________________
David
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