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

math.h problem

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



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

math.h problem
PostPosted: Fri Jul 30, 2010 10:48 am     Reply with quote

Hi every time I compile my program it gives this error:

*** Error 112 "simple_meter.c" Line 205(1,1): Function used but not defined: ... ceil SCR=862

I am using ceil() in my program and have included <math.h> in the program.

Here's the demo code:
Code:

#include <16f876A.h>
#device adc=10
#include <math.h>

#include <timers.h>
#include <button.c>

#USE DELAY( CLOCK=4000000) /* Using a 4 Mhz clock */
#FUSES XT,NOWDT,NOPROTECT,NOPUT
#PRIORITY INT_TIMER1,INT_RTCC

#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000     5ms
#define  INTERRUPT_OVERHEAD            500   //cycles wasted
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))

#USE FAST_IO(B)
#USE FAST_IO(C)


Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 11:59 am     Reply with quote

That's not enough code to demonstrate the problem. Post a complete
(but small) program that we can copy and paste into MPLAB, and compile
it and get the error. Your posted code is missing the main() and it's
missing the call to the ceil() function. Try to keep the program down to
20 to 25 lines. It's easier for us to find the problem in a small program.

Also post your compiler version.
bharatwalia



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 10:30 pm     Reply with quote

compiler version 4.084

Code:



#include <16f876A.h>
#device adc=10
#include <math.h>

void calPower(void);

unsigned int32 adc_voltage=751,adc_current=170,res,mode=0;
float power,volts,current;
float result_power;
byte cnt=0;


void main()
{

   cpuSetup();

   while(1)
      {
                  
               calPower();
               
      
                     
      }
}

//--------------------------------------------------------
void calPower(void)
{   
   volts=0;
   current=0;
   result_power=0;
   

   volts=(300*adc_voltage)/1023;
   current=(300*adc_current)/1023;

   power=(volts*current)/1000.00;                     //in KW.
   
//   result_power=(1023.00/300.00)*power;
   result_power=ceil(11.95);   
   
}
//--------------------------------------------------------

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 11:56 pm     Reply with quote

That program is not complete. It calls 'cpuSetup()' but there is no
function definition for that function.
Quote:

void main()
{

cpuSetup();
while(1)
{

calPower();

}
}

But anyway, I commented out 'cpuSetup();' and it compiled with no
errors with vs. 4.084:
Code:

CCS PCM C Compiler, Version 4.084, xxxxx        30-Jul-10 22:53
               Filename: pcm_test.lst
               ROM used: 1530 words (19%)
                         Largest free fragment is 2048
               RAM used: 39 (11%) at main() level
                         79 (21%) worst case
               Stack:    2 locations


Executing: "C:\Program Files\PICC\Ccsc.exe" "pcm_test.c" +FM +DF +LY -T -A +M -Z +Y=9 +EA -EW
      Memory usage:   ROM=19%      RAM=11% - 21%
      0 Errors,  0 Warnings.
Loaded C:\Program Files\PICC\Projects\PCM_Test\pcm_test.cof.
BUILD SUCCEEDED: Fri Jul 30 22:53:27 2010


Please post a program that is complete (has all necessary function
definitions) and that you have tested.

Also, I suggest that you re-install the compiler.
bharatwalia



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 12:20 am     Reply with quote

this is my complete program

Code:


/*----------------------------------------------------------SUNOXER DIGITAL METER------------------------------------------------------*/
#include <16f876A.h>
#device adc=10
#include <math.h>

#include <timers.h>
#include <button.c>

#USE DELAY( CLOCK=4000000) /* Using a 4 Mhz clock */
#FUSES XT,NOWDT,NOPROTECT,NOPUT
#PRIORITY INT_TIMER1,INT_RTCC

#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000     5ms
#define  INTERRUPT_OVERHEAD            500   //cycles wasted
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))

#USE FAST_IO(B)
#USE FAST_IO(C)


// These are the "Bvar" variables required by Button.c.
int8 C0 = 0;   // For the button on pin C1
int8 C1 = 0;   // For the button on pin C2
int8 C2 = 0;   // For the button on pin C2


