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/TMR1 & CCP2/TMR3 compare mode bug

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



Joined: 17 Aug 2010
Posts: 2
Location: Lima/Perú

View user's profile Send private message Visit poster's website MSN Messenger

CCP1/TMR1 & CCP2/TMR3 compare mode bug
PostPosted: Sun Sep 05, 2010 2:36 pm     Reply with quote

hi!!

I'm designing a 16-servo controller, which works to
8 servos perfection when I attend to the interruption of comparison
CCP1/TMR1 and attend other eight servos in my main program.

But I want to use the CCP2 with TMR3 to control eight servos that you used to in my main program.

I can not find my mistake but maybe there's something I'm not doing
well in the CCP2/TMR3.
Code:

#include <18F4550.h>

#fuses HSPLL,PLL5,USBDIV,CPUDIV1,MCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,VREGEN,NOPBADEN

// Fuses utilizados:
/*
HSPLL: utilizamos un cristal HS de alta velocidad, en conjunto con el PLL para generar los 48Mhz.
PLL5: significa que el PLL prescaler dividirá en 5 la frecuencia del cristal. para HS = 20Mhz/5 = 4Mhz.
USBDIV: signfica que el clock del usb se tomará del PLL/2 = 96Mhz/2 = 48Mhz.
CPUDIV1: El PLL postscaler decide la división en 2 de la frecuencia de salida del PLL de 96MHZ a 48MHZ para el CPU.
MCLR: Utilizamos R externa para el Master Clear
VREGEN: habilita el regulador de 3.3 volts que usa el módulo USB
*/

#use delay(clock=48000000)  // Frecuencia máxima de trabajo.

#use rs232(baud=19200, xmit=PIN_C6,rcv=PIN_C7)

#byte portB = 0xF81
#byte portD = 0xF83
#byte buffer= 0xFAE

int8  inc1=0, tramain[3];        // variables para int_RDA
int8  inc2=0;                    // variable para arreglo de trama
int8  inc3=0;                    // para uso de la int_CCP1 "compare mode"
int8  inc4=0;                    // variable para ciclo
int16 pos[16]={60,85,120,155,190,225,240,248,60,85,120,155,190,225,240,248};

void servopos(){
 if (tramain[0]=='A')      pos[tramain[1]]=tramain[2];     
 else if (tramain[0]=='B') for(inc2=0;inc2<16;inc2++) pos[inc2]=tramain[2];
}


#int_RDA
void RDA_isr(void)
{
 tramain[inc1]=buffer;           //graba el contenido del buffer al array tramain
 inc1++;                         // incrementa el indice del array
 if (inc1==3) {inc1=0; servopos();}
}

#int_CCP1
void  CCP1_isr(void)
{
 if (inc3==8) { portB=1; inc3=0; }
 else { portB=portB<<1; inc3++;}
 CCP_1=pos[inc3]*15; 
}

#int_CCP2
void  CCP2_isr(void)
{
 if (inc4==8) { portD=1; inc4=0; }
 else { portD=portD<<1; inc4++;}
 CCP_2=pos[inc4+8]*15; 
}

main(void){
 SETUP_ADC(ADC_OFF);
 SETUP_ADC_PORTS(NO_ANALOGS);
 SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_8);
 SETUP_TIMER_3(T3_INTERNAL|T3_DIV_BY_8|T3_CCP2);
 SETUP_CCP1(CCP_COMPARE_RESET_TIMER);
 SETUP_CCP2(CCP_COMPARE_RESET_TIMER);
 ENABLE_INTERRUPTS(INT_CCP1);
 ENABLE_INTERRUPTS(INT_CCP2);
 ENABLE_INTERRUPTS(INT_RDA);
 ENABLE_INTERRUPTS(GLOBAL);   
 set_tris_b(0);
 set_tris_d(0);
 delay_ms(10);
 portB=1;
 portD=0;
 
 while(1)
 {
  /*if (inc4==8) { portD=1; inc4=0; }
  else { portD=portD<<1; inc4++; }
  delay_us(pos[inc4+8]*10);*/
 } 
 
}
Robo3001



Joined: 17 Aug 2010
Posts: 2
Location: Lima/Perú

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Sun Sep 05, 2010 2:49 pm     Reply with quote

No problem, works perfect, only the simulator had problems.
In my actual implementation works perfect.
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