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

How to include a Microchip ASM file(s)?
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

How to include a Microchip ASM file(s)?
PostPosted: Fri Sep 04, 2009 12:40 am     Reply with quote

Hey there. On this page: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en020434

There is a document and a zip file relating to the implementation of a PID controller using a pic 18.

I'd like to give this a try to see if it produces a better result than our home grown solution. But there's really no documentation on usage beyond the rather abstract.

I don't know how to include such a file(s).
I don't know if I need to include both, or if the math one is implied somehow.
Both files seem to include p18f452.inc (where's it getting that from?) - does it matter that I'm not using a pic18f452 chip? I'm using a pic 18f4480.
I don't really know how to call the various functions, etc or to use it at all as virtually no syntax is given anywhere... but I'll cross that bridge when I get there.


Is there a way to convert this ASM file to a more readable c file? Probably not if my googling results were any indication.
Thanks.
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 2:12 am     Reply with quote

bloody hell this has been a frustrating and wasteful day.

So I gather I can't do the above.

I can't convert ASM to c.
I can't include an ASM file and access its functions from my c program.
The vast majority of Microchip's "Application Notes" files are completely useless to people programming in c?

this can't be the case.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 7:17 am     Reply with quote

As you already found out, the Microchip PID asm sources can't be simply included in CCS C for two reasons:
- they don't provide a C interface, it has to be created also when using the sources with C18
- Microchip assembler isn't fully compatible with CCS assembler

I assume, that it's generally possible to reuse the sources in a CCS project, but this involve a lot of work and requires a deeper knowledge of CCS C low level coding details. It's most likely more easy to extract the algorithm from the source and rewrite it in C. When debugging an assembly project, you have to understand the code's operation anyway, which is already half the way to rewrite it.

On the other hand, the basic PID agorithm is pretty straightforward, I can't see, if the AN937 code has any features, that pay the implementation effort.
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 9:02 am     Reply with quote

The biggest reason I'm looking at it is that it seems (though I can't read assembly code) that they do the entire process without the use of floats. Our existing PID controller routine is almost entirely floats. And I'm having a ROM issue Smile

Plus we have integrator windup issues that I've never been able to resolve so when I saw their document it was a "why reinvent the wheel" moment.


Anyway, I wonder... can I use an Assembler to generate .o files, then include them in my project and reference them like normal? Would ccs choke on that or ?

Hmm.

Or maybe I should just switch to C18. According to microchip, you can freely mix c and ASM files to your heart's content with it. So I don't mean this in any bad way... but why am I using CCS anyway? I mean that seriously. I was just handed the software and shown how to program our boards and make minor adjustments so I don't know where or why ccs came into it at all - it was just installed for me. Are there particular benefits to it? Will our code simply not work if I used C18 instead? I don't want to cause myself more headaches or spend $500 for no reason.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 10:32 am     Reply with quote

Ooo, C18, I wouldn't go there.

First, C18 vs. PIC-C won't fix your float problem. The PIC family of MPU's are all without FPU's. So C18 would have to generate messy code to handle floats just like PIC-C would have to for any other integer only MPU.

AND, in my comparison for C18:

More $$
More ROM (code isn't typically as efficient as the compiler has GCC roots)
Less built-in PIC friendly functions
More Overall Hassle to use.

It was not pretty.

Anyway - you can mix ASM into PIC-C as well. I've done it in the past when I need to super-tweak a routine or just prove out something else when working with CCS to integrate new chips that have new functions.

CCS also has a pretty reasonable maintenance program.

Regards,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 10:41 am     Reply with quote

Ok.... so then... how??

I've asked here and on Microchip's forum and on stackoverflow and nobody's really given me a way to do it. Seriously, I've spent probably 12 hours just trying to figure out how to include these asm files and access the functions in them.

I've now downloaded the evaluation version of C18 and at least right away it SHOWS me all the files (ASM and c, not just one or the other).

I'd rather stay with CCS rather than running into other problems. For example, I loaded up my project without the ASM files in C18 and hit "build all" and I have errors where it compiled without so much as a warning on CCS. So obviously switching is going to introduce headaches as well.

The question is: will I be able to faster integrate my c into C18 or find a way to integrate these ASM files into CCS?


A couple of times I've gotten the response that I should just write the PID code in c. Programmers typically have the attitude of "don't reinvent the wheel"... there's a library sitting in front of me already written and I want to take advantage of it.

It shouldn't be this hard.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:03 pm     Reply with quote

Ok, I'm looking at the link with the ASM files. I am curious though as to how you see 'C' files in C18 when the link you provided above points to a PDF and ZIP (containing only .ASM's)

Can you post the 'C' file up here so we can see it...


Otherwise you can do this a couple of ways..

1: break down the asm into functions that contain the desired code
2: write functions that essentially jump to the ASM routine you want.

I've done the former but not the latter. The latter would be easier for you.

the PIC-C help file lists the former method as:

Code:
int find_parity(int data){
    int count;

    #asm
    MOV #0x08, W0
    MOV W0, count
    CLR W0

    loop:
    XOR.B data,W0
    RRC data,W0
    DEC count,F
    BRA NZ, loop
    MOV #0x01,W0
    ADD count,F
    MOV count, W0
    MOV W0, _RETURN_
    #endasm
 }



To do the latter, I would imagine it would look like:
Code:


int8 function ( args ) {

 Code to set up args to right locations defined by ASM code

#asm
  call ASM_ROUTINE
#endasm

 Code to gather back things of interest
}

_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:09 pm     Reply with quote

And don't forget that floats are ugly with EITHER compiler because of the fact an integer MPU is being used.

(I just wanted to mention that again as I read the thread again)

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:12 pm     Reply with quote

No, that link only has ASM files. I mean with c18 I can open my project that contains my c files but also have the ASM files and include them just like I'd include another c file using ccs. In other words it seems to be perfectly happy mixing and matching the two languages in a project. The compile errors I'm currently getting are all related to my h files.

Anyway, I'd prefer to stick with ccs because I've been working with it for awhile.

I just found the #ASM listing in the help file and I'll play with doing it that way.

Seriously though, it shouldn't be like this. CCS should just be able to include an ASM file (ESPECIALLY if it has an #ASM directive!!) and I should be able to call the functions as though they were sitting in an included c file. It should just automatically recognize that its assembly and do its thing. Its not like we're talking French and Spanish here.
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:14 pm     Reply with quote

bkamen wrote:
And don't forget that floats are ugly with EITHER compiler because of the fact an integer MPU is being used.

(I just wanted to mention that again as I read the thread again)

-Ben


That's the whole reason I want to use their code!! We were using floats... and it works but its not as nice as it should be. Rather than reinventing the wheel, Microchip has ready made code for exactly what we want (possibly) using all integers (I think)... its just in assembly.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:22 pm     Reply with quote

s_mack wrote:
Seriously though, it shouldn't be like this. CCS should just be able to include an ASM file (ESPECIALLY if it has an #ASM directive!!) and I should be able to call the functions as though they were sitting in an included c file. It should just automatically recognize that its assembly and do its thing. Its not like we're talking French and Spanish here.


And you may be able to - I just haven't tried. Typically I think you might have to minorly CCS-ize it somehow. Have you asked support@ccsinfo.com?

Look at the #EXPORT and #IMPORT functions as well. They let you make .O files and could give you what you need with a less effort than #ASM'ing all the routines into functions.

I'd have to play with it.

Also read up on the CCS linker. I might also give some additional ideas for you.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:25 pm     Reply with quote

Thanks. I didn't know there was a CCS linker. I'll check that out.

No, I didn't ask them by email.

Thanks for your help. It vaguely seems like it might be coming together Smile
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:27 pm     Reply with quote

s_mack wrote:

That's the whole reason I want to use their code!! We were using floats... and it works but its not as nice as it should be. Rather than reinventing the wheel, Microchip has ready made code for exactly what we want (possibly) using all integers (I think)... its just in assembly.


Gotcha.. and Amen.

Some days I think Microchip likes to torture the common programmer with ASM. I can read the language -- but when importing into a C environment, it's usually a conversion bummer somehow.

If you can read the ASM and can do a conversion to C, you'd be surprised how efficient CCS code tends to be.

A lot of times I when I'm counting instructions (because of time constraints), I see the compiled C isn't really any better than the ASM.

And I've looked.

I would ask CCS, "how can I include an external .ASM file from Microchip with CCS and make calls to routines inside the assembled ASM file?"

So anyway --- keep us posted.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:29 pm     Reply with quote

s_mack wrote:
Thanks. I didn't know there was a CCS linker. I'll check that out.

No, I didn't ask them by email.

Thanks for your help. It vaguely seems like it might be coming together Smile


An old mentor of mine used to say, "DO YOUR HOMEWORK" and "GET YOUR SHiZNiT STRAIGHT"....

Which was his way of saying to do the research to figure out:

1. What you have now
2. What do you want to do with it
3. How to accomplish that with 1 and 2.

:D

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
s_mack



Joined: 04 Jun 2009
Posts: 107

View user's profile Send private message

PostPosted: Fri Sep 04, 2009 12:34 pm     Reply with quote

bkamen wrote:
s_mack wrote:

That's the whole reason I want to use their code!! We were using floats... and it works but its not as nice as it should be. Rather than reinventing the wheel, Microchip has ready made code for exactly what we want (possibly) using all integers (I think)... its just in assembly.


Gotcha.. and Amen.

Some days I think Microchip likes to torture the common programmer with ASM. I can read the language -- but when importing into a C environment, it's usually a conversion bummer somehow.

If you can read the ASM and can do a conversion to C, you'd be surprised how efficient CCS code tends to be.

A lot of times I when I'm counting instructions (because of time constraints), I see the compiled C isn't really any better than the ASM.

And I've looked.

I would ask CCS, "how can I include an external .ASM file from Microchip with CCS and make calls to routines inside the assembled ASM file?"

So anyway --- keep us posted.

-Ben


Email sent.

I can't follow ASM. Its just completely foreign to me. #import looks like it may have been the ticket I was missing. Thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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