go_away

Author Topic: Errors with delays.h header  (Read 4489 times)

0 Members and 1 Guest are viewing this topic.

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Errors with delays.h header
« on: July 06, 2011, 08:55:36 PM »
Hi:

I am using the MPLAB IDE to program a PIC24.  I am getting an abundance of errors when trying to use a code I found at pyro-electro.  The code should just create a pulse to move a servo.  Any ideas why this might be happening?

I thought I attached the header files, and linker scripts correctly.  I have attached the build failure, please advise.

Thanks!

Code: [Select]
#include<stdio.h>
#include<p24HJ32GP202.h>
#include <delays.h>

void main(void)
{

int count=0;

TRISB = 0x00;
PORTB = 0x00;

while(1)
{

for(count=0;count<50;count++)
{  //far counter-clockwise
PORTB = 0x01;
Delay1KTCYx(10);
PORTB = 0x00;
Delay1KTCYx(90);
}
//middle
for(count=0;count<50;count++)
{
PORTB = 0x01;
Delay1KTCYx(7);
Delay100TCYx(5);
PORTB = 0x00;
Delay1KTCYx(92);
Delay100TCYx(5);
}
for(count=0;count<50;count++)
{  //far counter-clockwise
PORTB = 0x01;
Delay1KTCYx(5);
//Delay100TCYx(5);
PORTB = 0x00;
Delay1KTCYx(95);
//Delay100TCYx(5);
}
;}
}

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Errors with delays.h header
« Reply #1 on: July 07, 2011, 04:01:34 AM »
Code: [Select]
//Delay100TCYx(5);
}
;}
}

Last three lines... is that semicolon supposed to be there?  (Right before the right bracket?)  It looks like it goes to the while loop but I can't think of any reason it'd be there, especially like that.  

Usually when I get a bunch of unknown/weird errors it's a missing/extra semicolon somewhere near the start of my program, causing cascading errors the rest of the way through.  
« Last Edit: July 07, 2011, 04:04:08 AM by corrado33 »

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #2 on: July 07, 2011, 07:35:30 AM »
Good eye that semi colon definitely looked misplaced, however, I removed it and the errors remain. I have the errors as an attached file.

The errors all site the delay.h path so here is my delay.h (look for errors line 28, 40, 51, 62,73):
Code: [Select]
#ifndef __DELAYS_H
#define __DELAYS_H

/* PIC 17Cxxx and 18Cxxx cycle-count delay routines.
 *
 *   Functions:
 * Delay1TCY()
 *               Delay10TCY()  // 17Cxx only
 *               Delay10TCYx()
 *               Delay100TCYx()
 *               Delay1KTCYx()
 *               Delay10KTCYx()
 */

/* Delay of exactly 1 Tcy */
#define Delay1TCY() Nop()

#if __18CXX
#define PARAM_SCLASS auto
#else
#define PARAM_SCLASS static
#endif

/* Delay of exactly 10 Tcy */
#if    __18CXX
#define Delay10TCY() Delay10TCYx(1)
#else /* 17CXX */
far void Delay10TCY(void);
#endif

/* Delay10TCYx
 * Delay multiples of 10 Tcy
 * Passing 0 (zero) results in a delay of 2560 cycles.
 * The 18Cxxx version of this function supports the full range [0,255]
 * The 17Cxxx version supports [2,255] and 0.
 */
#if    __18CXX
void Delay10TCYx(PARAM_SCLASS unsigned char);
#else /* 17CXX */
far void Delay10TCYx(PARAM_SCLASS unsigned char);
#endif

/* Delay100TCYx
 * Delay multiples of 100 Tcy
 * Passing 0 (zero) results in a delay of 25,600 cycles.
 * The full range of [0,255] is supported.
 */
#if    __18CXX
void Delay100TCYx(PARAM_SCLASS unsigned char);
#else /* 17CXX */
far void Delay100TCYx(PARAM_SCLASS unsigned char);
#endif

/* Delay1KTCYx
 * Delay multiples of 1000 Tcy
 * Passing 0 (zero) results in a delay of 256,000 cycles.
 * The full range of [0,255] is supported.
 */
