View previous topic :: View next topic |
Author |
Message |
Daniel1956
Joined: 31 Jan 2019 Posts: 7 Location: Quebec
|
PWM shutdown by #int_RC |
Posted: Thu Jan 31, 2019 11:16 pm |
|
|
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. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 01, 2019 2:25 am |
|
|
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: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Feb 01, 2019 6:45 am |
|
|
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: 19537
|
|
Posted: Fri Feb 01, 2019 6:58 am |
|
|
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
|
setup_ccp1 (CCP_PWM); |
Posted: Fri Feb 01, 2019 10:26 am |
|
|
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
|
Re: setup_ccp1 (CCP_PWM); |
Posted: Fri Feb 01, 2019 11:10 am |
|
|
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
|
|
Posted: Fri Feb 01, 2019 12:27 pm |
|
|
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: |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Fri Feb 01, 2019 12:31 pm |
|
|
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: 1909
|
|
Posted: Fri Feb 01, 2019 12:31 pm |
|
|
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é |
I don't understand French at all, but I was able to understand this without google translate.
+++++++++++++++++++++++
His post is now translated to English.
- Forum Moderator
+++++++++++++++++++++++ |
|
|
|