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

interrupts in DSPic and timers [SOLVED]

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



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

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

interrupts in DSPic and timers [SOLVED]
PostPosted: Sun Apr 10, 2011 1:38 pm     Reply with quote

Hello,
i have some strange problems,

when i set timer2 to internal, all interrupts stops working...no more timers ect...

any sugestions ?

Carl


Code:
#include <30f4013.h>
#device adc=12

#FUSES WDT // Watch Dog Timer
#FUSES HS
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#fuses HS2_pll8 // div by 3 and  multiply the ext. clock of 40mhz by 8x
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD

#define XTAL_FREQUENCY 120000000,RESTART_WDT
#use delay(clock=XTAL_FREQUENCY)
#use rs232(stream = RS232, baud=115200,parity=N,uart2,bits=8)
//#use i2c(Master, SDA=PIN_F2, SCL=PIN_F3, FORCE_HW, slow)
#use fast_IO(b)
#int_ext0 level=7
#int_ext1 level=7
#int_ext0 fast
#int_ext1 fast
/////////////////// Variabelen /////////////////
   long      EL_actu_position,AZ_actu_position;
   long       EL_calc_position,AZ_calc_position;
   long       EL_dest_position,AZ_dest_position;
   int         EL_init_ok, AZ_init_ok;
   long      EL_offset, AZ_Offset,AZ_u1;
   int         EL_stapteller=0,AZ_stapteller;


/////////////////// UIT-gangan /////////////////
      #define AZ_enc_A      PIN_A11   // input    pen 17
      #define AZ_enc_B      PIN_B4   // input   pen 6
      #define AZ_enc_Z      PIN_B11   // input   pen 36
      #define EL_enc_A      PIN_D8   // input    pen 23
      #define EL_enc_B      PIN_B5   // input    pen 7
      #define EL_enc_Z      PIN_B12   // input    pen 35
      #define AZ_Enbl_Drive   PIN_F1   // output    pen 29
      #define EL_Enbl_Drive   PIN_F0   // output    pen 30
      #define AZ_pwm_CCW      PIN_D3   // output    pen 19
      #define AZ_pwm_CW      PIN_D2   // output    pen 22
      #define EL_pwm_CCW      PIN_D1   // output    pen 33
      #define EL_pwm_CW      PIN_D0   // output    pen 34
   
/////////////////////////////////////////////////////////////////////////////////////
      void RS232();
/////////////////////////////////////////////////////////////////////////////////////
/****************** encoder Azimuth inlezen *******************/
   #int_ext0
   void EXT_Encoder_AZ()
   {
      if (input(AZ_enc_B) == 1)   
         {
               AZ_actu_position = AZ_actu_position + 1;
         }
         else
         {
               AZ_actu_position = AZ_actu_position - 1;
         }
   }
/////////////////////////////////////////////////////////////////////////////////////
/****************** encoder elevatie inlezen *******************/
   #int_ext1
   void EXT_Encoder_EL()
   {
      if (input(EL_enc_B) == 1)   
         {
               EL_actu_position = EL_actu_position +1;
         }
         else
         {
               EL_actu_position = EL_actu_position- 1;
         }
   }

/////////////////////////////////////////////////////////////////////////////////////
   #INT_TIMER1
   void TIMER1_isr()
   {
        rs232();
   }
/////////////////////////////////////////////////////////////////////////////////////
   void rs232()
   {
         printf("%c[2J%c[H",27,27);
         printf("ff$apel,%d*\r\n",EL_actu_position);
         printf("dd$apaz,%d*\r\n",AZ_actu_position);
         printf("$dpel,%u*\r\n",EL_dest_position);
         printf("$dpaz,%u*\r\n",AZ_dest_position);
         printf("$lsel%u,%u*\r\n",input(EL_CW_Lswitsh),input(EL_CCW_Lswitsh));
         printf("$lsaz%u,%u*\r\n",input(AZ_CW_Lswitsh),input(AZ_CCW_Lswitsh));
         printf("Fout            AZ    %d\n\r",AZ_u0);
         printf("Speed +-500      AZ   %d\n\r",AZ_u1);
         printf("Fout         EL   %d\n\r",EL_u0);
         printf("Speed +-500      EL   %d\n\r",EL_u1);
         printf("Stapteller    AZ  EL    %d  %d\n\r",AZ_actu_position,AZ_calc_position);
   }
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
Void main()
{
   set_tris_b(0b0001100100111111);
//   setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8,5000);   // prescale=64, PR2=255
   setup_timer1(TMR_INTERNAL | TMR_DIV_BY_256,65000);   // prescale=64, PR2=255 roept seriele communicatie aan


   //// initialisatie PWM's ///////////////
//   setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);      // Configre for PWM mode
//   setup_compare(2, COMPARE_PWM | COMPARE_TIMER2);      // Configre for PWM mode
//   setup_compare(3, COMPARE_PWM | COMPARE_TIMER2);      // Configre for PWM mode
//   setup_compare(4, COMPARE_PWM | COMPARE_TIMER2);      // Configre for PWM mode
   AZ_PWM(0,0);
   EL_PWM(0,0);
   //// initialisatie Interrupts ///////////////
   EXT_INT_EDGE(L_TO_H);

   enable_interrupts(INT_timer1);
   enable_interrupts(INT_timer2);
   enable_interrupts(INT_EXT1);
   enable_interrupts(INT_EXT0);
//   enable_interrupts(intr_GLOBAL);



   While(1)
   {
      
         if ((AZ_init_ok != 1))//||(EL_init_ok != 1))
            {
                  if (AZ_init_ok != 1)
                     Init_AZ(); //   eerst initialisatie uitvoeren
            }
         else
            {
            ///////   de regellus doorlopen

            }
      restart_wdt();//at least one in the main while(1) loop
   }//end while(1)
}//end void main()


Last edited by on7nh on Sun May 15, 2011 12:13 pm; edited 1 time in total
on7nh



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

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

PostPosted: Sun May 15, 2011 12:12 pm     Reply with quote

problem solved.....

when i use PWM...never enable the selected timer...
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