Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

HI-TECH programming problem

Status
Not open for further replies.

jameschia

New Member
I am using PIC16F877A to perform a calculation. But some error occurred after I include some trigonometry function and I have no idea with the error.

The errors state as below:

Error [1253] double.c; 55. could not find space (145 bytes) for auto/param block
Error [1253] C:\main display\delay.c; 35. could not find space (145 bytes) for auto/param block



My code is shown below:

//Project: Ultrasonic Range Finder Lesson
//Programmer: Shahrulnizam Mat Rejab
//PIDeg_C: PIDeg_C16F877Deg_A
//Deg_Crystal Frequency: 4MHz

#include <pic.h>
#include <htc.h>
#include <math.h>
#include <stdio.h>
#include "MyPIC16F874.h"
#include "delay.h"
#include "delay.c"
#include "lcd.h"

//Configuration
//=====================================================================
__CONFIG ( 0x3E31 );

#define BAUD 9600
#define _XTAL_FREQ 4000000

void pic_init(void);

void main()
{
const int Base1 = 200, Base2 = 200;
int display = 0;
int check = 0;
int X_cor = 0, Y_cor = 0;
double Range1, Range2, Range3;
double Xa_cor = 0, Ya_cor = 0, Xb_cor = 0, Yb_cor = 0, Xc_cor = 0, Yc_cor = 0;
double Deg_A = 0, Deg_B = 0, Deg_C = 0;



pic_init(); //initialize PIC
lcd_init(); //initialize LCD
lcd_goto(1,0); //select first line
lcd_puts("X : cm"); //display string
lcd_goto(2,0); //select second line
lcd_puts("Y : cm"); //display string




for(;;)
{
Range1 = 100;
Range2 = 100;
Range3 = 120;


check = Range1 * Range2 * Range3;

if (check > 0)
display = 1;
else
display = 0;

if (display == 1)
{


Deg_A = acos((Range1*Range1+Base1*Base1-Range1*Range1)/(2*Range1*Base1));

Xa_cor = Range1*cos(Deg_A);
Ya_cor = Range1*sin(Deg_A);

Deg_B = acos((Range2*Range2+Base1*Base1-Range1*Range1)/(2*Range2*Base1));

Xb_cor = Range2*cos(Deg_B);
Yb_cor = Range2*sin(Deg_B);

Deg_C = acos((Range3*Range3+Base2*Base2-Range2*Range2)/(2*Range3*Base2));

Xc_cor = Range3*sin(Deg_C);
Yc_cor = Range3*cos(Deg_C);

X_cor = ((Xa_cor)+(Base1-Xb_cor)+(Base1-Xc_cor))/3;
Y_cor = ((Ya_cor)+(Yb_cor)+(200-Yc_cor))/3;

lcd_goto(1, 5);
lcd_number(X_cor, 5, 3);
__delay_ms(100);

lcd_goto(2, 5);
lcd_number(Y_cor, 5, 3);
__delay_ms(100);

}

}
}
 
Hitech lite......The compiler packs the data with comma characters... (means you run out of ram sooner than you think)

Change the double's to float.. and see how it compiles.. a double takes some room and the math library takes an awful lot of ram...

I write my own math library for this reason...
 
You need more memory if you use the lite version of hitech.... This may be an indication to move up to pic18f4520 and C18 (students version is free)
There is always the new pic16f1939.... It has oodles more on board... its cheaper... it has twice as much memory... hitech 9.6 supports it..
 
erm... ok. I hope i can use back this PIC16F877A because i have done quite a lot of work for my project.
It is not a good idea for me to start everything in this stage.
 
Ok.. then you'll need to optimize the code your self..

Try to use one float and the use fixed point math... Remember the 877 has only 368 bytes of ram.. BUT there is also 256 bytes of eeprom.

Do you want my math routines? They are only accurate to 2 decimal places..

May I ask... Why do you need to use the pic16f877?... It's old and out of date!
 
I have also noticed... you are compiling for a pic16f877.... not a pic16f874 (specified in you code ) the 874 has only 4k memory and 198 byte ram......Nowhere near enough for these calculations.

I have just changed your code to work with fixed point and it compiles in only 52% of the code space and using only 36% of the ram space.

So it can be done.... I could upgrade the math routines to 3 decimal places...
 
Because this is the only PIC that I familiar with and I choose it as the controller for my final year project and i just notice this problem now.
what do you means by fixed point math? Can you upload the code that you have changed?
Two decimal point is very good for me already.
 
Last edited:
Hi.... I finished converting the tables last night.... but it was late so I went to bed.....I just need to test the code before I post.... I'll do this tonight when I get home.

I'm also converting the code to take a float and to return a float so you can interface much easier... I might post the math routines in the code repository so every one may use them.
 
ok. By the way, I just found that i just can use 20% of the RAM of my PIC.
This is because I am using a free version MPLAB and HI TECH compiler and this free software only allow me to use 20% of the PIC RAM.
I was trying to create a Look Up Table by myself but the memory still over flow when I trying to create the table.
 
Ok.... a few things to remember..... up to 90.0 degree.... ( you'll have to take care of 90 -180 - 270 - 360 ). But that's pretty simple...

arccos returns the angle to two decimal places..... there are a few instances where it's 0.01 out... (I use these routines on cranes so they work pretty well).

So we have... cosine(); sine(); arctan(); arccos(); and arcsin(); also we have abs();
 

Attachments

  • Mymath.c
    2.1 KB · Views: 169
  • Mymath.h
    229 bytes · Views: 137
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top