Dear everyone!

I am in the process of starting a new project around the 18F13K50, which have to mix ultra-low power and USB communication, a combination that seems to be difficult to mix.

I had previous success (about 3 years ago) with a couple of very simple project around the 18F2550/4550 and CDC communication profile. But now it seems that there is much more new things added to USB coding, including new USB handling library, and of course new USB pics from microchip too! The PIC18F13K50/14K50 is now becoming an exciting candidate for very small USB projects, and after upgrading MPLAB, purchasing a PicKit 3 and trying to makes everything working back together I can now concentrate on writing code!

Now onto the project, it is a temperature logger that will sample temperature at a preset interval of time and store it in EEPROM. Content of the EEPROM can then be uploaded to a computer using the CDC USB profile. This is actually very similar in conception to jellish00 ultrasonic logger project that was discussed a bit in this post.

Temperature logger in standalone mode
Now the challenge is to run the device out of an ultra-small 25mAh LiPO battery. That is not a whole lot of juice, but using power conservation technique I hope to be able to run it for a long period of time (namely, a few months).

The hardware that will actually eat power on the device:
- 3,3V Voltage regulator, TPS72933, quiescent current 500nA.
- I2C EEPROM, quiescent current about 1ľA, 5mA when writing.
- I2C Temperature sensor TMP100, quiescent current about 1ľA, 70ľA when sampling.
- A bicolor LED, for indicating errors (battery low, memory full). This will not be normally used.
- The PIC, which is going to be the biggest battery drain.

Here's my idea for power-saving for the PIC. Ideally a timer with the crystal used as a clock source (for accuracy) would be used to define my sampling interval (ideally 1sec, or 5sec). this would send an interrupt to the PIC, getting it out of sleep mode. It would then increment a counter (to get to longer sampling intervals), and when needed, trigger a temp sample on the TMP100 and store it to EEPROM. Then going back to sleep till next timer interrupt.

The USB charger is also connected to INT0 to send an interrupt when the USB power is connected.

The battery voltage level is also measured with the PIC ADC, but can be polled with temperature.

While the timer is ran on the external crystal oscillator, the PIC core may have to be run on the LF internal oscillator (31kHz), providing the lower consumption. The operation in standalone mode is actually not very challenging, what is more is to do it with little power!

Temperature logger in USB mode
In USB mode the logger will charge its battery over the USB current. I will have to wake the USB module oscillator, and very likely to change the core frequency to a much faster pace in order to send the data rapidly. The complicated part is all the USB code to handle the CDC communication, and I don't see myself writing that in C or assembler!

While I understood that the PIC can support all this in hardware, I am not sure about the capability yo implement it all in PicBasic, at least without using ASM calls. DEFINE OSC can only be used once, making a change in OSC frequency difficult for all PAUSE and delays used in the program. DEFINE OSC cannot accommodate for anything lower than 3.58MHz too. Hardware interrupt are not very obvious to handle in PicBasic, though I just found out the library written by Darrel Taylor which looks very promising. I have yet to dig in the details for using it.


Here is the quick and dirty prototype... at least the hardware works nicely!



Of course there's extra things too, the LCD is actually quite handy for debuging
Here it is polling temperature from the TMP100 in "one shot" sample mode, displaying it as the raw 12bit data + converted value (Yes it is hot in Paris tonight!).

Any consideration on the feasibility of such project with PicBasic?

I will probably have more question that will arise while advancing in the programming...

Looking forward to discuss around this!