|
|
View previous topic :: View next topic |
Author |
Message |
Herry Guest
|
probrem with detecting PWM width |
Posted: Tue Dec 14, 2004 3:11 am |
|
|
Hello everyone..
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
|
|
Posted: Tue Dec 14, 2004 8:39 am |
|
|
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 |
|
|
|
|
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
|