View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 354
|
dsPic33EP512 question |
Posted: Sat Mar 17, 2018 3:22 am |
|
|
Hello Developers!
Some of you know that I'm in the process of learning and playing with dsPic33ep512mu810 microcontroller.
I want to ask you some important questions for me.
1. I need RTC clock/calendar for many of my projects and I sow in datasheet that dsPic33ep512mu810 has an RTC but there is no separate batt. backup pin. How to use it if power switch off?
Because I am in the process of DESIGNING the hardware want to ask you:
2. How to design some power-fail circuit ? With adc voltage measure, with comparator trigger ...etc.?( Very important for me! ). The board will be powered with 12 to 24 v dc power supply.
3. Need some storage devices (FRAM, SD) . How it would be best to connect to MCU? Connect them to one SPI port with separate ChipSelect?
For now i have connected ENC28J60 Ethernet controller to SPI2(G6,G7,G8 and B0->CS)
Which would be better SPI FRAM (CY15B104Q) or I2C FRAM (FM24Cxxxx)?
You know all your suggestions will be very helpful for me!
Best Regards! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sat Mar 17, 2018 4:18 am |
|
|
The chip has to remain powered.
The base current in only a couple of hundred uA. You put the chip to sleep, and just leave the RTCC running.
Honestly, if you want a RTCC that you can keep running off a small battery while the main chip is switched off, you are better off using something like an MCP7940 or DS1337.
The crystal usually costs as much as the chip, and using I2C, it only costs two pins that you may well be able to also use for another I2C device.
You should never have to hurry on detecting power fail. Understand that if (for instance) you have perhaps 1000uF of capacitance on the supply rail, this can usually power a processor for many tens of mSec. So what you do is detect the voltage on the incoming supply falling just below the point where the regulator can maintain the processor supply, and start to tidy when this happens. A comparator interrupt is ideal for this. The LVD circuit present on many chips is just a comparator set to trigger at a specific voltage on a pin.
What you need to ensure is that there is sufficient reservoir to complete any high current operation. SD writes in particular draw a lot.
Do you genuinely need both SD and FRAM?. SD has the problem that you have to write large blocks. So with the high supply requirements, a lot of reservoir is needed.
SPI is generally faster than I2C. However I2C is better if the signal has to travel any distance. Down to what your actual speed requirements are. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Mar 17, 2018 5:16 am |
|
|
I have to agree with Mr. T, an external RTC device is a better option than using the PICs internal one. There are 2 problems using the RTCC of a PIC. The first is needing to provide some form of backup power and ensuring that everything other than the RTCC is turned off when 'sleeping'. The other problem is corrupted time. The RTCC data is in the PIC so if the program goes 'funny' or 'crashes', the RTCC data is probably bad. An external RTC chip minimizes those problems. Currently I'm testing the DS3231 and it is a better time keeper,however is lacks the batttery backed RAM the DS1307 has. You can use the 7 bytes used for 'alarm data' as BBRAM though !
With respect to storage, how much is required and how will it be used? If it's to be a 'data logger' consider a Vinicum or similar storage device. While not the cheapest solution the benefits are 1, easy serial interface, 2,unlimited storage and 3, PC friendly. I used one years ago and stored the greenhouse data as a 'CSV' file. Took flash drive to PC, and eXcel read the data into a spreadsheet..all neat and tidy ! There are other 'mass storage' devices available now, so check and decide based on your needs. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Sat Mar 17, 2018 7:10 am |
|
|
Hi,
For current project, the data size that I need to store is small (8 device with 10 int32 totalizers : 8 * 10 * 4 bytes = 320 bytes + ~100bytes config. datat). For now i2c F-RAM FM24c02 will be enough. Also need some data integrity check. Adding some crc check for all int32 totalizers?
SD card interface and CAN are not needed for now but I have to add for future projects!
With your professional advice I'm planing to use i2c RTC and F-RAM storage.
Thank you! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Mar 17, 2018 7:14 am |
|
|
You should check the prices for FRAM. A larger device might be cheaper ! I know that a 'bigger' PIC is usually cheaper as they make more of them . |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Sat Mar 17, 2018 8:33 am |
|
|
If really good accuracy for your RTC is required (less than a couple of seconds drift per month), then consider using a 32.768kHz oscillator to feed your RTC instead of a standard crystal circuit. Getting the PCB layout just right around the crystal to minimize drift is tough. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Sat Mar 17, 2018 10:26 am |
|
|
Hi,
Couple of seconds drift per month is not a problem.
The most important thing is speed. If I get the power-fail signal i have to save, in worst case: x8 int32 variables, x8 rtc times (may by in BCD format?) and couple status bytes!
DsPic33ep512mu810 has no LVD circuit only comparator module. Any example how to use it for PowerFail circuit?
For SD card interface where will be better to connect: (1)On the same spi port with enc28j60(SPI2) or (2) another spi port? I have no experience with SD card!
Thanks. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sat Mar 17, 2018 11:55 am |
|
|
On the comparator, a voltage reference feeding one input. Say 1.024v. Then a voltage divider from the incoming rail feeding the other input. So if (say) your 24v rail is guaranteed to give 22v minimum, a divider using perhaps a 250K and a 12K from the supply. This will give 1.024v at 21.33v, just below the lowest guaranteed in normal operation, and well above the point at which the regulator stops working. When it triggers you have all the time till the supply falls to the point where the regulator drops out, to finish the current operations.
All you then do is complete, and sit in the handler for this interrupt. You then wait for longer than the normal supply drop time, and check the input again. If it has gone back above the trigger point, wait a little longer and return to normal operation. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Sat Mar 17, 2018 1:10 pm |
|
|
Thank you all , Ttelmah!
I will do some tests in monday and write again.
Best Regards! |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Sat Mar 17, 2018 1:19 pm |
|
|
I forgot to say that ethernet controller enc28j60 is very "power hungry" device and I may have to design some mosfet switch off circuit when fire into power-fail state. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Mar 18, 2018 10:25 am |
|
|
Can I suggest if you are going FRAM, why not look at the FM3164, or FM31256. 64/256K FRAM and an RTC. Just needs a 32768Hz crystal and a battery. Ideal for your job.... |
|
|
|