View previous topic :: View next topic |
Author |
Message |
vinu Guest
|
using ordinary PWM in 16F690 which contain ECCP |
Posted: Wed Sep 13, 2006 10:06 pm |
|
|
Dear Sir,
Anyone give an example for using ordinary PWM (single output from p1A ) when the microcontroller( PIC16f690) is equiped with ECCP.
following code does not work.
//////////////////////////////////////////////////
set_tris_c(0x00);
setup_timer_2(T2_DIV_BY_16,253,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(5000;
while(1);
//////////////////////////////////////////////// |
|
|
vinu Guest
|
Error in previous post-ECCP |
Posted: Thu Sep 14, 2006 5:44 am |
|
|
Dear Sir,
Anyone give an example for using ordinary PWM (single output from p1A ) when the microcontroller( PIC16f690) is equiped with ECCP.
following code does not work.
//////////////////////////////////////////////////
long value;
value=500;
set_tris_c(0x00);
setup_timer_2(T2_DIV_BY_16,253,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(value);
while(1);
//////////////////////////////////////////////// |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 14, 2006 11:45 am |
|
|
Post your compiler version. This will be a 4-digit number such as
3.191, 3.249, etc. You can find it at the top of the .LST file which
will be in your project directory. |
|
|
vinu Guest
|
|
Posted: Thu Sep 14, 2006 10:13 pm |
|
|
version number-- 3.225
regards,
vinu |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 14, 2006 11:46 pm |
|
|
Quote: | version number-- 3.225 |
The setup_ccp1() function is buggy for the 16F690 with your verison
of the compiler. To fix this, I've created a substitute function called
my_setup_ccp1(), as shown below. The code in it is a duplicate of
the code used by vs. 3.249 of the compiler, so it should work.
Try the following test program:
Code: |
#include <16F690.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#byte PORTC = 0x07
#byte TRISC = 0x87
#byte PIR1 = 0x0C
#byte T2CON = 0x12
#byte CCP1CON = 0x17
#byte PWM1CON = 0x1C
#byte ECCPAS = 0x1D
#bit CCP1_TRIS = TRISC.5
#bit CCP1_PIN = PORTC.5
#bit TMR2ON = T2CON.2
#bit TMR2IF = PIR1.1
#inline
void my_setup_ccp1(int8 CCP1_value)
{
CCP1_TRIS = 1;
CCP1CON = CCP1_value;
PWM1CON = 0;
ECCPAS = 0;
if(TMR2ON)
{
TMR2IF = 0;
while(!TMR2IF);
}
CCP1_TRIS = 0;
CCP1_PIN = 0;
}
//====================================
void main()
{
long value;
value=500;
setup_timer_2(T2_DIV_BY_16, 253, 1);
my_setup_ccp1(CCP_PWM);
set_pwm1_duty(value);
while(1);
} |
|
|
|
vinu Guest
|
|
Posted: Sat Sep 16, 2006 2:07 am |
|
|
Thanks a lot. Finally the PWM is working. cost
Regards,
Vinu |
|
|
|