![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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; 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. | |
| |
| | (permalink) |
| USB is confusing, and complicated - first thing you should understand is that it's NOT interrupt driven in a PC, so it's either polled or requested. | |
| |
| | (permalink) |
| So should my pc side code continuously request updates? | |
| |
| | (permalink) |
| And the pic store data until requested? | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| Ok thanks nigel. | |
| |
| | (permalink) |
| 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 ![]() | |
| |
| | (permalink) |
| may be a stupid question: How did you determine that 4550 uses too many resources/overhead? thanks | |
| |
| | (permalink) |
| 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 by Mike, K8LH; 24th December 2007 at 04:03 PM. | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| Writing small footprint USB code is possible, the Microchip USB bootloader takes just 2K of program space. Mike. | |
| |
| | (permalink) | |
| Quote:
I know that the framework looks scary 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; 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 If you can't get it working, ill try and help you Last edited by HerbertMunch; 26th December 2007 at 03:06 AM. | ||
| |
| | (permalink) |
| 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 by HerbertMunch; 26th December 2007 at 03:02 AM. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| MP Lab Program Help | bamafan54 | Micro Controllers | 3 | 19th October 2007 03:53 AM |
| Need some help with a code provided by ATMEL | ikalogic | Micro Controllers | 1 | 23rd January 2007 03:46 PM |
| 12 bit, 8 channel data logger | florinm1982 | Electronic Projects Design/Ideas/Reviews | 11 | 17th April 2006 01:36 PM |
| Hardcode a PIC by hand? (or 16F74 + par.port.prog = problem) | smilen | Micro Controllers | 15 | 21st November 2005 10:23 AM |
| An error in pic16f84a, why? | Zener_Diode | Micro Controllers | 6 | 11th April 2004 03:55 AM |