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 using 16F876A

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







adc using 16F876A
PostPosted: Thu Sep 28, 2006 11:40 am     Reply with quote

Hi.

I'm having a huge problem. I'm using the code below on an ICD2 to read a value from the analog input via the adc and converting it to pwm. The code works fine on the IDC2 but for some reason it will not work on my self-built board. Not working means CCP1 stays low. I'm assuming the software is fine and this is a hardware problem. I'm using a 50k pot connected to 5V and Gnd only to input on A0. The voltage at A0 varies between 0V and 5V as the pot is adjusted, but why is there no output on CCP1? Please help. I'm going crazy!!

#include "16F876A.h"
#use delay(clock = 4000000)

unsigned int16 duty = 0;
unsigned int16 analoogWaarde;

main()
{
// Pin setup
set_tris_A(1) ;
// Port A as input
set_tris_C(0x0) ;

// ADC Setup
setup_adc_ports(RA0_ANALOG); // Set RA0 as analog
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel(0);

// PWM Setup
setup_ccp1(CCP_PWM); // Configure CCP1 as PWM
setup_timer_2(T2_DIV_BY_16, 77, 1); // Timer 2 for 800Hz
set_pwm1_duty(duty); // Duty Cycle


while(1)
{
analogValue = read_adc() ; duty = analogValue ; set_pwm1_duty(duty); }


}
Rikus
Guest







PostPosted: Thu Sep 28, 2006 12:27 pm     Reply with quote

Thanx for your help. I found the problem. The firts time (testing the blinking LED) the configuration bits settings were correct, but the secund (third, forth, etc) time the settings were changed for some reason. After changing it to the original settings, the adc worked fine.
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