#if    __18CXX
void Delay1KTCYx(PARAM_SCLASS unsigned char);
#else /* 17CXX */
far void Delay1KTCYx(PARAM_SCLASS unsigned char);
#endif

/* Delay10KTCYx
 * Delay multiples of 10,000 Tcy
 * Passing 0 (zero) results in a delay of 2,560,000 cycles.
 * The full range of [0,255] is supported.
 */
#if    __18CXX
void Delay10KTCYx(PARAM_SCLASS unsigned char);
#else /* 17CXX */
far void Delay10KTCYx(PARAM_SCLASS unsigned char);
#endif

#endif

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 98
Re: Errors with delays.h header
« Reply #3 on: July 07, 2011, 10:31:59 AM »
Just for a test try putting a copy of delay.h in the same folder as the source file and replace the <> with "" to tell the assembler to look in the local folder.
If the errors go away then it is a path issue. Check that the search paths are correctly setup in MPLAB for the PIC24 assembler.

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Errors with delays.h header
« Reply #4 on: July 07, 2011, 12:27:13 PM »
Is the "far" keyword supported by your compiler?

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Errors with delays.h header
« Reply #5 on: July 07, 2011, 02:31:38 PM »
Is the "far" keyword supported by your compiler?

This.

I honestly have no idea what "far" does, but it looks like something doesn't like it. 

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #6 on: July 07, 2011, 02:57:22 PM »
I performed waltr's test and accessed the header file from the local file, but the errors remain. So hopefully I can confidently state it is not a directory issue.

Now I will try to search this elusive "far".  The compiler is C30, but I'm not sure how ill find out if the compiler knows what it means... so I search

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Errors with delays.h header
« Reply #7 on: July 07, 2011, 03:02:38 PM »
It's something I haven't seen in a long time, I'd doubt many (if any) modern compiler supports it - think it was something to do with allowing 16bit pointers to address data in foreign segments, i.e. to use a 16bit offset from a different base address, though I'd look it up if you wanted to be sure, from the foggy past ...
You could try just deleting each occurrence of the word "far" from that header file.

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Errors with delays.h header
« Reply #8 on: July 07, 2011, 03:47:10 PM »
You could try just deleting each occurrence of the word "far" from that header file.

Or just delete one and see if it gives you one less error.   :)

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #9 on: July 07, 2011, 03:53:10 PM »
deleting each occurrence of the word far got rid of more than half of the errors. this is the current error list

Code: [Select]
Executing: "C:\Program Files (x86)\Microchip\mplabc30\v3.25\bin\pic30-gcc.exe" -mcpu=24HJ32GP202 -x c -c   "single_servo.c" -o"single_servo.o" -g -Wall
In file included from single_servo.c:3:
c:/program files (x86)/microchip/mplabc30/v3.25/bin/bin/../../support/PIC24H/h/delays.h:40: error: storage class specified for parameter 'type name'
c:/program files (x86)/microchip/mplabc30/v3.25/bin/bin/../../support/PIC24H/h/delays.h:51: error: storage class specified for parameter 'type name'
c:/program files (x86)/microchip/mplabc30/v3.25/bin/bin/../../support/PIC24H/h/delays.h:62: error: storage class specified for parameter 'type name'
c:/program files (x86)/microchip/mplabc30/v3.25/bin/bin/../../support/PIC24H/h/delays.h:73: error: storage class specified for parameter 'type name'
single_servo.c:6: warning: return type of 'main' is not 'int'

single_servo.c:43:2: warning: no newline at end of file
Halting build on first failure as requested.
BUILD FAILED: Thu Jul 07 17:49:24 2011

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Errors with delays.h header
« Reply #10 on: July 07, 2011, 04:09:12 PM »
Again, I think this is a legacy thing, compiler incompatibility, try deleting PARAM_SCLASS from each of those formal parameter lists i.e. on each of the lines it gives you the error.

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Errors with delays.h header
« Reply #11 on: July 07, 2011, 04:09:18 PM »
Do the above idea first.  They sound like they have a TON more experience than I do.  lol

I'm no expert, but I'd say it's not liking this...

