raghu
Joined: 28 Apr 2004 Posts: 2
|
Variable Frequency PWM |
Posted: Sat May 08, 2004 6:14 am |
|
|
Hi ,
I am using 16F819 in my design to generate a variable Frequency PWM
using CCP1 in my application
I have written a small Test Module
The module for single freq PWM seems to be working fine
I get the exact freq what I want by setting different values using
timer_setup() function
But when I continuously update the timer2 with different CCP1 Output is always Low
const long value = 520;
const byte loop = 1;
int selection;
int i;
void main()
{
OSCCON=0x74;
selection ==1;
while (loop == 1)
{
output_low(LED6);
delay_ms(1);
for (i=1;i<10;i++)
{
output_high(LED6);
set_pwm1_duty(value);
set_tris_b(0x00);
switch(selection)
{
case '1' : setup_timer_2(T2_DIV_BY_1, 255, 1);
break;
case '2' : setup_timer_2(T2_DIV_BY_4, 255, 1);
break;
case '3' : setup_timer_2(T2_DIV_BY_16, 255, 1);
break;
}
setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
}
if (selection > 3)
selection == 1;
else
selection ++;
} //while
} // main()
//EOF
In this I want to change the frequency continuously 350Hz,1.74khz& 7.6KHz using 'Selection' variable
When I checked individually , it was working fine
Am I missing something here for updating TIMER2 values?
Any suggestion would be of great help
Thanks & Best Regards,
Raghu |
|