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

ADC IN PWMMING

 
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

ADC IN PWMMING
PostPosted: Mon Jul 18, 2011 3:09 pm     Reply with quote

Dear All,

I'm doing a project about PWM Dimming using ADC. I'm using a variable resistor to do ADC but the dimming effect is not obvious. My code is shown as follows.

Code:


#include <16F877A.h>
#device adc=10
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,NOLVP, NOBROWNOUT,NOPUT



void main() {

int8 temp_res=0;
int8 temp_duty=0;
setup_timer_2(T2_DIV_BY_4,100,1);
set_tris_a(0xFF);*/
set_tris_c(0x00); // Set PORTC as an Output
setup_ccp1(CCP_PWM);

while(1){
set_adc_channel(0);
delay_us(20);
temp_res = read_adc(); // Get results of AD conversion
delay_us(20);                           // from channel 2 (RA2 pin)

temp_duty = (temp_res); // Convert the 10 bit value
set_pwm1_duty(50);
delay_us(10);
}
}





Should I change the mutiple of (temp_res) to make the effect more obvious?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 18, 2011 3:26 pm     Reply with quote

Here is a working program which reads the ADC and sets the PWM
duty cycle to dim an LED:
http://www.ccsinfo.com/forum/viewtopic.php?t=40007&start=1
lxc032



Joined: 12 Jul 2011
Posts: 5

View user's profile Send private message

PostPosted: Mon Jul 18, 2011 3:46 pm     Reply with quote

Thanks for your program.

I'm trying to use a variable resistor to change the duty cycle of the PWM signals. Should I need to change the multiple of the "temp_res" ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 18, 2011 3:51 pm     Reply with quote

You are not using the adc value to set the PWM duty. You are doing
nothing with it. Your PWM duty is set to a constant value of 50.

The program that I gave you in the link does use the ADC value
to set the duty. I suggest that you study it.
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