Code: [Select]
far void Delay10TCY(void);
That "void" in the "()" I've never seen before.  It's like you're sending the Delay10TCY function "nothing", and it doesn't like that.  Maybe post that function if you haven't already?  

This is why I don't like to use other people's code.  When you don't do it yourself you don't know how it works.  

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Errors with delays.h header
« Reply #12 on: July 07, 2011, 04:17:27 PM »
The func(void) is ok, it's just explicitly stating there's no params.
However, i dont think you can specify storage class in a parameter list e.g. func(auto int myInt). The params go on the stack i.e. the compiler decides where they're stored. Maybe there was a compiler once that allowed you to hint where you wanted the params stored but I don't know of any now that will let you do this.
Slightly worried that if you do get this to compile you'll just run into more and more issues like this, does appear to be very old code!

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #13 on: July 07, 2011, 05:04:01 PM »
So maybe we just throw out this code.  I was just looking for a code, so that I could sample my Futaba S31114 servo, and learn from/modify it.

Any suggestions on a code I can use with this set up that will work? 

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Errors with delays.h header
« Reply #14 on: July 07, 2011, 05:17:38 PM »
Did you try deleting the PARAM_SCLASS?

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Errors with delays.h header
« Reply #15 on: July 07, 2011, 05:27:19 PM »
Did you try deleting the PARAM_SCLASS?

Try this first, if not, tell us exactly what you want to do.

When you say "sample" do you mean you just want to see it work?  Controlling a servo isn't extremely hard it just requires that you understand what it needs to work.

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #16 on: July 07, 2011, 07:28:57 PM »
Deleted PARAM_SCLASS.  Now the only problem is with the original code to move the servo, error stating
Code: [Select]
undefined reference to `Delay1KTCYx'

I can work with this if we can get it to run... the function isn't being recognized?

just in case this is how my delay.h looks now:
Code: [Select]
#ifndef __DELAYS_H
#define __DELAYS_H

/* PIC 17Cxxx and 18Cxxx cycle-count delay routines.
 *
 *   Functions:
 * Delay1TCY()
 *               Delay10TCY()  // 17Cxx only
 *               Delay10TCYx()
 *               Delay100TCYx()
 *               Delay1KTCYx()
 *               Delay10KTCYx()
 */

/* Delay of exactly 1 Tcy */
#define Delay1TCY() Nop()

#if __18CXX
#define auto
#else
#define static
#endif

/* Delay of exactly 10 Tcy */
#if    __18CXX
#define Delay10TCY() Delay10TCYx(1)
#else /* 17CXX */
void Delay10TCY(void);
#endif

/* Delay10TCYx
 * Delay multiples of 10 Tcy
 * Passing 0 (zero) results in a delay of 2560 cycles.
 * The 18Cxxx version of this function supports the full range [0,255]
 * The 17Cxxx version supports [2,255] and 0.
 */
#if    __18CXX
void Delay10TCYx(unsigned char);
#else /* 17CXX */
void Delay10TCYx(unsigned char);
#endif

/* Delay100TCYx
 * Delay multiples of 100 Tcy
 * Passing 0 (zero) results in a delay of 25,600 cycles.
 * The full range of [0,255] is supported.
 */
#if    __18CXX
void Delay100TCYx(unsigned char);
#else /* 17CXX */
void Delay100TCYx(unsigned char);
#endif

/* Delay1KTCYx
 * Delay multiples of 1000 Tcy
 * Passing 0 (zero) results in a delay of 256,000 cycles.
 * The full range of [0,255] is supported.
 */
#if    __18CXX
void Delay1KTCYx(unsigned char);
#else /* 17CXX */
void Delay1KTCYx(unsigned char);
#endif

/* Delay10KTCYx
 * Delay multiples of 10,000 Tcy
 * Passing 0 (zero) results in a delay of 2,560,000 cycles.
 * The full range of [0,255] is supported.
 */
#if    __18CXX
void Delay10KTCYx(unsigned char);
#else /* 17CXX */
void Delay10KTCYx(unsigned char);
#endif

#endif

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #17 on: July 07, 2011, 08:17:39 PM »
Disregard the last code insertion, I read richiereynolds suggestion more closely and he instructed me to delete PARAM_SCLASS from only the lines giving me the "type-name" error, so now I did that, but the same "undefined reference" errors... remain.

Corrado33 I do just want to watch it do something, I recently acquired an animatronic hand, Mecha TE, and I'm trying to start somewhere, a finger wiggle would be nice.  Once I can get going with driving servos (software) I will learn how to close all the fingers in to a fist. Maybe there is some prewritten code for that? Probably not a good idea though, like someone said its better to write it yourself.

Ultimately, I will use EMG signals from my extensor carpi to drive the animatronic hand to close in parallel with my own hand.

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Errors with delays.h header
« Reply #18 on: July 08, 2011, 02:13:54 AM »
What's the whole error? I take it you're getting that undefined reference in another file? Can we see that file? Is that file properly including your delays.h header?

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #19 on: July 08, 2011, 06:39:54 AM »
Correct Richie, the error appears in the single_servo.c file, which should move the servo between two positions.

the whole error:
Code: [Select]
       
C:\test\single_servo.c:19: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x22):C:\test\single_servo.c:21: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x38):C:\test\single_servo.c:27: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x3c):C:\test\single_servo.c:28: undefined reference to `Delay100TCYx'
single_servo.o(.text+0x44):C:\test\single_servo.c:30: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x48):C:\test\single_servo.c:31: undefined reference to `Delay100TCYx'
single_servo.o(.text+0x5e):C:\test\single_servo.c:36: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x66):C:\test\single_servo.c:39: undefined reference to `Delay1KTCYx'

