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 support@ccsinfo.com

PIC16F73 RTC help needed.
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PIC16F73 RTC help needed.
PostPosted: Sun Jan 11, 2015 10:01 am     Reply with quote

Hello,
I am new to PIC programming. I know some C. I can build PCB and know basic to moderate electronics.
I did program some PICs projects in the past 4 months and I had a lot of fun doing so. Most of my project I got from online and I did some edit to fit my need.
I know I am asking too much, but I really need someone to help me and provide code for my project. Your help will be greatly appreciated!
I built the project below and I had been trying to program it without any luck.
My project is basically a real time clock for feeder. Using watch crystal, 4X7 segments display to show the time and settings, some switches and a MOSFET to power a 12V DC motor.
This is how I think it should work:
1- I need to save power as the project uses 12V battery to power the motor and LM2672 to power the circuit with 5V.
2- The displays disabled (turn OFF) when no key press within about 10 seconds to save power.
3- The time is 24H military time format.
4- By default and hard coded 4 feeding times 7:00, 8:00. 16:00 and 17:00 for 3 seconds each. The time and interval/motor running time can be adjusted (the interval/motor running time can be adjusted from 0-10 seconds).
5- The “Test” key will enable the display and will show a count down from 10 to 0 in seconds and once reach 0 the motor will run for 3 seconds.
6- The “Mode”, “UP” and “DN” keys will enable the display and to set the real time clock, the 4 feeding times and the interval/motor running time. I am open for suggestions for these three buttons and how they should function to achieve the best out of them! Even if I have to rename them to whatever you guys suggest.

I already build a prototype for this project.

These are the datasheets for the components:
PIC16F73 Datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/30325b.pdf

ELF-511EWA Datasheet
https://www1.elfa.se/data1/wwwroot/assets/datasheets/07506827.pdf

FDP7030BL Datasheet:
https://www.fairchildsemi.com/datasheets/FD/FDB7030BL.pdf

LM2672 Power Converter High Efficiency 1A Step-Down Voltage Regulator
http://www.ti.com/lit/ds/symlink/lm2672.pdf

Thanks in advance,
Sam

This is the schematic
(alt+p)


Last edited by Sam_40 on Sun Jan 11, 2015 11:22 am; 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: Sun Jan 11, 2015 10:24 am     Reply with quote

some immediate comments:

1- make R8,9,10,11 == 4.7k as you will draw too much base current as shown

2- use a 4.194304 mhz or 8.388608 mhz crystal and do more division to get your time in seconds or useful fractions. 32768 hz will not be much good for multiplexing your display as your working Fosc is only gonna be 8192 hz and divided between 4 digits is going to starve your program for useful cycles if the display is to be maintained with low flicker. you need to be button scanning too remember!!

3- alternatively use any faster master clock frequency and use the timer1 OSC at 32768hz

4- otherwise your circuit looks well designed.
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 10:50 am     Reply with quote

asmboy,
Thanks for the reply:
1- Consider it done. Do I need to do the same for R21 for the MOSFET?
2 & 3- You have a point. I did notice the 32768 will make the displays flicker. however the datasheet for the 16F73 shows that "the LP crystal option saves power.". The little flicker is acceptable.
4-Thanks, That made my day Smile
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Sun Jan 11, 2015 10:59 am     Reply with quote

I like to assign blame , where blame is due. Very Happy Very Happy Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 11:04 am     Reply with quote

some comments...

1) consider using an LCD module for the display. Around here they're about $5 and far simpler to connect and use.You can eliminate the 2n3904s and 8 resistors AND make the PCB a lot simpler.As well power is far less with LCD. There is a 'flex_lcd' driver on this forum allows for simple 6 wire interface.

2) use a BIG battery! far too often people use a low aH battery for cost or size, yet for not much more a 'real' battery can be bought. Also consider a 'supercap' on the +5 of the PIC AND be sure the +12 has a big( 4700mfd)cap as well. When the motor turns on it will 'dip' the +12 and maybe the +5 depending on current drawn. This might reset the PIC or send a 'glitch' to it.

3) you should add small 'debounce' caps ( .1 mfd) across the push buttons and/or add code to eliminate switch debounce. All mechanical switches do this, giving multiple '1s and 0s' when operated.


otherwise the schematic seems good.


Jay
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 11:28 am     Reply with quote

I did update the schematic as suggested.

Temtronic,
Thanks for the reply,
1- I see your point, however for this project I need to use the 7 segments.
2- I will be using 12V 7.5AH battery or equivalent in size. The motor will draw 1.2 AMP under extreme load. The 47uf cap I used is not enough?
3- Thanks for the info. I did add the caps in my updated schematic and I will add them to my prototype board.

asmboy,
Do I need to do the same for R21 for the MOSFET?
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 11:31 am     Reply with quote

Agree with the LCD - MUCH lower power. Also, you might want to experiment with putting a small cap across R22 for the FET - depending on the value of the cap, you slow down the turn on/ turn off of the fet. This makes for much less in the way of spikes/junk on the supply and provides a soft start/stop on the motor. You have to weigh that with you are now putting the FET in the linear mode for a short time and as such, depending on the time constant of R21 and the cap causes some heating of the FET but it can make every thing else much cleaner.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 11:39 am     Reply with quote

One important difference between MOSFETs and bipolar transistors is that the base/gate drive is different. For a bipolar transistor, the transistor is controlled by the base current into the base times the gain of the transistor and the base looks like a diode from a modeling point of view (about .7 v). A MOSFET is voltage controlled and has virtually no current into the gate (other than charging / discharging the gate capacitance which is significant at high speed). You can use much higher values for R21 and R22 with a MOSFET since they are not supplying any current to the gate (other than charging the capacitance associated with the gate).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 11:46 am     Reply with quote

mikey,
Thanks for the reply, The displays are only turn ON upon setting and testing! So no power consumption during operation.
Do you think R21=10K and R22=100K is better?
Would you please refer me to an example on the use of CAP that provides a soft start/stop on the motor?
Thanks,
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 12:01 pm     Reply with quote

Worth being aware that a very large amount of your power is actually going to be wasted in your regulator!...
This has a quiescent consumption when running of about 3mA. When your PIC is asleep, this will be the biggest use of power. You might consider (for example) having a very small supply that just runs the PIC, and only turning on the other supply when you want to use the display. Maxim do some low power switchers rated for 100mA max, that have a quiescent below 100uA.
temtronic



Joined: 01 Jul 2010
Posts: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 12:03 pm     Reply with quote

re: the RTC portion...

There's a software based RTC in the 'code library' on this forum. Easy to adapt to your PIC and xtal. Makes a great 'start' for your RTC section of code

re: motor FET cap...the datasheet of the FET should have some ideas. Maybe start with .1 " Easy to test, no PIC needed, just breadboard and monitor the V across FET or motor.

hth
jay
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 12:34 pm     Reply with quote

Your 10k/100k would probably work just fine. For the cap, since your comment was this was for a feeder, I assume it only happens a couple of times a day and runs for several seconds when it does - consider something that would give you say 250ms turn on/off time on the motor. Look at the FET data sheet for the voltage levels for control and figure a time constant that would give something in that neighborhood. Experiment and see what works best from there. I have not looked at that FET, but since you are working with 5v control, make sure it is rated for logic level control (many FETS don't completely turn on with 3-4 volts on the gate).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 1:08 pm     Reply with quote

mikey,
The MOSFET I am using is the FDP7030BL N-Channel logic level powertrench MOSFET with gate threshold voltage of 1 to 3 V.
I did try it by just activate and deactivate the RA4 and it seams to be OK as it is on the schematic. You are correct, the motor will turn on for no more than 10 seconds per feed 4 times a day.

jay,
Actually this post inspired this project:
http://www.ccsinfo.com/forum/viewtopic.php?t=26177

Ttelmah,
Thanks for the info, I will look into the use of more efficient power management for the 5V.

Now all I need is a code to make my project alive Smile
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sun Jan 11, 2015 2:07 pm     Reply with quote

Looks good on the MOSFET - I tend to be a bit paranoid about spikes and things so the one I often use is the IRL520 (same price range - about $1.20) it is only rated for 10A instead of the 20A yours is, but is rated for 100V instead of the 30V for the FDP7030BL. Also logic level (the "L" in the "IRL" indicates logic level drive).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Sam_40



Joined: 07 Jan 2015
Posts: 127

View user's profile Send private message

PostPosted: Tue Jan 20, 2015 8:14 pm     Reply with quote

I think I got the switches and the RTC function just right as far as code.

1- Where can I find any good example on how to drive 4X7 segments LED for my project? I am having a hard time with this :(

2- asmboy had suggested "alternatively use any faster master clock frequency and use the timer1 OSC at 32768hz" to use faster clock for the multiplexing. How to do this? All the examples I had seen so far using either external crystal or internal clock but never seen both. Would someone please explain this.

Thanks,
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, 3  Next
Page 1 of 3

 
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