void cpuSetup(void);
void HTO7S(unsigned int32 Num);
void display();
void readADCdata(void);
void calPower(void);
void checkButton(void);

#byte port_b=6 /* define the location of register port_b */
#byte port_c=7 /* define the location of register port_c */

byte CONST LED_MAP[11] = {0x81,0xF3,0x49,0x61,0x33,0x25,0x05,0xF1,0x01,0x21,0xFF};

//                          0    1    2    3    4    5    6    7    8    9   OFF
byte Column[4]   = {0x80,0x40,0x20,0x10};         //Low bits(right,center,left)
byte Segment[4] = {0x25,0xC7,0x57,0x5F};            // S , u, n, r

unsigned int32 adc_voltage=0,adc_current=0,res,mode=0;
float power,volts,current;
float result_power;
byte cnt=0;

//--------------------------------------------------------
#INT_TIMER1
void Timer1(void)
{   
   set_timer1(TMR1RESET);
   display();   
   
}   

//--------------------------------------------------------
//--------------------------------------------------------

void display()
{
   
if(cnt>=4){
cnt=0;}
port_b=Segment[cnt];
//port_b=0x25;
port_c=Column[cnt];
cnt++;
   
}
//--------------------------------------------------------
//--------------------------------------------------------
// The rtcc interrupt occurs when the rtcc rolls over from FF to 00.
// I have programmed it to interrupt at a 100 Hz rate.
//
// RTCC interrupt rate = Fosc / (4 * rtcc pre-scaler * rtcc pre-load)
//
//                     = 4 MHz / (4 * 256 * 39)
//
//                     = 100.16 Hz
//
// This gives us a timer tick approx. every 10 ms  (9.98 ms actually).

#INT_RTCC
void rtcc_isr(void)
{
// Reload the RTCC, so it will keep overflowing every 10 ms.
set_rtcc(RTCC_PRELOAD);

// Decrement any timers that are running.

if(gc_refresh_timer)                                     //7-Segment counter to count down till 500ms for 7-Segment refresh rate
   gc_refresh_timer--;

if(gc_button_timer)                                     //Buttons counter to count till 40ms for buttons scan
   gc_button_timer--;

}

//--------------------------------------------------------
void cpuSetup(void)
{
      setup_counters(RTCC_INTERNAL,RTCC_DIV_256);       //setting timer0 for display refesh rate and for scanning buttons
       enable_interrupts(INT_RTCC);

      setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);            //no division
       set_timer1(TMR1RESET);                           //65535-4965=60570
         enable_interrupts(INT_TIMER1);                   //timer1 for 7-Segment display
      enable_interrupts(GLOBAL);

      setup_adc_ports(AN0_AN1_AN3);                   //Setting ADC Channels
      setup_adc(ADC_CLOCK_DIV_64);

   
      set_tris_b(0x01);
      set_tris_c(0x07);

      
      delay_ms(1500);

      gc_refresh_timer = REFRESH_TIMER_TICKS;             //Display Counter
      gc_button_timer = BUTTON_TIMER_TICKS;               //Buttons Counter
}
//--------------------------------------------------------
//--------------------------------------------------------MAIN PROGRAM STARTS-----------------------------------------------

void main()
{

   cpuSetup();

   while(1)
      {
         
         switch(mode){
         case 0:   
               
               Column[3]=0x00;
               readADCdata();
               HTO7S(adc_voltage);
               checkButton();
               break;
         case 1:
               Column[3]=0x10;
            
               readADCdata();
               HTO7S(adc_current);
               checkButton();
               break;
         case 2:
               Column[3]=0x10;
               
               readADCdata();
               calPower();
               HTO7S(result_power);
               checkButton();
               break;   
      
      }
               
      }
}