single_servo code:
Code: [Select]
#include<stdio.h>
#include<p24HJ32GP202.h>
#include <delays.h>

void main(void)
{

int count=0;

TRISB = 0x00;
PORTB = 0x00;

while(1)
{

for(count=0;count<50;count++)
{  //far counter-clockwise
PORTB = 0x01;
Delay1KTCYx(10);
PORTB = 0x00;
Delay1KTCYx(90);
}
//middle
for(count=0;count<50;count++)
{
PORTB = 0x01;
Delay1KTCYx(7);
Delay100TCYx(5);
PORTB = 0x00;
Delay1KTCYx(92);
Delay100TCYx(5);
}
for(count=0;count<50;count++)
{  //far counter-clockwise
PORTB = 0x01;
Delay1KTCYx(5);
//Delay100TCYx(5);
PORTB = 0x00;
Delay1KTCYx(95);
//Delay100TCYx(5);
}
}
}

just in case, the whole build:
Code: [Select]
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\test\single_servo.o".
Clean: Done.
Executing: "C:\Program Files (x86)\Microchip\mplabc30\v3.25\bin\pic30-gcc.exe" -mcpu=24HJ32GP202 -x c -c   "single_servo.c" -o"single_servo.o" -g -Wall
single_servo.c:6: warning: return type of 'main' is not 'int'
single_servo.c:43:2: warning: no newline at end of file
Executing: "C:\Program Files (x86)\Microchip\mplabc30\v3.25\bin\pic30-gcc.exe" -mcpu=24HJ32GP202 "single_servo.o" -o"single_servo.cof" -Wl,--script="C:\Program Files (x86)\Microchip\mplabc30\v3.25\support\PIC24H\gld\p24HJ32GP202.gld",-Map="single_servo.map",--report-mem


Program Memory  [Origin = 0x200, Length = 0x5600]

section                    address   length (PC units)   length (bytes) (dec)
-------                    -------   -----------------   --------------------
.text                        0x200                0x90            0xd8  (216)
.text                        0x290                0x72            0xab  (171)
.dinit                       0x302                 0x2             0x3  (3)
.isr                         0x304                 0x2             0x3  (3)

                     Total program memory used (bytes):          0x189  (393) 1%


Data Memory  [Origin = 0x800, Length = 0x800]

section                    address      alignment gaps    total length  (dec)
-------                    -------      --------------    -------------------

                        Total data memory used (bytes):              0  (0)


Dynamic Memory Usage

region                     address                      maximum length  (dec)
------                     -------                      ---------------------
heap                             0                                   0  (0)
stack                        0x800                               0x800  (2048)

                        Maximum dynamic memory (bytes):          0x800  (2048)

