• 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.

Microchip USB framework (custom driver) data logger

Status
Not open for further replies.

HerbertMunch

New Member
Can anyone tell me how id go about using a 18F4550 to make a crude data logger?

I want to use the microchip custom driver and framework (not CDC library) to send updates about the state of a port.

Im looking at the code in the User.C file of the framework:

Code:
void ServiceRequests(void)
{
    byte index;
	
    
    if(USBGenRead((byte*)&dataPacket,sizeof(dataPacket)))
    {
        counter = 0;
        switch(dataPacket.CMD)
        {
            case READ_VERSION:
                //dataPacket._byte[1] is len
                dataPacket._byte[2] = MINOR_VERSION;
                dataPacket._byte[3] = MAJOR_VERSION;
                counter=0x04;
                break;
The way that this code work is that the usb host makes a request, and then the a packet is sent back.

How do i go about sending a stream of data with the framework? its not really ideal to keep having to request the data each time.

Also i cant just sit in the above method waiting and logging, as the usb needs servicing regularly.

ive tried looking for information, but I find all this USB lark quite confusing.


Anyway thanks for any help that is offered.:D
 

Nigel Goodwin

Super Moderator
Most Helpful Member
I don't really know, because I've never done it - but in many respects it's only a vastly more complicated version of serial comms. Where you would normally store the readings in the logger itself, then squirt it over as a complete batch of readings. Really it depends on exactly what you're trying to do?, USB requires data in large chunks, if you only send a byte at a time (like serial) it reduces the speed to about 9600 baud, due to the overheads of USB.
 

Mike - K8LH

Well-Known Member
I haven't been able to justify using a '2550 or '4550 "usb" device yet because it seems to require so much of the devices resources and processing "overhead" for the "usb" connection. Instead, I've pretty much decided to use the $20 (USD) TTL-232R interface below which eliminates the resource/overhead problems and allows me to implement an RS232 connection via USB for even the most modest low-pin-count PIC projects.

Happy Holidays. Mike

 

Mike - K8LH

Well-Known Member
Hi Chris (?),

I'm not certain. It's my impression. Frankly, I have not been able to determine the amount of resources and overhead used because the sub-system is spread out across so many different source and header files.

If you've progressed farther than me and would consider sharing what you've discovered I would be grateful.

Mike
 
Last edited:

HerbertMunch

New Member
Im not really the best person to answer that question, but here's what i think:

MPLABs memory usage guage, shows that IMO, an acceptable amount of memory is utilised (see pic) by the framework.

The main loop that services USB takes around 70 instruction cycles to complete once.

Upon first glance, The framework appears to be vast, but its not that big really. I supoose it depends what you need to use USB for. Maybe you could employ more ram if space is a problem.

This is about all I have come up with at the moment, but i am satisfied so far.
Ill let you know if that changes.

Another bonus for me, is the microchip custom driver. This will enable me to make professional usb hardware installation on the pc. It maybe just me, but the idea of simulating a Com port through USB is at best, cheap and nasty.

I like to program in c# on the pc and there are a few good examples out on the web of how to use the microchip custom driver in c#.

Here are a few links (that you probably allready have seen!)

http://eegeek.net/content/view/13/32/

also
http://www.piccoder.co.uk/content/view/42/26/

buts its not working at the moment.

Anyway hope this helps.:)
Chris
 

Attachments

HerbertMunch

New Member
The link to the pic coder website is down, However Ive just found a copy of the pages that i saved a while ago.

Just in case you need it, its quite an informative site.

cheers,
Chris
 

Attachments

Mike - K8LH

Well-Known Member
Chris,

Thank you for the encouragement. I downloaded the eegeek software but I'm afraid it's way over my head. I can't even get the MCHPUSB.mcp project file to open up in my MPLAB to look at the files.

Mike
 

Pommie

Well-Known Member
Most Helpful Member
Writing small footprint USB code is possible, the Microchip USB bootloader takes just 2K of program space.

Mike.
 

HerbertMunch

New Member
Mike said:
Chris,

Thank you for the encouragement. I downloaded the eegeek software but I'm afraid it's way over my head. I can't even get the MCHPUSB.mcp project file to open up in my MPLAB to look at the files.

Mike
Instead of eekgeek, Try the pic coder files instead. I know they work, because ive tested them.

I know that the framework looks scary:eek:, believe me, i put off learning about usb with 18f because of that. If you look at it carefully, and trace through it using mplab sim, you will see that there is not much that needs
modifying.

The framework is structured in such a way, that most of the code that you need to modify, is contained within the files called user. (user.c & user.h)

I would advise you to start off by looking at the following files/methods:

User.h > DATA_PACKET

Code:
typedef union DATA_PACKET
{
    byte _byte[USBGEN_EP_SIZE];  //For byte access
    word _word[USBGEN_EP_SIZE/2];//For word access(USBGEN_EP_SIZE msut be even)
    struct
    {
        enum
        {
            READ_VERSION    = 0x00,
            ID_BOARD        = 0x31,

The enum is for command hex codes. If you wanted to add a new command to the framework, you would simply define another enum member with a unique hex.
i.e you could have "FLASHLED = 0x1A,". You would then need to get the pc to send 0x1A to flash the led.

User.C > ServiceRequests()

This is where you do something with the enum value that you defined before.
It basically just contains a case statement (like an If, else statement combined)

For my example above, you would add a case statement (following the convention set out in the code). i.e case FLASHLED: <HANDLERCODE>; break;
The compiler will replace FLASHLED with 0x1A:.

Code:
void ServiceRequests(void)
{
   
	
    
    if(USBGenRead((byte*)&dataPacket,sizeof(dataPacket)))
    {
        counter = 0;
        switch(dataPacket.CMD)
        {
            case READ_VERSION:
                //dataPacket._byte[1] is len
                dataPacket._byte[2] = MINOR_VERSION;
                dataPacket._byte[3] = MAJOR_VERSION;
                counter=0x04;
                break;
To get the project to compile, you need to have microchip C18 compiler installed, and mplab configured to use it.

You will need to alter the project specific file paths, otherwise the compiler will look in the wrong directories when compiling.

If memory serves me correctly, i think that the paths are set up to use the G:\ drive. My G drive is a dvd drive, so obviously these paths need to be updated.

I have included a few screenshots to help you, in case you dont understand what im going on about.



You should make a board, as described by the site, ensuring that you use a capactitor as described on vUSB pin. You also need to make sure that you implement the pin that 'senses' the usb bus (connected to the usb bus v+), if you dont do this (as i didnt) you need to modify the code to not expect the pin which tests whether usb is connected. If you follow the circuit diagram exactly, you will find it easier to get the code working.

right mate, that should get you started (hopefully:D ).
If you can't get it working, ill try and help you:)
 

Attachments

Last edited:

HerbertMunch

New Member
IMO Microchip over did it just a tad, on creating files and folders for their framework.
I think that they should have split the code up less, and reduced the file count. That way, using it wouldn’t look like such a tedious task.
Trying to remember which file contains which method/#define/etc, is virtually impossible and obviously results in a lot of open windows in MPLAB.
Also MPlab, unlike vs.net offers no way of grouping source files in the project window. Even though microchip went to the trouble of making lots of folders to divide the framework source code, MPLAB makes no use of them, and lumps all the files into one folder.


When Ive fully got to grips with it, im definately going to look into crafting the framework into a more developer friendly form.

Chris
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top