//--------------------------------------------------------
void HTO7S(unsigned int32 Num)
{
   unsigned int32 res;
   if(gc_refresh_timer)
   return;
else
  gc_refresh_timer = REFRESH_TIMER_TICKS;               //500ms interrupt to control display refresh rate
//   output_toggle(PIN_C3);                           //for testing only
   
   
                                    
   Segment[0]=LED_MAP[30*Num/10230];                     //calculating look-up value from LED_MAP array.
   if (Segment[0]==0x81)                               //turning off 1st digit if 0
   Segment[0]=0xFF;                                    //dividing the three digits

   res = 30*Num%10230;
   Segment[1]=LED_MAP[10*res/10230];

   res=10*res%10230;
   Segment[2]=LED_MAP[10*res/10230];

   res=10*res%10230;
   Segment[3]=LED_MAP[10*res/10230];

   
}
//--------------------------------------------------------
void calPower(void)
{   
   volts=0;
   current=0;
   result_power=0;
   

   volts=(300*adc_voltage)/1023;
   current=(300*adc_current)/1023;

   power=(volts*current)/1000.00;                     //in KW.
   
//   result_power=(1023.00/300.00)*power;
   result_power=ceil(11.95);   
   
}
//--------------------------------------------------------
void checkButton(void)
{
   if(gc_button_timer)
      return;
      else
     gc_button_timer = BUTTON_TIMER_TICKS;
      if(button(PIN_C0, 0, 50, 10, C0, 1)){
            mode=0;                                 //changing the mode.
      }
   if(button(PIN_C1, 0, 50, 10, C1, 1)){
            mode=1;                                 //changing the mode.
      }
         
   if(button(PIN_C2, 0, 50, 10, C2, 1)){
            mode=2;                                 //changing the mode.
      }
   
}
//--------------------------------------------------------
void readADCdata(void)
{
   adc_voltage=0;
   adc_current=0;   
               
         
            set_adc_channel(0);
            delay_us(10);            //-------->NOTE:AQUISITION TIME NECCESARY
            adc_voltage=read_adc();         //reading voltage
            delay_us(10);
            set_adc_channel(1);
            delay_us(10);            //-------->NOTE:AQUISITION TIME NECCESARY
            adc_current=read_adc();         //reading current
            delay_us(100);
            
            
}
//-------------------------------------------------------

/*------------------------------------------------------END OF PROGRAM----------------------------------------------*/



thanks

Error:


*** Error 112 "simple_meter.c" Line 205(1,1): Function used but not defined: ... ceil SCR=862

i now re-install the compiler and then i'll agan compile it
bharatwalia



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 1:09 am     Reply with quote

i re-installed the compiler and still getting the same error....
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 1:33 am     Reply with quote

Quote:
this is my complete program

It isn't, unfortunately. After commenting function calls to missing include files, it compiles without problems (also in V4.084).
bharatwalia



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 1:58 am     Reply with quote

I tried compiling this program on my other PC which has version 4.106 but the error is same.

I hope I am making some mistake in the syntax or so.

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19262

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 2:07 am     Reply with quote

It is common in CCS, for a problem to be a long way from the line reporting it. I'd guess in one of your include files (button.c, since this is the only one that you have written - unless you have modified the standard compiler files), you have a function defintion, that has perhaps the wrong number of brackets. Then the code carries on compiling OK, till it gets to line 205 in the main, where it 'spots' the imbalance.

Best Wishes
bharatwalia



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 2:26 am     Reply with quote

i removed the button.c header file and compiled the program, i even compile the small piece of code proved above but the error remains same with "math.h"

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19262

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 2:41 am     Reply with quote

You are missing the point.
The code posted _is_ OK. It may well have operational faults, but compiles fine. If we take what you have posted, modify the header, so that it doesn''t load your other include files, and add dummies for the undefined things (variables and a function), it _works_ without any error.

If I take exactly what you have posted, and change the first dozen lines, to:
Code:

#include <16f876A.h>
#device adc=10
#include <math.h>

//#include <timers.h>
//#include <button.c>
int8 gc_button_timer,gc_refresh_timer;

#USE DELAY( CLOCK=4000000) /* Using a 4 Mhz clock */
#FUSES XT,NOWDT,NOPROTECT,NOPUT
#PRIORITY INT_TIMER1,INT_RTCC

#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000     5ms
#define  INTERRUPT_OVERHEAD            500   //cycles wasted
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))

