Novice question on how to set sampling rate of a PIC data logger

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
Hi, I would like to be able to build a data logger and was wondering if someone could point me in the right direction on a topic so I could read up on it.

My question is ,with a PIC and assembly language , how is the sampling rate set and are there different ways to do it? I guess a read operation could be done every machine cycle and the machine cycle could be set at about the sampling rate desired but there must be other and better options.
Thanks in advance!
 

AlbertHall

Joined Jun 4, 2014
9,263
It depends what you are logging. If you were monitoring room temperature for instance it is only going to change slowly so there would be no point in sampling it very quickly.
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
Is there a operand in the instruction set to read a input every so often? Is code written to do it or does it all depend on clock cycles?
 

ronsimpson

Joined Oct 7, 2019
438
how is the sampling rate set and are there different ways to do it?
This depends on how fast you want to sample.
If the sampling rate is days, or hours, or seconds you might want a real time clock. Watch the clock then go do the sampling and save in memory then back to watching the clock.
For sampling 1000 times a second you could set up a timer to interrupt every 1mS.
You must determine what is the very fastest you can sample, store, house keeping and back. Then set the interrupt slower than that.
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
Thanks for the help. Would reading articles on timing LEDs flashing be a good source to learn from? Do articles on PIC timers include the info I need? Is the time on the timer being sent to the accumulator register and then to the ALU?

I studied pics in the past but it's been a while. I would like to read up on this subject at the same time with general early computer architecture.
 
Is there a operand in the instruction set to read a input every so often? Is code written to do it or does it all depend on clock cycles?
There are a couple different ways depending on which one you are using and how fast you want to do it. As mentioned earlier you could use a timer. You could also use the compare function of the CCP module and the special event trigger to give you a little finer control over the time, but depending on which PIC you are using it may also toggle a pin so keep that in mind. You could also set up a PWM to use as a clock input for a timer if you need some really slow timers. Or if the timing does not need to be very precise you can just log on every so many loops through your main loop in the program.
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
Thanks for the help. I'll try to read some related guides. Years ago I bought a bunch of PIC stuff but never used it. The pics I have look like Edit: PIC18F452-I/P but the label is hard to read.
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
I found this link.http://embedded-lab.com/blog/lab-7-timers-and-counters-part-1/ I want to read a few general guides before the actual manual for the specific pic first to get a general understanding first.
 

jpanhalt

Joined Jan 18, 2008
8,711
My current project is similar and in Assembly.

Some suggestions:
1) Use an enhanced mid-range or newer PIC. I am using the 16F1xxx series. Beside enhanced but still simple instructions they allow "linear memory." That is, you can use the entire general purpose RAM as one big file. If you are into 16-bit devices they would work too, but I have no experience with them.

I see you have chosen the 18F452. That has some advantages over the 16F1xxx. Does it have linear memory?

2) Compare/capture will help you capture events. In my case, I am taking temperature readings every 2 seconds and saving to RAM once a minute. My logger uses Timer 1 for that and an interrupt.

Questions:
1) How much data do you intend to save? (bytes)
2) What type of display? Character or graphic?
3) And as already asked, what events will you be capturing?
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
If the sampling rate is days, or hours, or seconds you might want a real time clock. Watch the clock then go do the sampling and save in memory then back to watching the clock.
I can't find any info on this. What should I search for? Is this referring to a external clock?
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
I see you have chosen the 18F452. That has some advantages over the 16F1xxx. Does it have linear memory?
Questions:
1) How much data do you intend to save? (bytes)
2) What type of display? Character or graphic?
3) And as already asked, what events will you be capturing?
Thank you for the reply.
I'm going to stay away from the microChip site for as long as possible because in my opinion the guides not completely comprehensive. Lol. I'm not sure on the memory. I don't have the courage to look.lol

I have a lot of need for data loggers in other projects so I would like to use a external memory chip just to have the logger have that capacity at all times and flexibility. Mostly I want to data log at a rate of maybe every 15 seconds to maybe 300 per second for a auto sensor logger. I have uses that are much faster as well. I'm I minimalist so a text output would be perfect if I ever get that far. As long as I can get the data onto a desktop that would be okay. I have a lot of time invested in electronics and computers but have not ever done much with it.
 

jpanhalt

Joined Jan 18, 2008
8,711
Thank you for the reply.
I'm going to stay away from the microChip site for as long as possible because in my opinion the guides not completely comprehensive. Lol. I'm not sure on the memory. I don't have the courage to look.lol
1579844347917.png
Staying away from "Microchip" will be tough to do if you plan to use a "PIC." Does that stand for something else?
 

AlbertHall

Joined Jun 4, 2014
9,263
Do you want to use assembly language or 'C' - do you already know 'C'?
On a PIC 'C' is a little different as you need to know how to set up the clock, timers and so on.
 
I took a quick peek at the datasheet. The 18f452 in a way would be a good place to start. It's one of the simpler chips they offer and it does not take as much to get the peripherals going as some of the newer offerings. It is however on the expensive side and has less then half of what the newest designs offer peripheral wise.

I don't have the exact figures, but if you are only logging every quarter second or longer you could use external SPI based memory. If you need something faster parallel memory isn't too hard to work with, but has at least 5 times the connections to deal with.

Good luck!! I'm kind of going down the same road myself.
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
39
I'm planning on using assembly language. The research I did on PIC's in the past lead me to believe that a high level language was not worth it. I have studied some C and some assembly but have never written any code. I don't want to abstract the process of the device if it is possible.
 

MrChips

Joined Oct 2, 2009
20,167
Based on your current knowledge and experience there are different approaches to your situation.
Do you want:

1) to gain a working knowledge of microcontrollers (MCU) and MCU applications
2) to be able to understand and use Microchip PIC MCUs
3) to become a reasonably knowledgeable ASM programmer
4) to become a reasonably knowledgeable C programmer
5) to gain in-depth knowledge on MCUs, embedded systems and associated electronics
6) to be able to buy and use off-the-shelf data loggers without the need to know any of the above

Answer any the questions and you can choose your learning path.
There is no short cut to in-depth learning about electronics, computers, and programming.
 
Top