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

Thread Starter

Beetle_X

Joined Nov 2, 2012
41
I found this data sheet for a for a RTC and it's intentionally comprehensive. lol
https://www.nxp.com/docs/en/data-sheet/PCF8583.pdf
As far as memory/buses goes I want to use something that is a balance of function and complications.It has to be a balance of practicability. I imagine if successful I will have to build or modify at least 3 data loggers. The last one would have a character screen to get data from.
So basically when using a RTC you are tethering two IC's together and using the RTC to signal the PIC.
 

BobTPH

Joined Jun 5, 2013
2,260
I use C on PICs for most of my projects, often with a small amount of inline assembly code for speed.

I would only use assembly on a very small PIC, where limited code size is a problem.

But since I do not do mass produced products, I don’t try to save a dollar by going to a smaller PIC, I typically use the one with the largest memory in the family I am using, because saving a dollar or two is not worth the headaches and extra time needed to make the program extra compact.

Bob
 

BobTPH

Joined Jun 5, 2013
2,260
I see no reason to add an RTC. The PIC itself can do everything the RTC chip can. You just need to use a crystal for the clock. KISS.

Bob
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
41
I see no reason to add an RTC. The PIC itself can do everything the RTC chip can. You just need to use a crystal for the clock. KISS.

Bob
I agree but how do I get a PIC to sample at such a slow speed? What is the first method to slow it down and ending by the last method. I would guess the last method would be op code loops. Can interrupts actually be counted?
 

MrChips

Joined Oct 2, 2009
20,263
I agree but how do I get a PIC to sample at such a slow speed? What is the first method to slow it down and ending by the last method. I would guess the last method would be op code loops. Can interrupts actually be counted?
There are suitable answers to all of your questions which are valid.
The problem is where to begin answering your questions.

Question #1
Do you want to design and build your own data logger or do you want to be able to control an existing data logger?
 

jpanhalt

Joined Jan 18, 2008
8,746
Which is it?

I'm looking to build my own logger. :)
or
Peripheral interface Controller; first designed for phone modems. When it gets down to the fine details I'll be at the microChip site. :eek:
Second:
Mostly I want to data log at a rate of maybe every 15 seconds to maybe 300 per second for a auto sensor logger.
Neither of those rates is particularly slow or fast. As I said in my original post here, I save a sample every minute which is an average to 10 measurements made every two-seconds. How fast you can go up to your 300/second will more likely be limited by your sensor.

My PIC16F1xxx is running at 32 MHz. If I wanted something really slow, I might add a watch crystal for Timer 1. Your responses here have been quite vague. Maybe it is time for you to outline in more definite terms what you want to do and the questions you have.
 

MrChips

Joined Oct 2, 2009
20,263
For timing functions just about any MCU will work. You do not have to change anything or add any external timer.
It doesn't matter what clock frequency the MCU is running.
Using any internal HW timer or SW timer you can create any time interval you need (greater than micro- or milli-seconds).
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
41
I pretty sure that PIC18F452-I/P's don't have a clock so I will be looking for another micro controller.https://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf. I don't want to buy a system from a manufacturer that needs a special compiler .burner, etcetera. That's why I bought a PIC.

My programmer is a MicroByte 2.10 PDB-MB2D which looks to be defunct but I have the manual for it. Does anyone know of a host that would store the manual if others are looking for it?
 

BobTPH

Joined Jun 5, 2013
2,260
Can interrupts actually be counted?
You keep a clock in a PIC by using a timer to interrupt at a specific time period. The interrupt handler the adds one to a counter. If you like, you can convert this count to msec, seconds, minutes and hours, but that is not necessary.

You then schedule the next sample by adding to the current time, and checking periodically if the time has been reached. You can even trigger the tests in the interrupt handler, since the time only chagrs at the time of the interrupt.

Actually, at least some PICs have hardware capabilities to run period samples without any intervention by the code, but this approach would not be as flexible as the approach above.

You need to get some PICs and start doing tutorials to learn how to use them. Then you will be ready to make informed decisions about your data-logger.

Bob
 

BobTPH

Joined Jun 5, 2013
2,260
All PICs have a clock, actually multiple clocks.

If you mean realtime clock, you are probably correct, but that is done with software. See my previous post where I told you how that is done.

Bob
 

BobTPH