single_servo.o(.text+0x1a): In function `main':
C:\test\single_servo.c:19: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x22):C:\test\single_servo.c:21: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x38):C:\test\single_servo.c:27: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x3c):C:\test\single_servo.c:28: undefined reference to `Delay100TCYx'
single_servo.o(.text+0x44):C:\test\single_servo.c:30: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x48):C:\test\single_servo.c:31: undefined reference to `Delay100TCYx'
single_servo.o(.text+0x5e):C:\test\single_servo.c:36: undefined reference to `Delay1KTCYx'
single_servo.o(.text+0x66):C:\test\single_servo.c:39: undefined reference to `Delay1KTCYx'
Link step failed.
BUILD FAILED: Thu Jul 07 22:04:35 2011

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: Errors with delays.h header
« Reply #20 on: July 08, 2011, 07:46:33 AM »
Looks like your header file isn't actually being included i.e. an include path issue, though I'd expect the compiler to report that it can't find the file so not certain.

On second look, the output from the compiler isn't what I'm used to, doesn't look to be very well separated into compilation and linking phases, but I noticed it does say "link step failed" at the end - so the include is probably ok, but where is the actual definition of those DelayXXX prototypes in the header? Were they supplied in another C file that you need to also compile? Or a compiled library that you need to link with?
« Last Edit: July 08, 2011, 05:01:40 PM by richiereynolds »

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #21 on: July 11, 2011, 04:26:51 PM »
This is where my inexperience fails me.  I didn't realize that delays.h didn't actually define those functions.

My compiler didn't have delays.h in the library, so I found it at a website called Koders. I could try to find the missing piece, but I'm not sure what the file name would be for any compiled library, or C file that I need.  In that case I'm not sure that we can keep going with this code.

Can you direct me to a sample code to arbitrarily move a servo motor, that doesn't require any obscure header files?  I don't know how to code a delay precise enough to create an accurate pulse.  Up until now if I needed to create a delay in C I would just make some counter for loops.  But to implement PWM I dont think that will work...?

From my understanding the delay function takes into account processing cycles.  If I know my processor speed and instructions per second is it possible to use for loops to create pulses or is that just silly?
« Last Edit: July 11, 2011, 04:31:35 PM by freddie00 »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 98
Re: Errors with delays.h header
« Reply #22 on: July 11, 2011, 05:24:25 PM »
Coding delay functions are rather basic and a necessary learning experience when working with micro-controllers.

MPLAB has a simulator that can be used to test and measure the delay time so it isn't hard to get the dealy function working. Here is a good tutorial that uses software delays:
http://www.gooligum.com.au/tutorials.html

Offline freddie00Topic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Errors with delays.h header
« Reply #23 on: July 12, 2011, 12:08:34 PM »
Thanks.  I have noticed that the tutorial uses assembly language to code the delays, is this standard practice with micro controllers, or can you use a higher level language like C?

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Errors with delays.h header
« Reply #24 on: July 12, 2011, 02:16:40 PM »
To program delays in C, I simply set up a timer on the microcontroller.

This site has a tutorial on timers, you should read it.  :)

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 98
Re: Errors with delays.h header
« Reply #25 on: July 12, 2011, 02:28:34 PM »
For accurate software delays assembler is common. Accurate delays can be done in C but just beware of any optimizing done by the compiler. Do use the MPLAB simulator to test, measure and debug you functions. A simple delay function in C goes like this:

void delay(int x){
    int i;
    for(i=0 ;i<x; i++){
        nop();                       // putting code line here increases the delay time per loop
    }                                   //  and can keep the compiler from removing the loop
}

Offline corrado33

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Errors with delays.h header
« Reply #26 on: July 12, 2011, 03:33:39 PM »
void delay(int x){
    int i;
    for(i=0 ;i<x; i++){
        nop();                       // putting code line here increases the delay time per loop
    }                                   //  and can keep the compiler from removing the loop
}


I used to do delays like this, but I could never get the EXACT delay I wanted unless I played with it for a long time.  If they are trying to control a servo, do you think more precise timing would be required?

 


Get Your Ad Here

data_list