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 support@ccsinfo.com

problems with int16 or methods

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



Joined: 11 Feb 2007
Posts: 19
Location: Cedar Rapids

View user's profile Send private message

problems with int16 or methods
PostPosted: Tue Mar 06, 2007 12:24 pm     Reply with quote

Right now, I'm drawing up an outline for my dc motor control. I was trying to compile this preliminary program, but I get error messages that say "A numeric expression must appear here" for all the lines that say int16. Does this have something to do with the way I wrote the methods (my programming skills are rusty). Thanks for your help. Here's the code:

Code:
#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)

void check_reset()  {

   int reset_value = 0;   

   while (reset_value==0)  {

      reset_value = input(PIN_B1);  //delays circuit until user resets circuit (emits high signal to pin B1

   }


}

int check_current()  {

   set_adc_channel( 0 );
   
   int16 current_value;

   current_value = (read_adc()*512)/1024;
   
   int overload;

   if (current_value > 5)   //NOT SURE WHAT THIS VALUE WILL BE YET, BUT 5 is probably a good guess
      overload = 1;
   else
      overload = 0;

   return overload;
}


int check_speed()  {

   return 0;      //not sure how to handle this just yet...

}

void compare_with_user()  {

   int16 value1;
   int16 value2;

   value1=(read_adc()*512)/1024;     //note, adc_channel should already be set to 0 from check_current method!
   delay_us( 10 );               //10uS delay is necessary for proper ADC reading.
   value2=(read_adc()*512)/1024;

   //COMPARISON GOES HERE...   

   set_pwm1_duty(value1);
   /*   This sets the time the pulse is high each cycle.
      The high time will be:
      if value is LONG INT: value*(1/clock)*t2div
      if value is INT: value*4*(1/clock)*t2div
      for example a value of 30 and t2div of 1 the high time 12uS
      A value too high or too low will prevent the output from changing.
   */
   

}

void main() {
   
   setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
   setup_timer_2(T2_DIV_BY_1, 24, 1);  //output at 50KHz
                              //Period = (1/clock)*4*t2div*(period+1)

   setup_port_a(ALL_ANALOG);
    setup_adc(adc_clock_internal);

   int shutdown1;
   int shutdown2;   

   while( TRUE ) {

   shutdown1 = check_current();     //returns 0 if okay and 1 if overloaded
   shutdown2 = check_speed();      //returns 0 if okay and 1 if it's too fast
   
   if ( (shutdown1==0)&&(shutdown2==0) )
      compare_with_user();
   else {
      set_pwm1_duty(0);
      check_reset();   
      }

   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 06, 2007 12:33 pm     Reply with quote

All local variables must be declared at the start of the function,
before any code.
sonicfire



Joined: 11 Feb 2007
Posts: 19
Location: Cedar Rapids

View user's profile Send private message

PostPosted: Tue Mar 06, 2007 12:44 pm     Reply with quote

That did the trick! Many thanks...
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 06, 2007 1:55 pm     Reply with quote

PCM programmer wrote:
All local variables must be declared at the start of the function,
before any code.


sonicfire - get a copy of Kernighan and Richie's "C Lanugage" 2nd edition. In ANSI C (and in CCS's decidedly non-ANSI C) you MUST complete all declarations prior to starting code in the body of a function.

C++ however relaxed that requirement.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
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