Event driven datalogger

Discussion in 'Programmer's Corner' started by mns, Jan 18, 2008.

  1. mns

    Thread Starter New Member

    Jan 18, 2008
    3
    0
    Hi,

    I'm in the process of designing an event driven datalogger that will have approximately 10 digital inputs. The interfaces to be used are LCD, EEPROM, RTCC, RS232, all of which i have tested and all work okay. The PIC i'm using is the 18F452. The c compiler is the ccs one.

    I'm now starting to think about the software for the main program and this is where i'm weak (software!) but learning slowly. As the datalogger will be event driven, i was thinking of scanning each input in turn and if a state change occurs, then log the state, time and date to EEPROM. Sounds simple but i can't think of a way of only capturing the time on a state change (due to lack of programming experience).

    Has anyone got ideas that could point me in the right direction to get started?

    Regards

    mns
     
  2. PhotoMonger

    Member

    Jan 7, 2008
    16
    0
    What event will trigger the recording of the data? Is this a push button, received information on the serial port, etc... If its a push buttion I would see if you can enable an interrupt for a state change on one of you I/O pins. This would be more effective then polling.
    More details would be nice too. Do you already have a timer going to keep track of your local time?

    ~Ian
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    The method that you describe is referred to as "polling". Polling is inherently inefficient since it is possible to miss a critical event if your polling interval is too long.

    As has been pointed out, the ideal approach would be to have 10 external interrupt lines that could be used to monitor transitions on the 10 lines and then handle each event with its own interrupt.

    The PIC you have chosen appears to have only three inputs that can be assigned to interrupts. That means that if you need to use interrupts to service the 10 data lines you will need some additional logic to take care of matrixing the 10 lines into one of the interrupts available.

    If you have not commited to PIC you may want to consider an AVR 8-bit microcontroller. The ATTINY2313 would be a very good candidate for this datalogger application since it has 10 external interrupt lines that can be assigned to your 10 data lines.

    If you are commited to PIC then you may want to look for a member of the PIC family that has at least 10 external interrupts.

    hgmjr
     
  4. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    As said above, event driven uses interrupts and not polling. Part of the interrupt servicing routine needs to be adding the system clock to the data file.
     
  5. mns

    Thread Starter New Member

    Jan 18, 2008
    3
    0
    Many thanks for your replies.

    The data lines are coming from a PLC, the plc outputs and seperate push buttons / key switches are going to be monitored.

    I'm aware that polling isn't as efficient but i'm not looking for super accuracy of when the event occured. If this was inside 2/3 minutes, it will be ample.
    The system i'm trying to monitor is at my place of work and it's PLC controlled. Due to human intervention and / or poor design of some areas of the plant, we often get failures, so i'm just trying to gather some data as to what was pressed when and what outputs changed (state of plant).
    I'm fairly new to pics and programming and i took on this project to learn more.

    Would it be a good idea to draw a state diagram and try to program a finite state macine? I'm also kind of limited to pic microcontrollers.

    Regards

    mns
     
  6. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I would highly recommend that you compare the features and available software and hardware tools between the PIC and the AVR before you make a final decision to go with the PIC.

    The AVR software development tools are FREE for both the assembly language and C. Due to ATMEL's microcontroller philosophy, all of the ATMEGA and ATTINY microcontrollers have indentical core architectures so that means you can develop on one and without changing software tools you can migrate it to another 8-bit AVR micros. The hardware development tools for the AVR are reasonably priced.

    If interested let me know I have much more information that I think will sway you over to the AVR camp.

    hgmjr
     
  7. PhotoMonger

    Member

    Jan 7, 2008
    16
    0
    Wow I didn't know that, and I've been using a ATMEL core for a few years now. Then again I was using TinyOS so I wasn't really getting down to the hardware level.

    For risk of sounding a little stupid what is a PLC?

    mns,
    While polling is an option I think you will find using interrupts much easies as your program won't run the risk of getting stuck in an infinite loop. Also where do you plan to store this information, on the micro controller or a local computer?
     
  8. mns

    Thread Starter New Member

    Jan 18, 2008
    3
    0
    Hi,

    A PLC is a programmable logic controller and is used to control industrial processes as you can have tons of i/o's and nowadays have 3 term control ability and all sorts of extras (they're like a small version of a distributed control system-dcs) . Search for allen bradley if you want more info.

    I'm using an i2c external eeprom to store my data. i'm quite stuck with the pic at the minute as i've got all my interfaces such as the eeprom, rtc, lcd etc all working. I'm now just trying to write my main program.

    I'll let you know how far i get with it.

    Regards

    mns
     
Loading...