CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Datalogger project
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
eye1984



Joined: 08 Mar 2012
Posts: 7

View user's profile Send private message

Datalogger project
PostPosted: Thu Mar 08, 2012 12:07 pm     Reply with quote

Hi everyone, I am new in pic and C programming, but i need for my school project to develop a datalogger, which will be inserted in the wall under the switch for lights (so small and for 1 year living from battery). I need it cheap, because I need log that in more rooms so i have chosen 12f675 for its small size and sleep function, pcf8583 for save time and eeprom 24lc512 for storing data. Circuit is in picture, but i need strong help with program. I think the best solution for battery lifetime is that:

1) pic read switch (turned off), read time from pcf8583, enable eeprom by log 1 on GP2, write it to eeprom V:hh:mm/DD:MM, disable pin GP2 to save battery power, sleep procesor/wait for turn on.
2) After switch turned on - wake up procesor, read time from pcf8583, enable eeprom by GP2 , write time to it Z:hh:mm/DD:MM, disable eeprom by GP2 get low, sleep procesor/wait for turn off.

If it will by readable from eeprom by hyperterminal and time/date possible to set up, it will be very comfortable for my research. But microcontrollers are not my specialization and this is only one project for me and to learn for one project complete i2c communication and C programing for pic is too difficult. I have only one month to do that. (If I will not buy datalogger in shop for about 70eur which in 10 rooms mean 700eur).
Because of that i will ask if is here some good soul who have function parts of that what i need (I browsed forum for 3 days and found only little things about intosc and fuses or something about eeprom writing but for another processor). Or if someone will help me with program that stuff.

thx for help



Last edited by eye1984 on Thu Mar 08, 2012 6:23 pm; edited 1 time in total
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Mar 08, 2012 1:32 pm     Reply with quote

you need to try to code this and see how far you get.

this is not a resource for doing your creative THINKING for you .

or the homework for that matter, either.

BTW: R Y sure U sized your storage big enough ??

Smile Smile Very Happy Very Happy Exclamation Question Arrow
eye1984



Joined: 08 Mar 2012
Posts: 7

View user's profile Send private message

PostPosted: Thu Mar 08, 2012 2:23 pm     Reply with quote

i don't know if 512kb is enough, but it is the biggest eeprom in my local store.

i am trying it, but after one week i have only blinking led until switch is pressed.
after that i try to implement ex_wakup.c to 12f675 from ccs c, but i think it is not working, i would to blink led on gp4 2 times, after switch is on, and go sleep....but when i use #int_EXT it is not working for me, when i use #int_RA with the same code in routine as in #int_EXT, i think it works but led will not blink 2 times but only once and after switch turned off it again blink only once. this is my code for now:
Code:


#include <12F675.h>
#device adc=8
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, BANDGAP_HIGH, RESERVED
#use delay(clock=4000000)

short sleep_mode;

#int_RA
void  RA_isr(void)
{
static short button_pressed=FALSE;

   if(!button_pressed)        // if button action and was not pressed
   {
      button_pressed=TRUE;    // the button is now down
      sleep_mode=TRUE;        // activate sleep
      ext_int_edge(L_TO_H);   // change so interrupts on release
   }
   else                       // if button action and was pressed
   {
      button_pressed=FALSE;   // the button is now up
      sleep_mode=FALSE;       // reset sleep flag
      ext_int_edge(H_TO_L);   // change so interrupts on press
   }
   if(!input(PIN_A5))         // keep button action sychronized wth button flag
      button_pressed=TRUE;
 
}

void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC);
   setup_vref(FALSE);
   clear_interrupt(INT_RA);
   enable_interrupts(INT_RA5);
  enable_interrupts(GLOBAL);

loop:   sleep_mode=FALSE;          // init sleep flag
   ext_int_edge(H_TO_L);      // init interrupt triggering for button press

