|
|
View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
PIC16f684 does not accept variable for function |
Posted: Thu Nov 10, 2005 3:48 pm |
|
|
I have used pwm function for several chips, and it works very well so far, I can set duty as constant as well as variable, however, when it comes to pic16f684 chip, I just got the set_pwm1_duty() function work for constant, it is not working for variable,any ideas? attached is the testing code.
Code: |
#if defined(__PCM__)
#include <16F684.h>
#fuses INTRC_IO, NOBROWNOUT,NOWDT,NOPROTECT,NOPUT,NOMCLR
//#device ADC=10
#use delay(clock =8000000)
void main()
{
int8 i;
SET_TRIS_a(0x07);
SET_TRIS_c(0x07);
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_timer_2(T2_DIV_BY_1, 255, 1);
SETUP_CCP1(CCP_PWM);
disable_interrupts(GLOBAL);
while(1)
{
/*if(input(PIN_A0))
SET_PWM1_DUTY(88);
else if(input(PIN_A1))
SET_PWM1_DUTY(96);
else if(input(PIN_A2))
SET_PWM1_DUTY(112);
else if(input(PIN_C0))
SET_PWM1_DUTY(128);
else if(input(PIN_C1))
SET_PWM1_DUTY(144);
else if(input(PIN_C2))
SET_PWM1_DUTY(160);
else
SET_PWM1_DUTY(88);
*/ //the above code is work, the following is not
for (i=0;i<=254;i++)
{
SET_PWM1_DUTY(i);
output_high(PIN_C3);
delay_ms(1500);
output_low(PIN_C3);
delay_ms(1500);
}
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 10, 2005 4:27 pm |
|
|
Quote: |
SET_PWM1_DUTY(88);
SET_PWM1_DUTY(96);
SET_PWM1_DUTY(112);
SET_PWM1_DUTY(128);
SET_PWM1_DUTY(144);
SET_PWM1_DUTY(160);
|
All of these tests above have a cycle value of 88 or greater.
In this test below, you are starting with a duty cycle of 0 and you
increase it by 1, every 3 seconds. So to get up to 88, which you
declare to be working, it takes 88 x 3 = 264 seconds = 4 minutes
and 24 seconds. Do you really wait for almost 5 minutes, while
watching the output ? I wonder.
Quote: |
for (i=0;i<=254;i++)
{
SET_PWM1_DUTY(i);
output_high(PIN_C3);
delay_ms(1500);
output_low(PIN_C3);
delay_ms(1500);
} |
I suggest you use a very simple test, like this:
Code: |
i = 88;
SET_PWM1_DUTY(i); // Set duty cycle value = 88
while(1); // Wait here and let PWM run.
|
|
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Fri Nov 11, 2005 8:17 am |
|
|
Thank you PCM:
you are right, I tested it again it is working, before when I was testing it, I run the for loop too fast that the meter could not followed it. |
|
|
|
|
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
|