Joined Jun 5, 2013
2,260
Using any internal HW timer or SW timer you can create any time interval you need (greater than micro- or milli-seconds
A 1 msec clock is no problem even on a PIC running at 4MHz. It can execute a thousand instructions in that time. So an interrupt handler using as many as many as 50 instructions would leave you 95% of the processor time.

Bob
 

Thread Starter

Beetle_X

Joined Nov 2, 2012
41
I would like to thank all of the posters on this thread.:) I would otherwise be trying to make a data logger without a oscillator.o_O
I made a sh.t choice for a first pic.lol I'm going to shelve the PIC18F452-I/P for a PIC18F4520 just for ease. I won't have to try to source the external oscillator and I want the experience with the internal oscillator. I'll save the PIC18F452-I/P for a project down the road.
 

AlbertHall

Joined Jun 4, 2014
9,310
. I won't have to try to source the external oscillator and I want the experience with the internal oscillator.
The oscillator is still internal but the frequency determining element, the crystal, is external. The PICs with built in oscillators are nowhere near as accurate as using a crystal. It all depends how accurate you want your timing to be.
 

MrChips

Joined Oct 2, 2009
20,263
I pretty sure that PIC18F452-I/P's don't have a clock so I will be looking for another micro controller.https://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf. I don't want to buy a system from a manufacturer that needs a special compiler .burner, etcetera. That's why I bought a PIC.

My programmer is a MicroByte 2.10 PDB-MB2D which looks to be defunct but I have the manual for it. Does anyone know of a host that would store the manual if others are looking for it?
You are confused as to what constitutes a clock.
ALL MCUs have a clock.
A clock is not just a time-of-day time keeper. It is any system or procedure that can keep track of time.
ALL MUCs have an oscillator. It does not necessarily have to be an external oscillator or an external crystal. Many MCUs have internal oscillators.

As long as the code is running you can keep track of time. If you need to stop the MCU for low-power battery operation then you need an oscillator that keeps running while the CPU core is halted. MCUs designed for this in mind have internal oscillators that keep track of time even while the main power is turned off.
 

jpanhalt

Joined Jan 18, 2008
8,746
Since we seem to be in the gray zone between reality and hypothetical, it may be worth pointing out that PIC's are specified for clock frequencies of DC:
1579903675773.png

That's particularly interesting, because SPI is also specified at DC, but I can't make my led's flash with either at DC.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
6,171
FYI, a DS3231 is a single chip real time clock. Which operates in a coin cell. This is important because the chip can keep time by itself and you’ll only need an MCU to wake up to perform a task.

You haven’t mentioned where you’re going to store the data being logged. In the MCU RAM? It might be list during a power outage. There are microSD card modules that can permanently store your data, and depending on your computer, can be directly read into the PC or laptop.

Another point, you comment on needing a special compiler. Most MCUs do require a special compiler. Except for open source MCUs. Many people shudder when they hear Arduino, but that label refers to more than a specific MCU. It refers to a class of MCUs, barebones or complete system, that can be programmed by the Arduino IDE. Due to the popularity of the IDE, new MCUs are being developed to support the Arduino IDE. For example, the ATTiny series of MCUs can be programmed in C using the Arduino IDE. I’ve programmed devices using the ATTiny85 MCU with the Arduino IDE. Also, I’ve programmed a proprietary language on the ATMega338... using the Arduino IDE. It’s being migrated to a standalone system as I write this.

I suggest you follow on with the PICs as it appears you are most familiar with them. Just wanted to make a point that be careful about your assumptions. There may be another solution stating you in the face.
 

jpanhalt

Joined Jan 18, 2008
8,746
When I noticed the TS had been a member of AAC since November 2, 2012, I wondered why he was still a "novice." So, I looked up his other thread: https://forum.allaboutcircuits.com/threads/eprom-emulator-basics.76511/#post-540285 No real conclusion there.

Given the vagary of this current thread, I still wonder for what outcome we are searching. If the TS is a novice to MPASM Assembly, then the PIC18Fxxx and others may not be the best device with which to start. On the other hand, if the TS has 7+ years of experience, then maybe that is appropriate, but his questions about oscillators belie that assumption.

I have asked the TS what he wants to know, yet that has been ignored. The enhanced mid-range MCU's from Microchip will do everything the TS has asked and have a far simpler instruction set. Moreover, many have internal oscillators that are relatively accurate to the as yet unstated needs.
 
Top