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

CCP1 not switching off.

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



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

CCP1 not switching off.
PostPosted: Wed Oct 10, 2007 5:28 am     Reply with quote

Hi. I have been sitting with the same problem for about 2 days now and i cant seem to figure out what the problem is. I have got a joystic conected to an1 for forward reverse motion and a joystic on an2 to read the left right motion. If i move an1 forward and back the pwm output works fine and if i push an2 left and right the other pwm uotput works works fine but if i push an2 left or right while pushing an1 forwar and back both the pwm indication led's goes on and even when returning both sticks to there original middle position the pwm led's does not want to swtch of. Please see if anyone can find a hole in the program or some other error. I am using a 16f886 pic.

Code:
set_tris_a(TRISA | 0b00001110);
set_tris_a(TRISA & 0b11001111);
set_tris_b(trisb & 0b11000001);

output_low(PIN_A4);
output_low(PIN_A5);
output_low(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);
output_low(PIN_B4);
output_low(PIN_B4);

         
setup_adc_ports(sAN1);
setup_adc_ports(sAN2);
setup_adc_ports(sAN3);
setup_adc( ADC_CLOCK_DIV_8  );

#define P1C PIN_B1
#define P1b PIN_B2
setup_timer_2(T2_DIV_BY_4, 124, 1);  // 1000 Hz
output_low(P1C);

//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
while(1){

///part were weapon is actvated
//xxxxxxxxxxxxxxxxxxxxxxxxxxx

//////////////////////////////////////Joystick pushed right ////////////////////////////////////////
set_adc_channel(2);   
delay_us(20);
value1 = read_adc();

if(value1 > 245 ){
setup_ccp1(CCP_OFF);
output_high(pin_A4);
output_low(pin_b5);
output_low(pin_b3);
PutCC1000(PREAMBLE);
PutCC1000(0x1A);
}
else if(value1 > 210 && value1 < 246 ){
set_pwm1_duty(0);
setup_ccp1(CCP_OFF);          ////switch off ccp1(pwm)
output_low(pin_A4);
output_low(pin_b5);
output_low(pin_b3);
PutCC1000(PREAMBLE);
PutCC1000(0x1B);
}
///////////////////////////////////////////Joystick pushed left////////////////////////////////////////////
if(value1 > 10 && value1 < 90  ){
//set_pwm1_duty(0);
setup_ccp1(CCP_OFF);                   ////switch off ccp1(pwm)
output_low(pin_A5);
output_low(pin_b5);
output_low(pin_b3);
PutCC1000(PREAMBLE);
PutCC1000(0x2A);
}
else if(value1 < 11 ){
set_pwm1_duty(80);
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_B);
output_high(pin_A5);
output_low(pin_b5);
output_low(pin_b3);
PutCC1000(PREAMBLE);
PutCC1000(0x2B);
}
//////////////////////////////joystic pushed forward /////////////////////////////////////////////////
if(value1 > 90 && value1 <211){
output_low(pin_A4);
output_low(pin_A5);
set_adc_channel(1);
delay_us(20);
value = read_adc();

 if(value > 110 && value < 116  ) {
set_pwm1_duty(25);
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_C);
output_high(pin_b3);
PutCC1000(PREAMBLE);
PutCC1000(0x3E);
}
//////////////Joystic in the middle////////
else if(value > 115 && value < 161  ) {
setup_ccp1(CCP_OFF);                          ////switch off ccp1(pwm)
output_low(pin_b5);
output_low(pin_b3);
PutCC1000(PREAMBLE);
PutCC1000(0x4A);
}
/////////////////joystick pushed back////////////
else if(value > 160 && value < 181  ) {
set_pwm1_duty(25);
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_C);
output_high(pin_b5);
PutCC1000(PREAMBLE);
PutCC1000(0x5A);
}


}
}
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Wed Oct 10, 2007 8:03 am     Reply with quote

While many of the experts here can read through code and pick out errors with amazing results, it will be easier, in the long run, for you to learn some debugging techniques. If you have some way to output information, preferably a rs232 but an LED will work in a pinch. (Many use an ICD, CCS or Microchip.... my CCS ICD quit after a while and I didn't go back to it.) Anyway, adding debug statements to test conditions and output rs232 values or illuminate or not illuminate an LED can be used to your advantage.

You may also want to use the #case directive. I notice you have variety of formats of P1C P1b PIN_B1 pin_b5 etc. The #case directive can prevent some pretty frustrating problems.

John
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 10, 2007 9:14 am     Reply with quote

Quote:

setup_adc_ports(sAN1);
setup_adc_ports(sAN2);
setup_adc_ports(sAN3);

setup_adc( ADC_CLOCK_DIV_8 );

This is a bug. The setup_adc_ports() function does not work with
sequential calls. The only call that will take effect is the last one.

If you want to define several analog pins, you should 'OR' them
together with the bitwise 'OR' operator '|', and do it in only one
call to the setup_adc_ports() function.
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Wed Oct 10, 2007 11:52 am     Reply with quote

Thanks.
I changed the setup of the adc although it did work the other way as well i think it is more stable now.
I changed the

setup_ccp1(CCP_OFF); statement to
set_pwm1_duty(0);
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_B);
and now it seems to work. Is there a logical reason that ccp_off doesn't work in this program corectly?
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

View user's profile Send private message Send e-mail

PostPosted: Wed Oct 10, 2007 12:07 pm     Reply with quote

I think i found my mistake.
It should be ccp_off
then output_low(pwm pin)
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