#USE FAST_IO(B)
#USE FAST_IO(C)

#define RTCC_PRELOAD (200)
#define REFRESH_TIMER_TICKS (10)
#define BUTTON_TIMER_TICKS (10)
int8 button(int16 val, int8 v1, int8 v2, int8 v3, int8 v4, int8 v5) {
   return 1;
}

It is fine.

Your fault _is_ in one of your other include files. It may well be 'math.h', _if_ you have edited the file. But with the supplied files from CCS, this code compiles...

Best Wishes
bharatwalia



Joined: 04 May 2009
Posts: 35
Location: India

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 3:08 am     Reply with quote

Hi,
I deleted the math.h file and again copy and pasted it now it compiles.

Thanks
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Mon Jan 06, 2014 10:30 am     Reply with quote

bharatwalia wrote:
this is my complete program

Code:


/*----------------------------------------------------------SUNOXER DIGITAL METER------------------------------------------------------*/
#include <16f876A.h>
#device adc=10
#include <math.h>

#include <timers.h>
#include <button.c>

#USE DELAY( CLOCK=4000000) /* Using a 4 Mhz clock */
#FUSES XT,NOWDT,NOPROTECT,NOPUT
#PRIORITY INT_TIMER1,INT_RTCC

#define  TICKS_BETWEEN_INTERRUPTS      5000 //5000     5ms
#define  INTERRUPT_OVERHEAD            500   //cycles wasted
#define  TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))

#USE FAST_IO(B)
#USE FAST_IO(C)


// These are the "Bvar" variables required by Button.c.
int8 C0 = 0;   // For the button on pin C1
int8 C1 = 0;   // For the button on pin C2
int8 C2 = 0;   // For the button on pin C2


void cpuSetup(void);
void HTO7S(unsigned int32 Num);
void display();
void readADCdata(void);
void calPower(void);
void checkButton(void);

#byte port_b=6 /* define the location of register port_b */
#byte port_c=7 /* define the location of register port_c */

byte CONST LED_MAP[11] = {0x81,0xF3,0x49,0x61,0x33,0x25,0x05,0xF1,0x01,0x21,0xFF};

//                          0    1    2    3    4    5    6    7    8    9   OFF
byte Column[4]   = {0x80,0x40,0x20,0x10};         //Low bits(right,center,left)
byte Segment[4] = {0x25,0xC7,0x57,0x5F};            // S , u, n, r

unsigned int32 adc_voltage=0,adc_current=0,res,mode=0;
float power,volts,current;
float result_power;
byte cnt=0;

//--------------------------------------------------------
#INT_TIMER1
void Timer1(void)
{   
   set_timer1(TMR1RESET);
   display();   
   
}   

//--------------------------------------------------------
//--------------------------------------------------------

void display()
{
   
if(cnt>=4){
cnt=0;}
port_b=Segment[cnt];
//port_b=0x25;
port_c=Column[cnt];
cnt++;
   
}
//--------------------------------------------------------
//--------------------------------------------------------
// The rtcc interrupt occurs when the rtcc rolls over from FF to 00.
// I have programmed it to interrupt at a 100 Hz rate.
//
// RTCC interrupt rate = Fosc / (4 * rtcc pre-scaler * rtcc pre-load)
//
//                     = 4 MHz / (4 * 256 * 39)
//
//                     = 100.16 Hz
//
// This gives us a timer tick approx. every 10 ms  (9.98 ms actually).

#INT_RTCC
void rtcc_isr(void)
{
// Reload the RTCC, so it will keep overflowing every 10 ms.
set_rtcc(RTCC_PRELOAD);

// Decrement any timers that are running.

if(gc_refresh_timer)                                     //7-Segment counter to count down till 500ms for 7-Segment refresh rate
   gc_refresh_timer--;

if(gc_button_timer)                                     //Buttons counter to count till 40ms for buttons scan
   gc_button_timer--;

}

