View previous topic :: View next topic |
Author |
Message |
WAQASKHAN
Joined: 26 Apr 2012 Posts: 4
|
set_pwm1_duty(temp) not working please help me ? |
Posted: Sat Apr 28, 2012 9:50 am |
|
|
Code: |
#include <16f877a.h>
#device adc=10 // Set ADC resolution to 10Bit
#fuses XT,NOLVP,NOWDT,NOPROTECT
#use delay(clock=2000000)
#use rs232(baud=9600,bits=8,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#define LOAD PIN_B6
#define THRES 40 // load switching threshold in Celsius
int16 digital_reading; // ADC resolution is 10Bit, an 8Bit integer is not enough to hold the reading
float temp;
char value;
void main()
{
/* ADC Initialization */
setup_adc(ADC_CLOCK_INTERNAL); // initialize ADC with a sampling rate of Crystal/4 MHz
setup_adc_ports(ALL_ANALOG); // set PIN_A0 as analog input channel
set_adc_channel(0); // point ADC to channel 0 for ADC reading
delay_ms(1); // ADC module is slow, needs some time to adjust.
// set PWM
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 1023, 1);
while(1) // infinite loop
{
digital_reading = read_adc(); // capture current temperature reading
delay_us(100); // 0.1ms delay for ADC stabilization
temp = digital_reading * 0.4883; // convert reading to Celsius
[color=red][b]set_pwm1_duty(temp);[/b[/color]]
if(temp>=THRES)
{
output_high(LOAD); // Control Load
}
else
{
output_low(LOAD);
}
delay_ms(1000); // 1 second delay between readings
if(kbhit())
{
value=getc();
switch(value)
{
case '1':
output_high(pin_b0);
break;
case '2':
output_high(pin_b1);
break;
case '3' :
output_low(pin_b0);
break;
case '4' :
output_low(pin_b1);
break;
case '5':
printf("%lf\n",temp);
break;
default:
printf("error");
break;
}
}
}
} |
|
|
|
WAQASKHAN
Joined: 26 Apr 2012 Posts: 4
|
|
Posted: Sat Apr 28, 2012 9:53 am |
|
|
The Text in the Red is Actually set_pwm1_duty(temp) |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Sat Apr 28, 2012 1:57 pm |
|
|
Code: |
setup_timer_2(T2_DIV_BY_1, 1023, 1);
|
What is the maximum value that Timer2's period can accept on a PIC16F877?. Read the manual entry.
Best Wishes |
|
|
|