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 CCS Technical Support

Problem of using PIC16F877A

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



Joined: 12 Jul 2011
Posts: 5

View user's profile Send private message

Problem of using PIC16F877A
PostPosted: Tue Jul 12, 2011 10:17 am     Reply with quote

Dear All,

I'm doing a project about PWM DIMMING using PIC16F877A,

I have two problems.
(1) How can I generate a phase shift between two LED strings?
(2) Following is the code of my project. However, It does not work.
What is the problem?

Code:

#include<16F877A.h>
int value;
void adc ();
{
 setup_adc(ALL_ANALOG);
 set_adc_channel(1)
 delay_ms(3000)
 value = read_adc()
}
void PWM_generation;
{
 setup_ccp1(CCP_PWM);
 if (value==2)
 {
 setup_timer_2(T2_DIVBY_4, 100, 0);
 set_pwm1_duty(50);
 delay_ms(200);
}
else
{
 setup_timer_2(T2_DIVBY_4, 250, 0);
 set_pwm1_duty(125);
 delay_ms(300);
}
 set_pwm1_duty(0);
}
void main;
{
 adc;
 PWM_generation;
}
end
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PWM dimming
PostPosted: Tue Jul 12, 2011 2:12 pm     Reply with quote

Hi,

Give us more detail about frequency, resolution etc.

A sketch of the expected PWM signals (as viewed on a 'scope) would help.

Mike Walne
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Tue Jul 12, 2011 3:02 pm     Reply with quote

Some comments inline.
Code:

#include<16F877A.h>
//No clock statement - delays won't work properly - no fuses...

int value;

void adc ();
{
 setup_adc(ALL_ANALOG);
 set_adc_channel(1)
 delay_ms(3000)
 value = read_adc()
}

void PWM_generation; //Not a function declaration - creates a void variable
{
 setup_ccp1(CCP_PWM);
 if (value==2)
 {
 setup_timer_2(T2_DIVBY_4, 100, 0); //Incorrect syntax for the divisor
 set_pwm1_duty(50);
 delay_ms(200);
}
else
{
 setup_timer_2(T2_DIVBY_4, 250, 0);
 set_pwm1_duty(125);
 delay_ms(300);
}
 set_pwm1_duty(0);
}

void main;
{
 adc;
 PWM_generation; // function  calls = ()
 //No loop, so code will execute once, and then die.
}
end //Er. Different language....


'value' is very unlikely to ever be '2'. Would need approximately 0.0488v (assuming a 5v PIC) on the analog input to get this.

Best Wishes
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Jul 12, 2011 3:42 pm     Reply with quote

Also:
Code:
set_adc_channel(1)
 delay_ms(3000)
 value = read_adc()


The delay should be more like delay_us(20);
_________________
Google and Forum Search are some of your best tools!!!!
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