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

set_pwm1_duty(temp) not working please help me ?

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



Joined: 26 Apr 2012
Posts: 4

View user's profile Send private message

set_pwm1_duty(temp) not working please help me ?
PostPosted: Sat Apr 28, 2012 9:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 28, 2012 9:53 am     Reply with quote

The Text in the Red is Actually set_pwm1_duty(temp)
dyeatman



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

View user's profile Send private message

PostPosted: Sat Apr 28, 2012 12:32 pm     Reply with quote

This may help:
http://www.ccsinfo.com/forum/viewtopic.php?t=43355
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19503

View user's profile Send private message

PostPosted: Sat Apr 28, 2012 1:57 pm     Reply with quote

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
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