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

PWM shutdown by #int_RC

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



Joined: 31 Jan 2019
Posts: 7
Location: Quebec

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

PWM shutdown by #int_RC
PostPosted: Thu Jan 31, 2019 11:16 pm     Reply with quote

I am using CCP1 to generate a PWM via the following syntax:
Code:

setup_timer_2 (T2_DIV_BY_4, 255, 1);
setup_ccp1 (CCP_PWM);
set_pwm1_duty ((int16) 500);

I get a PWM with a duty cycle of about 50%.
But following the interruption by the keyboard (#int_RC) the PWM stopped.
Why do I have to put at the end of the interrupt procedure this syntax?
Code:

setup_ccp1 (CCP_PWM);

I thank you in advance for your help. Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 01, 2019 2:25 am     Reply with quote

Post:

1. Your PIC.

2. Your CCS compiler version.

3. The #int_rc routine.

4. Post what PIC pins are used to connect to your keyboard.

5. Post the keyboard type, or post a link to the website for it.

6. Post the name of the keyboard driver, if it's a CCS driver.
temtronic



Joined: 01 Jul 2010
Posts: 9102
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 01, 2019 6:45 am     Reply with quote

As PCMP says we need a lot more information however from what you say 'something' in the ISR is changing the CCP 'for some reason'...
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Fri Feb 01, 2019 6:58 am     Reply with quote

My guess would be that the keyboard driver he is using uses the CCP as part of it's debounce routine, but without data we cannot tell....
Daniel1956



Joined: 31 Jan 2019
Posts: 7
Location: Quebec

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

setup_ccp1 (CCP_PWM);
PostPosted: Fri Feb 01, 2019 10:26 am     Reply with quote

The PIC is 16F1789
The compiler is PCWHD 5.07
Keyboard row RC4,5,6,7
Keyboard column RD4,5,6,7
It is by interrupting #int_rc that I read the keyboard which is a 4 x 4:
Code:

#use delay(clock=32000000)
#int_RC
void clavier16touches(void){
   extern unsigned char clavier[6];
   extern unsigned char clavier_valide, kb_enable;
   char rangee;
   static signed int8 i = 0;
   delay_ms(30);
   rangee = input_c() & 0xf0;      // masque C0 C1 C2 C3
   switch(rangee)
   {
   // **************    Rangé 1 *******************************   
      case RANGEE1 :
         output_high(COL1);
         if(input(ROW1))   
         {
            if(i != nb_max && kb_enable)
            {
               clavier[i] = tableau_clavier[0][0];
               lcd_putc(clavier[i]);            // 1
               i++;
            }
            output_low(COL1);
         }
         else
         {
            output_low(COL1);
            output_high(COL2);
            if(input(ROW1))
            {
               if(i != nb_max && kb_enable)
               {
                  clavier[i] = tableau_clavier[0][1];
                  lcd_putc(clavier[i]);            // 2
                  i++;
               }
               output_low(COL2);            
            }
            else
            {
               output_low(COL2);
               output_high(COL3);
               if(input(ROW1))
               {
                  if(i != nb_max && kb_enable)
                  {
                     clavier[i] = tableau_clavier[0][2];
                     lcd_putc(clavier[i]);               
                     i++;
                  }
                  output_low(COL3);            
               }
               else
               {
                  //clavier[i] = tableau_clavier[0][3];
                  output_low(COL3);
                  clavier_valide = STOP;      //stop
                  i = 0;
               }
            }   
         }
      break;
   // *****************    Range2*****************************    
      case RANGEE2 :
         output_high(COL1);
         if(input(ROW2))
         {
            if(i != nb_max && kb_enable)
            {
               clavier[i] = tableau_clavier[1][0];
               lcd_putc(clavier[i]);            // 4
               i++;
            }
            output_low(COL1);
         }
         else
         {
            output_low(COL1);
            output_high(COL2);
            if(input(ROW2))
            {
               if(i != nb_max && kb_enable)
               {
                  clavier[i] = tableau_clavier[1][1];
                  lcd_putc(clavier[i]);          // 5
                  i++;
               }
               output_low(COL2);
            }
            else
            {
               output_low(COL2);
               output_high(COL3);
               if(input(ROW2))
               {
                  if(i != nb_max && kb_enable)
                  {
                     clavier[i] = tableau_clavier[1][2];
                     lcd_putc(clavier[i]);            // 6
                     i++;
                  }
                  output_low(COL3);
               }
               else if(kb_enable)
               {
                  clavier[i] = tableau_clavier[1][3];
                  while(i)
                  {
                     clavier[i] = '0';
                     lcd_putc('\b');                     //  home
                     lcd_putc(' ');
                     lcd_putc('\b');
                     i--;
                  }
                  i = 0;
                  clavier[i] = '0';
               }
               output_low(COL3);            
            }
         }   
      break;
   // **************************    Rangé 3 *******************************    
      case RANGEE3 :
         output_high(COL1);
         if(input(ROW3))
         {
            if(i!= nb_max && kb_enable)
            {
               clavier[i] = tableau_clavier[2][0];
               lcd_putc(clavier[i]);                     // 7
               i++;
            }
            output_low(COL1);
         }
         else
         {
            output_low(COL1);
            output_high(COL2);
            if(input(ROW3))
            {
               if(i!= nb_max && kb_enable)
               {
                  clavier[i] = tableau_clavier[2][1];
                  lcd_putc(clavier[i]);                        //8
                  i++;
               }
               output_low(COL2);
            }
            else
            {
               output_low(COL2);
               output_high(COL3);
               if(input(ROW3))
               {
                  if(i!= nb_max && kb_enable)
                  {
                     clavier[i] = tableau_clavier[2][2];
                     lcd_putc(clavier[i]);                           // 9
                     i++;
                  }
                  output_low(COL3);
               }
               else if(kb_enable)
               {
                  clavier[i] = tableau_clavier[2][3];
                  output_low(COL3);
                  if(i > 0)
                  {
                     lcd_putc(clavier[i]);                        // back space
                     lcd_putc(' ');
                     lcd_putc(clavier[i]);
                     i--;
                  }
               }
            }
         }
      break;   
   // **************************    Rangé 4 *******************************    
      case RANGEE4:
         output_high(COL1);
         if(input(ROW4))
         {
            if(i!= nb_max && kb_enable)
            {
               clavier[i] = tableau_clavier[3][0];
               // lcd_putc(clavier[i]);
               i++;
               output_low(COL1);
               clavier_valide = REV;                  // Manuel
               i = 0;
            }
            output_low(COL1);
         }
         else
         {
            output_low(COL1);
            output_high(COL2);
            if(input(ROW4))
            {
               if(i!= nb_max && kb_enable)
               {
                  clavier[i] = tableau_clavier[3][1];
                  lcd_putc(clavier[i]);               // 0
                  i++;
               }
               output_low(COL2);
            }
            else
            {
               output_low(COL2);
               output_high(COL3);
               if(input(ROW4))
               {
                  if(i!= nb_max && kb_enable)
                  {
                     clavier[i] = tableau_clavier[3][2];               
                     lcd_putc(clavier[i]);
                     i++;
                     output_low(COL3);
                     clavier_valide = DEP;               // AUTOMATIQUE
                     i = 0;
                  }
                  output_low(COL3);
               }
               else
               {
                  output_low(COL3);
                  clavier[i] = tableau_clavier[3][3];
                  clavier_valide = VRAI;                     // ENTER (vrai)
                  i = 0;
               }
            }   
         }
      break;         
   }

   if(i>nb_max)
   {
      i = nb_max;
   }
   clear_interrupt(INT_IOC_C4);
   clear_interrupt(INT_IOC_C5);
   clear_interrupt(INT_IOC_C6);
   clear_interrupt(INT_IOC_C7);
   setup_ccp1(CCP_PWM);


}


Thank you for your help
Daniel
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: setup_ccp1 (CCP_PWM);
PostPosted: Fri Feb 01, 2019 11:10 am     Reply with quote

Daniel1956 wrote:

Keyboard row RC4,5,6,7
Keyboard column RD4,5,6,7
It is by interrupting #int_rc that I read the keyboard which is a 4 x 4:
[code]
#use delay(clock=32000000)
#int_RC
void clavier16touches(void){
extern unsigned char clavier[6];
extern unsigned char clavier_valide, kb_enable;
char rangee;
static signed int8 i = 0;
delay_ms(30);
rangee = input_c() & 0xf0; // masque C0 C1 C2 C3
switch(rangee)
{

If you're using Standard i/o mode (which is the default mode), your
input_c() line will cause all pins on PortC to be inputs. If your CCP2
output is set to pin C1 (which is the default), then your PWM output will
stop. The 16F1789 data sheet says in the PWM section:
Quote:
Note 1:
The corresponding TRIS bit must be
cleared to enable the PWM output on the
CCPx pin.

For the TRIS, "cleared" means to set it to an output pin.
Daniel1956



Joined: 31 Jan 2019
Posts: 7
Location: Quebec

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

PostPosted: Fri Feb 01, 2019 12:27 pm     Reply with quote

Thanks for your help!

Setting RC2 as output by this syntax
Code:
#use fixed_io (c_outputs = PIN_C2)

I solved my problem.

THANK YOU again for your quick help WELL appreciated:grin: Very Happy Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Fri Feb 01, 2019 12:31 pm     Reply with quote

and just to add, the reason that re-enabling the PWM started it again
is that when you enable the PWM, the compiler automatically sets the
PWM pin as an output.
newguy



Joined: 24 Jun 2004
Posts: 1902

View user's profile Send private message

PostPosted: Fri Feb 01, 2019 12:31 pm     Reply with quote

Daniel1956 wrote:
merci pour votre aide!

en fixant RC2 en sortie par cette syntaxe #use fixed_io(c_outputs= PIN_C2) j'ai résolue mon problème.

MERCI encore de votre aide rapide BIEN apprécié Very Happy Very Happy Very Happy


I don't understand French at all, but I was able to understand this without google translate.

Very Happy


+++++++++++++++++++++++
His post is now translated to English.
- Forum Moderator
+++++++++++++++++++++++
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