//--------------------------------------------------------
void cpuSetup(void)
{
      setup_counters(RTCC_INTERNAL,RTCC_DIV_256);       //setting timer0 for display refesh rate and for scanning buttons
       enable_interrupts(INT_RTCC);

      setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);            //no division
       set_timer1(TMR1RESET);                           //65535-4965=60570
         enable_interrupts(INT_TIMER1);                   //timer1 for 7-Segment display
      enable_interrupts(GLOBAL);

      setup_adc_ports(AN0_AN1_AN3);                   //Setting ADC Channels
      setup_adc(ADC_CLOCK_DIV_64);

   
      set_tris_b(0x01);
      set_tris_c(0x07);

      
      delay_ms(1500);

      gc_refresh_timer = REFRESH_TIMER_TICKS;             //Display Counter
      gc_button_timer = BUTTON_TIMER_TICKS;               //Buttons Counter
}
//--------------------------------------------------------
//--------------------------------------------------------MAIN PROGRAM STARTS-----------------------------------------------

void main()
{

   cpuSetup();

   while(1)
      {
         
         switch(mode){
         case 0:   
               
               Column[3]=0x00;
               readADCdata();
               HTO7S(adc_voltage);
               checkButton();
               break;
         case 1:
               Column[3]=0x10;
            
               readADCdata();
               HTO7S(adc_current);
               checkButton();
               break;
         case 2:
               Column[3]=0x10;
               
               readADCdata();
               calPower();
               HTO7S(result_power);
               checkButton();
               break;   
      
      }
               
      }
}

//--------------------------------------------------------
void HTO7S(unsigned int32 Num)
{
   unsigned int32 res;
   if(gc_refresh_timer)
   return;
else
  gc_refresh_timer = REFRESH_TIMER_TICKS;               //500ms interrupt to control display refresh rate
//   output_toggle(PIN_C3);                           //for testing only
   
   
                                    
   Segment[0]=LED_MAP[30*Num/10230];                     //calculating look-up value from LED_MAP array.
   if (Segment[0]==0x81)                               //turning off 1st digit if 0
   Segment[0]=0xFF;                                    //dividing the three digits

   res = 30*Num%10230;
   Segment[1]=LED_MAP[10*res/10230];

   res=10*res%10230;
   Segment[2]=LED_MAP[10*res/10230];

   res=10*res%10230;
   Segment[3]=LED_MAP[10*res/10230];

   
}
//--------------------------------------------------------
void calPower(void)
{   
   volts=0;
   current=0;
   result_power=0;
   

   volts=(300*adc_voltage)/1023;
   current=(300*adc_current)/1023;

   power=(volts*current)/1000.00;                     //in KW.
   
//   result_power=(1023.00/300.00)*power;
   result_power=ceil(11.95);   
   
}
//--------------------------------------------------------
void checkButton(void)
{
   if(gc_button_timer)
      return;
      else
     gc_button_timer = BUTTON_TIMER_TICKS;
      if(button(PIN_C0, 0, 50, 10, C0, 1)){
            mode=0;                                 //changing the mode.
      }
   if(button(PIN_C1, 0, 50, 10, C1, 1)){
            mode=1;                                 //changing the mode.
      }
         
   if(button(PIN_C2, 0, 50, 10, C2, 1)){
            mode=2;                                 //changing the mode.
      }
   
}
//--------------------------------------------------------
void readADCdata(void)
{
   adc_voltage=0;
   adc_current=0;   
               
         
            set_adc_channel(0);
            delay_us(10);            //-------->NOTE:AQUISITION TIME NECCESARY
            adc_voltage=read_adc();         //reading voltage
            delay_us(10);
            set_adc_channel(1);
            delay_us(10);            //-------->NOTE:AQUISITION TIME NECCESARY
            adc_current=read_adc();         //reading current
            delay_us(100);
            
            
}
//-------------------------------------------------------

/*------------------------------------------------------END OF PROGRAM----------------------------------------------*/



thanks

Error:


*** Error 112 "simple_meter.c" Line 205(1,1): Function used but not defined: ... ceil SCR=862

i now re-install the compiler and then i'll agan compile it


any body can draw its SCH diagram . .?
_________________
sahu
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