while(TRUE)
   {
      if(sleep_mode)          // if sleep flag set
        output_high(PIN_A4);    // blinking will be changed with
        delay_ms(500);            // reading/writing routines
        output_low(PIN_A4);
        delay_ms(500);
        output_high(PIN_A4);
        delay_ms(500);
        output_low(PIN_A4);
        sleep();             
       goto loop;         //never executed
   }

}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Mar 08, 2012 3:18 pm     Reply with quote

OK the code does have a way to go before you are ready to be critiqued on function.

But here is a conceptual thing i wonder about?

you are using an I2C EEPROM that has page or byte mode - lucky it has BYTE mode because your pic has not got enough RAM to buffer a page
Very Happy Very Happy

But it only has 64K bytes of storage and you said you want perhaps a year of data ... your data format if it was expressed w/o delimiters as ASCII will take 18 bytes for every on/off cycle. thats a total of only 3640 total captures on/off events. Lets stipulate that given a compact binary STRUCT for your data could take less space:

such as V || Z is a single bit
&& that V!Z is the high order bit of a single BYTE conveying the seconds value in binary - && similar compression of the other data.
Then this could be packed in say 12 bytes or less for each full cycle of recorded events .. BUT , thats still only 5460 events or put another way about 15 times ON/off per day that you have space to record.

Is that an amount that will actually be enough?

ALSO - your code must have a bullet proof way of managing and storing the pointer to WHERE the next block of data will be written.

Have you thought about how you will handle your external EEPROM when power is applied - to find out what is written and what is not ?

I am still thinking about your concept for using sleep in between events,
as it may be harder to implement than you think, given your honest admission about your program skills.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Mar 08, 2012 3:21 pm     Reply with quote

also LOOK AT YOUR SCHEMATIC CLOSELY

where is PIN 2 of the PIC connected --

what does the switch ACTUALLY DO ?????

what do you think >
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Mar 08, 2012 3:23 pm     Reply with quote

also
HOW WILL YOU SET your RTC ????
eye1984



Joined: 08 Mar 2012
Posts: 7

View user's profile Send private message

PostPosted: Thu Mar 08, 2012 4:04 pm     Reply with quote

How to set up the rtc i don't know, if through pic/rs232 or only leave it unset if it starts counting from power up and correct dates in PC after downloading data from eeprom.
I think that in most rooms there will be on/off cycle for 5-10-times per day maximum, so i think it will be enough.

And thank you for warning, it is mistake, pin2 is connected between SW and resistor of course.

Its everything new for me and that are only ideas how i think it can be done. It is for research lab to make graphs from that data to show how long was turned on lights in every room of building. So at the end i will download data to Excel and make graphs based on months to show how is weather and year seasons influencing to need of light turned on, and for graphs how long people stays in rooms (when light is on) in rooms without windows.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Mar 08, 2012 4:18 pm     Reply with quote

It is an interesting project - and of a sort that has often been done before.

Getting your data out of the EEPROM ought to be considered before you go a lot further, as well as proper RTC management control.

I would have a super-cap OR memory battery for the RTC
AND perhaps using the RTC user RAM for my "next write pointer".

also

I personally would do this with a higher function PIC
such that there is RS-232 for:

1- setting the RTC
2- playing BACK the EEPROM data
3- design so you can switch the PIC from 32khz RTC mode to Internal 4 or 8 mhz during RS-232 operation with a host

Are you going to seriously produce number of these or just hand in a prototype??
eye1984



Joined: 08 Mar 2012
Posts: 7

View user's profile Send private message

PostPosted: Thu Mar 08, 2012 4:38 pm     Reply with quote

Only prototype - little series in about 10 pcs. I have selected 12f675 for price, size of only 8 pins and i2c, sleep and low power consumption and internal oscillator for minimum parts. But if it is better solution with bigger pic, it is no problem to change it. Only requirement is that all that parts with 3V battery must be on pcb - round of maximum diameter 5cm.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Mar 08, 2012 7:39 pm     Reply with quote

You can have it all - including an RS-232 TTL I/O system with twice the program memory in the 12F1822.

Check it out and adjust your schematic.

