Data logger clock and array


Closed Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Sep 2008
    Posts
    10

    Default Data logger clock and array

    I just want to say hello since I’m new to PBP. I’m thinking to make Data Logger to log 4 batteries, 2 temperatures, frequency, and time 2% or less accuracy using 16k 18F4420 8mhz internal clock. I’ll be saving all the data in Flash. 100,000 life cycles is more than enough for my lifetime to use data logger. Before I start writing the program I’d like to consult with you guys what a proper way to do it. If you please can suggest anything, I'm all ears.

    1) I have to write 32bytes in to Flash at a time. Let’s assume 8 adc at resolution 8bit samplings equal 8 bytes. Should I just make 32 variables each equal byte and take 4 samplings of 8adc channels and write all 32 variables at once to flash? Is it a proper way to do it? Let’s say I’ll be logging only 7adc channels and is it possible to use an Array of 32 bytes and once it is full or almost full it starts writing to flash automatically. Is there a sample code like that so I can get an idea to modify for my application?

    2) I’d like to be able to log time as well. Data logger will be logging under 20 minutes at a time. Time should be 2% or less accurate. What would be the best way to make 20 minutes clock using hardware interrupt or software without external RTC IC? If I use 100hz interrupt, I’m afraid it’d conflict with data logging. If I just use software code then I would have to adjust the timing to compensate for ADC sampling, CCP sampling, flash writing, flash erasing and other calculation which is probably a big pain in the butt and I’m not proficient as well do that kind of calculations yet.

    3) I’m going to import all the data to Excel and use charts. I found Parallax PLX-DAQ software but is there any better solution to do that? I’m going to use software rs232 command so I don’t have to use Max232 and make it simple. What’s the fastest baud rate I can use with 8mhz internal clock with a minimum error tolerance?


    Thank you
    Last edited by PicLearner; - 24th September 2008 at 11:19.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PicLearner View Post
    I just want to say hello since I’m new to PBP.
    I can tell you right off the get-go, if you haven't built anything before, you'd better start small and work your way up. You'd be shooting yourself in the foot if you don't. Opinion...

    I’m thinking to make Data Logger to log 4 batteries, 2 temperatures, frequency, and time 2% or less accuracy
    At what sampling rate? 100 times per second? Once per second?

    using 16k 18F4420 8mhz internal clock.
    Use a PIC18F4550 and you can use the serial port initially then switch over to USB. Cool points included.

    I’ll be saving all the data in Flash. 100,000 life cycles is more than enough for my lifetime to use data logger.
    Easy enough to add a fair sized external 2 wire EEPROM. Why take the chance of messing up the PIC's operating system.

    Before I start writing the program I’d like to consult with you guys what a proper way to do it. If you please can suggest anything, I'm all ears.
    Good plan...

    1) I have to write 32bytes in to Flash at a time. Let’s assume 8 adc at resolution 8bit samplings equal 8 bytes. Should I just make 32 variables each equal byte and take 4 samplings of 8adc channels and write all 32 variables at once to flash? Is it a proper way to do it? Let’s say I’ll be logging only 7adc channels and is it possible to use an Array of 32 bytes and once it is full or almost full it starts writing to flash automatically.
    Whatever way you want to do it, as long as you take good notes and keep track of what you're doing.

    Is there a sample code like that so I can get an idea to modify for my application?
    Starting to go downhill here... And by that I mean... Well, never mind.
    Suffice to say, if you write some code, and it doesn't look right, and/or doesn't work right, I'm sure a dozen people around here will stand up and give you a hand.
    However, I don't have your hardware, I don't know how much you know, and I'm not going to use up a days upon days trying to explain every little thing.

    2) I’d like to be able to log time as well. Data logger will be logging under 20 minutes at a time. Time should be 2% or less accurate. What would be the best way to make 20 minutes clock using hardware interrupt or software without external RTC IC?
    Easy enough to use a crystal on the PIC and keep <1% accuracy, or again, easy enough to add on a 2 wire RTC for tigher accuracy.

    If I use 100hz interrupt, I’m afraid it’d conflict with data logging.
    External eeproms are quick enough. You can get away with a write, wait 10ms (100hz) then write another byte. Or if your program is written right, you can use a page mode and write more data in practically the same time.

    3) I’m going to import all the data to Excel and use charts. I found Parallax PLX-DAQ software but is there any better solution to do that? I’m going to use software rs232 command so I don’t have to use Max232 and make it simple. What’s the fastest baud rate I can use with 8mhz internal clock with a minimum error tolerance?
    Use USB and you don't have to worry about it.
    Generally speaking, using software SERIAL, 19.2K baud is what the book says. Using hardware serial, you'll have to check your datasheet for whichever PIC you want to use and see what the numbers show.
    Last edited by skimask; - 24th September 2008 at 14:16.

  3. #3
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thanks Skimask for a quick reply. I have some experience with Proton picbasic. The data logger will be taking every 1s-10s samplings adjustable from Excel. What do you think the best way to make 20 minutes Clock? I've never used USB before but it might be a good idea to learn it. How to communicate between USB and excel? Would it not require custom PC software? Using serial port I can even use HyperTerminal to import the data.
    I'd like to keep data logger very simple without external parts. This is just a hobby project and I know once my friends would see the data logger I would have to make them as well. I'd prefer to keep the project with minimum parts so I wouldn't even need a PCB and it'll be easy to build it for my friends.

  4. #4
    Join Date
    Nov 2005
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PicLearner View Post
    I'd like to keep data logger very simple without external parts. This is just a hobby project and I know once my friends would see the data logger I would have to make them as well. I'd prefer to keep the project with minimum parts so I wouldn't even need a PCB and it'll be easy to build it for my friends.

    You having a laugh, Keep it simple with out no extrenal parts & no PCB (This would be good to see)
    What voltage measurement you require ? has if it is more then 5V you then would need resistors Opps! i forgot no extrenal parts, Don't forget you need an eeprom of sd card but how would you connect them wiht out PCB.

    Give it to your friends I think I would sell it for a small fee plus this helps you get your money back for PBP after all your the one that has put all the time into it.
    Like skimask said do your home work write some code give it ago then come back and may be more people would take you seriously and offer more help

    Do a serach and you will find some code

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Cool

    Quote Originally Posted by PicLearner View Post
    I have some experience with Proton picbasic.
    You know this forum isn't for Proton picbasic right?

    The data logger will be taking every 1s-10s samplings adjustable from Excel.
    So Excel is going to talk to the PIC?

    What do you think the best way to make 20 minutes Clock?
    Make a whole bunch of 1 second clocks and keep track of them.

    I've never used USB before but it might be a good idea to learn it.
    There's one really really really good thread here on how to do just that using an 18F4550.

    How to communicate between USB and excel? Would it not require custom PC software? Using serial port I can even use HyperTerminal to import the data.
    Pull it in using that link I eluded to above, and dump the data to a .csv file, then import it to Excel. Or write a really cool VBA app to pull the data from the file as it comes in. Doesn't matter.

    I'd like to keep data logger very simple without external parts. This is just a hobby project and I know once my friends would see the data logger I would have to make them as well. I'd prefer to keep the project with minimum parts so I wouldn't even need a PCB and it'll be easy to build it for my friends.
    Now that's classic... And just how do you suggest doing that? Chips without a PCB... Are you going to mount this stuff on wheat bread or Pringles chips or what?
    What exactly do you plan on datalogging again?
    Last edited by skimask; - 24th September 2008 at 23:16.

  6. #6
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    In order for me to keep it very simple it would take ADC from lipo cells which are 3.7v. I might use a resistor 4.7k on the connector it self or without a resistor since it shouldn't have any spikes in voltage. To take frequency I was thinking just to use 2 resistors 1k and 100ohm to drop the voltage. To power up the pic I was thinking to use TO-92 0.5% LDO and 1 or 2 small capacitors. I'm not going to use voltage reference to keep it simple and ADC probably should work within 1%-3% accurate. As you can see 1 PDIP microchip, 1 LDO, 1-2 capacitors and just connector glued and soldered directly to microchip. Using software rs232 I don’t need Max232 so I can just use serial female connector with 2 resistors and connect it directly to microchip whenever I need to upload the data. Sure I can make PCB at home but I just want to keep it very simple so my friends can use it as well just to pay for parts or so. I bought PicBasic just for fun since I like electronics and I don't intend to make profit but maybe I might sell it for a small fee. I have regular job which pays my bills and I don't mind to spend money for my hobby that I like.

  7. #7
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    double post deleted
    Last edited by PicLearner; - 25th September 2008 at 00:13.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PicLearner View Post
    To power up the pic I was thinking to use TO-92 0.5% LDO and 1 or 2 small capacitors.
    You should be able to drive a PIC directly from one LiPo, no regulators need.

    I'm not going to use voltage reference to keep it simple and ADC probably should work within 1%-3% accurate.
    There's a few PICs out there that have a built-in .6v reference which you could 'reference against'.

    As you can see 1 PDIP microchip, 1 LDO, 1-2 capacitors and just connector glued and soldered directly to microchip.
    If you think it'll run, go with it... I don't think it'll run and last, but that's just me.

    Using software rs232 I don’t need Max232 so I can just use serial female connector with 2 resistors and connect it directly to microchip whenever I need to upload the data.
    Same thing with the USB, the connector, 2 wires to the PIC (D+/D-), an extra cap, and the right firmware.

  9. #9
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Yeah I know. So far I love the forum, it's got so much info to learn from...

    Quote Originally Posted by skimask View Post
    You know this forum is Proton picbasic right?
    I was thinking to use Excel to change settings in microchip using PLX-DAQ or Realterm OCX example. I can adjust number of batteries, number temp sensors connected to pic just by using serout command to update EEPROM of Flash to store different settings.

    Quote Originally Posted by skimask View Post
    So Excel is going to talk to the PIC?
    Let's say I use interrupt for 1 second using 16bit timer. 8mhz / 4 cycles / 16bit timer 65536 = 0.000030517578125 multiply by 256 prescaler = 0.0078125. 1 second / 0.0078125 = 128. As I understand it should interrupt the software 128 per second. My guess it might conflict with a software running in the background or I'm wrong.

    I would love to hear more about that.
    Quote Originally Posted by skimask View Post
    PLX-DAQMake a whole bunch of 1 second clocks and keep track of them.PLX-DAQ
    Very simple, please read my previous post.

    Quote Originally Posted by skimask View Post
    Now that's classic... And just how do you suggest doing that? Chips without a PCB... Are you going to mount this stuff on wheat bread or Pringles chips or what?
    What exactly do you plan on datalogging again?

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PicLearner View Post
    Yeah I know. So far I love the forum, it's got so much info to learn from...
    Let me try that one again...

    You know this forum is for MeLabs PicBasicPro and not Proton Basic right?

  11. #11
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Let me try that one again...

    You know this forum is for MeLabs PicBasicPro and not Proton Basic right?

    Yeah I know. That's what I said I bought MeLabs PicBasicPro but I've used Proton lite to learn on

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PicLearner View Post
    Yeah I know.
    Ok, just checking...

    That's what I said I bought MeLabs PicBasicPro
    Having trouble finding that particular sentence...

  13. #13
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Sorry I didn't say what data logger is for. This is just for Remote Control airplanes/helicopter so I know what battery voltage is and motor RPM, temperature of the battery and speed controller. The main reason to use minumum external parts so it is very light because every gram counts on small electric RC helicopters. Everything looks very easy to make since I already did everything bit by bit by writing to flash and reading from flash. Getting ADC to work properly in 8bit and 10bits and CCP to ger RPM from the motor. Debugging the pic using RS232 and HyperTerminal but I just can't figure it out how to make clock. Can anybody please tell me if my calculation is right?
    Let's say I use interrupt for 1 second using 16bit timer. 8mhz / 4 cycles / 16bit timer 65536 = 0.000030517578125 multiply by 256 prescaler = 0.0078125. 1 second / 0.0078125 = 128. As I understand it should interrupt the software 128 times per second. How do I figure it out if it will not conflict during ADC, CCP, EEPROM, CCP sampling, writing and erasing? I know I can disable interrupt routine during any of these sampling but it'll mess up the time. Is it even possible to do that without external RTC?
    Last edited by PicLearner; - 25th September 2008 at 00:40.

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PicLearner View Post
    Let's say I use interrupt for 1 second using 16bit timer. 8mhz / 4 cycles / 16bit timer 65536 = 0.000030517578125 multiply by 256 prescaler = 0.0078125. 1 second / 0.0078125 = 128. As I understand it should interrupt the software 128 times per second. How do I figure it out if it will not conflict during ADC, CCP, EEPROM, CCP sampling, writing and erasing? I know I can disable interrupt routine during any of these sampling but it'll mess up the time. Is it even possible to do that without external RTC?
    8Mhz / 4 = 2Mhz...
    Clocking a 16 bit timer off the instruction clock @ 2Mhz = 2Mhz / 65536 = 30.517578125 interrupts per second (have to take the 1/x of the result, that's the part you forgot).
    Set up the interrupt routine to count to 30, then take a sample. Yes, you'll be 16.69ms off for each second, unless you reload that particular timer at each interrupt with a correction factor to make it exactly one second. Look up the phrase PIC Multi-Calc.
    If you clock an 8 bit timer off the instruction clock @ 2Mhz, 2Mhz / 256 = 7812.5 interrupts per second. Set up that interrupt routine to count to 7812, then take a sample. With the 8 bit timer, you'll only be 65us off in each second.

  15. #15


    Did you find this post helpful? Yes | No

    Talking

    Ok, I have been watching this thread and I have to jump in. I understand that every gram counts in an RC chopper, I have built some from scratch. The dead bug approach to soldering the PIC without a circuit board is not a good idea. I suggest you take as thin a pcb as possible, use a 16F88 or something with 18 to 20 pins in a SSOIC package, ICP setup will be your best option. You can then buy from RFM or similar an ASK 4mm square surface mount 900Mhz TX. You can then assemble all of these components and it should not weight more 5gm. I know because I have done it. The RX side is an ASK receiver connected to a serial port on your pc. TX every 1sec and log it on laptop PC, write your own app or buy an app, there are lots out there. My advise is intended to save you hours of wondering why things don't work.

    Nick

  16. #16
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    8Mhz / 4 = 2Mhz...
    Clocking a 16 bit timer off the instruction clock @ 2Mhz = 2Mhz / 65536 = 30.517578125 interrupts per second (have to take the 1/x of the result, that's the part you forgot).
    Set up the interrupt routine to count to 30, then take a sample. Yes, you'll be 16.69ms off for each second, unless you reload that particular timer at each interrupt with a correction factor to make it exactly one second. Look up the phrase PIC Multi-Calc.
    If you clock an 8 bit timer off the instruction clock @ 2Mhz, 2Mhz / 256 = 7812.5 interrupts per second. Set up that interrupt routine to count to 7812, then take a sample. With the 8 bit timer, you'll only be 65us off in each second.
    Oh my god, it looks so much simpler after you explained it to me. I've been reading about the timer and I still was wrong but after your explanation it is so clear to me now. Thank you!!!!!!! Just to make sure about prescaler. For example using 16bit timer with a prescaler 1:1 it would interrupt approximately 30 times per second and using prescaler 1:2 it should interrupt approximately 60 times. Is it correct?

    I was just reading thread about instruction execution time by Darrel Taylor and after testing I can easily calculate what it takes to do ADC, CCP, etc. Probably I can even make a simple software clock and add to the clock execution time to compensate missing nanoseconds/milliseconds. I think interrupt clock is much easier and faster to write but what would you recommend interrupt or software clock?

  17. #17
    Join Date
    Sep 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Macgman2000 View Post
    Ok, I have been watching this thread and I have to jump in. I understand that every gram counts in an RC chopper, I have built some from scratch. The dead bug approach to soldering the PIC without a circuit board is not a good idea. I suggest you take as thin a pcb as possible, use a 16F88 or something with 18 to 20 pins in a SSOIC package, ICP setup will be your best option. You can then buy from RFM or similar an ASK 4mm square surface mount 900Mhz TX. You can then assemble all of these components and it should not weight more 5gm. I know because I have done it. The RX side is an ASK receiver connected to a serial port on your pc. TX every 1sec and log it on laptop PC, write your own app or buy an app, there are lots out there. My advise is intended to save you hours of wondering why things don't work.

    Nick
    Thank you for your advice. The project is not intended to be for sale but it is just for fun and learning experience. I've been learning Microchips for the past couple of month and it is very hard for me but every day I learn something new from reading the forum. The whole point of the project just to make it work. Will I even use it in the future? I don't know but it is a lot of fun just to build it and make it work the way I want to. Like I said it's fun to learn something new.
    Last edited by PicLearner; - 25th September 2008 at 04:17.

  18. #18
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PicLearner View Post
    For example using 16bit timer with a prescaler 1:1 it would interrupt approximately 30 times per second and using prescaler 1:2 it should interrupt approximately 60 times. Is it correct?
    Nope...

    Scaler = Divider, prescaler = predivider, postscaler = postdivider

    I was just reading thread about instruction execution time by Darrel Taylor and after testing I can easily calculate what it takes to do ADC, CCP, etc. Probably I can even make a simple software clock and add to the clock execution time to compensate missing nanoseconds/milliseconds. I think interrupt clock is much easier and faster to write but what would you recommend interrupt or software clock?
    Must've missed my suggestion to search for PIC Multi-Calc...
    If you're using interrupts, you don't have to count the ADC, the CCP, any of that. The interrupt will INTERRUPT every xxx microseconds (or instruction cycles, whatever) and run the interrupt subroutine. Look in the PBP manual under ON INTERRUPT, or if you're feeling froggy, search here for Instant Interrupts.
    And think about this...do you really need an exact 1 second interrupt? I'd just concentrate on getting it all working first, then add in some interrupt routines.

Similar Threads

  1. Bit Angle Modulation (BAM) in a PIC
    By Bronx68 in forum mel PIC BASIC Pro
    Replies: 150
    Last Post: - 24th February 2015, 13:41
  2. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  3. PIC HSERIN problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 20th July 2008, 11:08
  4. Using SPI with External Interrupts
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th June 2008, 04:08
  5. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts