|
|
View previous topic :: View next topic |
Author |
Message |
Jean Paul Guest
|
I need help |
Posted: Thu Nov 14, 2002 8:13 am |
|
|
Hi
someone can tell me the possible errors in my code.
my code is for pwm with pin b0 and pin b1 I change the duty cyle
of the pwm. the problem is that I cand view the changes in my scope. I dont know the reason.
thanks
my code is:
#include <16F877.h>
#use delay(clock=1843200)
#fuses XT,NOWDT,NOPROTECT
main() {
long value;
byte data;
SET_TRIS_B( 0xFF );
setup_timer_2(T2_DIV_BY_16,239,1);
setup_ccp1(CCP_PWM);
value=480;
set_pwm1_duty(value); // This sets the time the pulse is
while( TRUE ) {
data = input_b();
data = data && 0x03;
if ( data==0x01)
{
value=value+192;
}
if ( data==0x02)
{
value=value-192;
}
delay_ms(100);
set_pwm1_duty(value);
delay_ms(50);
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 8902 |
|
|
nilsener Guest
|
Re: I need help |
Posted: Thu Nov 14, 2002 9:38 am |
|
|
Dear,
I get this code running, perhaps it is a problem that your duty_cycle value (480) is greater than 239 (239 sets the time of one period) as in you setup_timer2 statement. I think you will only get PWM if the duty cycle is between 0 and 239.
regards nilsener
void PWM_INIT()
{
SETUP_CCP1(CCP_PWM); // Set PWM Mode
setup_timer_2(T2_DIV_BY_16, 26, 1); // Set Timer2
SET_PWM1_DUTY(13); // Set Duty to 50\%
} /*End if PWM_INIT*/
:=Hi
:=
:=someone can tell me the possible errors in my code.
:=my code is for pwm with pin b0 and pin b1 I change the duty cyle
:=of the pwm. the problem is that I cand view the changes in my scope. I dont know the reason.
:=
:=thanks
:=
:=my code is:
:=
:=
:=#include <16F877.h>
:=#use delay(clock=1843200)
:=#fuses XT,NOWDT,NOPROTECT
:=
:=main() {
:= long value;
:= byte data;
:= SET_TRIS_B( 0xFF );
:=
:= setup_timer_2(T2_DIV_BY_16,239,1);
:= setup_ccp1(CCP_PWM);
:= value=480;
:= set_pwm1_duty(value); // This sets the time the pulse is
:=
:=
:=while( TRUE ) {
:=
:= data = input_b();
:= data = data && 0x03;
:= if ( data==0x01)
:= {
:= value=value+192;
:=
:= }
:=
:= if ( data==0x02)
:= {
:= value=value-192;
:=
:= }
:=
:=
:=
:= delay_ms(100);
:= set_pwm1_duty(value);
:=
:= delay_ms(50);
:=}
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 8909 |
|
|
Jean Paul Guest
|
Re: I need help |
Posted: Thu Nov 14, 2002 9:50 am |
|
|
thanks for your reply
but I thinks my problem is how to detect the bits b0 and b1 of the portB
I use data = (input_b()&& 0x03); to check the status of the
bits 0 an 1 but IT DOESNT WORK
can you tell me another way
thanks
:=Dear,
:=
:=I get this code running, perhaps it is a problem that your duty_cycle value (480) is greater than 239 (239 sets the time of one period) as in you setup_timer2 statement. I think you will only get PWM if the duty cycle is between 0 and 239.
:=
:=regards nilsener
:=
:=void PWM_INIT()
:={
:=SETUP_CCP1(CCP_PWM); // Set PWM Mode
:=setup_timer_2(T2_DIV_BY_16, 26, 1); // Set Timer2
:=SET_PWM1_DUTY(13); // Set Duty to 50\%
:=
:=} /*End if PWM_INIT*/
:=
:=:=Hi
:=:=
:=:=someone can tell me the possible errors in my code.
:=:=my code is for pwm with pin b0 and pin b1 I change the duty cyle
:=:=of the pwm. the problem is that I cand view the changes in my scope. I dont know the reason.
:=:=
:=:=thanks
:=:=
:=:=my code is:
:=:=
:=:=
:=:=#include <16F877.h>
:=:=#use delay(clock=1843200)
:=:=#fuses XT,NOWDT,NOPROTECT
:=:=
:=:=main() {
:=:= long value;
:=:= byte data;
:=:= SET_TRIS_B( 0xFF );
:=:=
:=:= setup_timer_2(T2_DIV_BY_16,239,1);
:=:= setup_ccp1(CCP_PWM);
:=:= value=480;
:=:= set_pwm1_duty(value); // This sets the time the pulse is
:=:=
:=:=
:=:=while( TRUE ) {
:=:=
:=:= data = input_b();
:=:= data = data && 0x03;
:=:= if ( data==0x01)
:=:= {
:=:= value=value+192;
:=:=
:=:= }
:=:=
:=:= if ( data==0x02)
:=:= {
:=:= value=value-192;
:=:=
:=:= }
:=:=
:=:=
:=:=
:=:= delay_ms(100);
:=:= set_pwm1_duty(value);
:=:=
:=:= delay_ms(50);
:=:=}
:=:=
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 8910 |
|
|
Tomi Guest
|
Re: I need help |
Posted: Thu Nov 14, 2002 10:22 am |
|
|
"&&" is logical AND. Use "&" to get bit-wise AND:
data = input_b() & 0x03;
:=thanks for your reply
:=
:=but I thinks my problem is how to detect the bits b0 and b1 of the portB
:=
:=I use data = (input_b()&& 0x03); to check the status of the
:=bits 0 an 1 but IT DOESNT WORK
:=can you tell me another way
:=
:=thanks
:=
:=
:=:=Dear,
:=:=
:=:=I get this code running, perhaps it is a problem that your duty_cycle value (480) is greater than 239 (239 sets the time of one period) as in you setup_timer2 statement. I think you will only get PWM if the duty cycle is between 0 and 239.
:=:=
:=:=regards nilsener
:=:=
:=:=void PWM_INIT()
:=:={
:=:=SETUP_CCP1(CCP_PWM); // Set PWM Mode
:=:=setup_timer_2(T2_DIV_BY_16, 26, 1); // Set Timer2
:=:=SET_PWM1_DUTY(13); // Set Duty to 50\%
:=:=
:=:=} /*End if PWM_INIT*/
:=:=
:=:=:=Hi
:=:=:=
:=:=:=someone can tell me the possible errors in my code.
:=:=:=my code is for pwm with pin b0 and pin b1 I change the duty cyle
:=:=:=of the pwm. the problem is that I cand view the changes in my scope. I dont know the reason.
:=:=:=
:=:=:=thanks
:=:=:=
:=:=:=my code is:
:=:=:=
:=:=:=
:=:=:=#include <16F877.h>
:=:=:=#use delay(clock=1843200)
:=:=:=#fuses XT,NOWDT,NOPROTECT
:=:=:=
:=:=:=main() {
:=:=:= long value;
:=:=:= byte data;
:=:=:= SET_TRIS_B( 0xFF );
:=:=:=
:=:=:= setup_timer_2(T2_DIV_BY_16,239,1);
:=:=:= setup_ccp1(CCP_PWM);
:=:=:= value=480;
:=:=:= set_pwm1_duty(value); // This sets the time the pulse is
:=:=:=
:=:=:=
:=:=:=while( TRUE ) {
:=:=:=
:=:=:= data = input_b();
:=:=:= data = data && 0x03;
:=:=:= if ( data==0x01)
:=:=:= {
:=:=:= value=value+192;
:=:=:=
:=:=:= }
:=:=:=
:=:=:= if ( data==0x02)
:=:=:= {
:=:=:= value=value-192;
:=:=:=
:=:=:= }
:=:=:=
:=:=:=
:=:=:=
:=:=:= delay_ms(100);
:=:=:= set_pwm1_duty(value);
:=:=:=
:=:=:= delay_ms(50);
:=:=:=}
:=:=:=
:=:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 8913 |
|
|
R.J.Hamlett Guest
|
Re: I need help |
Posted: Thu Nov 14, 2002 10:50 am |
|
|
:=thanks for your reply
:=
:=but I thinks my problem is how to detect the bits b0 and b1 of the portB
:=
:=I use data = (input_b()&& 0x03); to check the status of the
:=bits 0 an 1 but IT DOESNT WORK
:=can you tell me another way
:=
:=thanks
Yes. Use &, not &&. The former is the 'bitwise' AND operator (will do an 'AND' with your '3', and the input byte). The latter is the _logical_ AND operator. The operator you are using will return 'true', if input_b is logically 'true' (non zero), AND the test pattern is tre (which it is).
Best Wishes
:=
:=:=Dear,
:=:=
:=:=I get this code running, perhaps it is a problem that your duty_cycle value (480) is greater than 239 (239 sets the time of one period) as in you setup_timer2 statement. I think you will only get PWM if the duty cycle is between 0 and 239.
:=:=
:=:=regards nilsener
:=:=
:=:=void PWM_INIT()
:=:={
:=:=SETUP_CCP1(CCP_PWM); // Set PWM Mode
:=:=setup_timer_2(T2_DIV_BY_16, 26, 1); // Set Timer2
:=:=SET_PWM1_DUTY(13); // Set Duty to 50\%
:=:=
:=:=} /*End if PWM_INIT*/
:=:=
:=:=:=Hi
:=:=:=
:=:=:=someone can tell me the possible errors in my code.
:=:=:=my code is for pwm with pin b0 and pin b1 I change the duty cyle
:=:=:=of the pwm. the problem is that I cand view the changes in my scope. I dont know the reason.
:=:=:=
:=:=:=thanks
:=:=:=
:=:=:=my code is:
:=:=:=
:=:=:=
:=:=:=#include <16F877.h>
:=:=:=#use delay(clock=1843200)
:=:=:=#fuses XT,NOWDT,NOPROTECT
:=:=:=
:=:=:=main() {
:=:=:= long value;
:=:=:= byte data;
:=:=:= SET_TRIS_B( 0xFF );
:=:=:=
:=:=:= setup_timer_2(T2_DIV_BY_16,239,1);
:=:=:= setup_ccp1(CCP_PWM);
:=:=:= value=480;
:=:=:= set_pwm1_duty(value); // This sets the time the pulse is
:=:=:=
:=:=:=
:=:=:=while( TRUE ) {
:=:=:=
:=:=:= data = input_b();
:=:=:= data = data && 0x03;
:=:=:= if ( data==0x01)
:=:=:= {
:=:=:= value=value+192;
:=:=:=
:=:=:= }
:=:=:=
:=:=:= if ( data==0x02)
:=:=:= {
:=:=:= value=value-192;
:=:=:=
:=:=:= }
:=:=:=
:=:=:=
:=:=:=
:=:=:= delay_ms(100);
:=:=:= set_pwm1_duty(value);
:=:=:=
:=:=:= delay_ms(50);
:=:=:=}
:=:=:=
:=:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 8917 |
|
|
|
|
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
|