With this small change you can have external setting of the RTC and a way to play back your data by simply diode coupling and upping your VCC to 5v externally and provide a MAX232 or FTDI UM232 to get a standard EIA RS-232 PC connect or a USB connection - respectively.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Mar 09, 2012 7:35 am     Reply with quote

asmboy wrote:
... and upping your VCC to 5v externally and provide a MAX232 or FTDI UM232 to get a standard EIA RS-232 PC connect or a USB connection - respectively.
I don't see why the external VCC should be upped to 5V? Many RS232 and USB drivers do exist for the 3V , maybe even more than for 5V.

I do agree that the means for reading the data have to be considered as one of the first design goals. Instead of including the RS232/USB drivers on every board you could consider an external board with these components and then a simple straight connector to the serial CMOS port on your PIC18F1822 (with UART) logger board. This has the advantage that your logger PCB can be smaller and cheaper. Reading the eeprom and setting the RTC are tasks only performed on installation and one year later at removal. A waste of money and PCB space to implement this on all 10 prototype boards.

As power supply I recommend to use a lithium battery as these have a high energy density and very low discharge rate. For example a CR2430 (3V, 280mAh) or CR2450 (3V, 600mAh). Special versions of these batteries exist that you can solder directly on the pcb. The option of using a direct mains power supply I wouldn't recommend because costs, space and safety reasons.

With a 280mAh battery your average current consumption can be:
280mAh / (365 days * 24 hours) = 32uA
Considering that your application will be only active for a few seconds a day the higher current used during activity is neglectable.

Out of curiosity I checked the PIC12F1822 datasheet and was surprised by the high current consumption during sleep: 22uA at 3V
Within limits, but when compared to the PCF8583 3uA@3V typical (but 30uA max. !!) and 24LC512 sleep current of 1uA max., the PIC12F1822 is using a lot of current while sleeping.


A good article on low PIC power consumption is Microchip AN606. This also describes a simple external circuit to completely power of the PIC with a total power consumption during power off of just a few nA.

Or consider using the PIC18LF1822 (note the 'L') which has a much lower sleep current of 0.03 uA.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Mar 09, 2012 8:02 am     Reply with quote

A good suggestion from Asmboy is to use the non-volatile RAM in the clock chip as a storage for the EEPROM write address pointer. Otherwis, if you are not planning on using the clock chip's RAM you could change the PCF8583 for a PCF8563 which has a lower power consumption of typical 0.4uA @ 3V
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Mar 09, 2012 8:04 am     Reply with quote

Quote:

VCC should be upped to 5V?


Not suggesting to RUN the logger on 5v - ONLY that it CAN be run on 5v when you are EXTERNALLY connecting for control of the RTCC , setup /reset of the EEPROM and PLAYBACK of captured data . all thats needed is a typical low drop diode as part of the PSU section.

Quote:

the PIC12F1822 is using a lot of current while sleeping.


I believe this is a worst case figure at 5.5v Vcc and is actually configuration dependent and proportional to Vcc .
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Mar 09, 2012 11:41 am     Reply with quote

asmboy wrote:
Quote:

the PIC12F1822 is using a lot of current while sleeping.


I believe this is a worst case figure at 5.5v Vcc and is actually configuration dependent and proportional to Vcc .
I think the difference between an F and LF version is very large, but which part of parameter D022 in table 30.3 am I misunderstanding?
DC Power-Down current for the 'F' version: typical 22uA at 3V (WDT, BOR, FVR, and T1OSC disabled, all Peripherals Inactive)
For the 'LF' typical 0.03uA at 3V

Almost a factor 1000 difference?
eye1984



Joined: 08 Mar 2012
Posts: 7

View user's profile Send private message

PostPosted: Fri Mar 09, 2012 1:53 pm     Reply with quote

today i have searched in all eshops and local stores in my city(eshops in my country) and 12f1822 / 12lf1822 is not possible to buy :(


12f are possible only 12f508/509/510/629/675
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group