Noob project needs some critique. EagleCADsoft file attached

Thread Starter

jameschristian

Joined Nov 24, 2011
58
Interesting idea with the ICSP strip. I have a Willem programmer that I have been planning on using, and can't really afford to branch out for the moment, but it's something to think about nonetheless. Is it a good idea to have just in case I want to do some reprogramming? Or better yet, is it something I should be doing and just nix the Willem programmer? I also like the wider traces. Seems like it'll make for a longer life for the project once it's built. The charlieplexing idea is a cool one, mostly because I love anything that concerns maximizing efficiency, and also because I have never built one. It may be superfluous given that I think I just want to go with variable times for the fan to be on, and not variable speeds. I will work it into a future project if I don't go with it on this one though, just too cool to not use. I am planning on making a remote starter for my car, so I am thinking I could put it on the fob that goes with that. I am also concerned about keeping costs low, so the LED's may be an extraneous cost for this project. I just had in mind a power switch, and then a switch or knob to control how long the fan stays on. I have a few ideas rolling around in my head, so the charlieplexing will get used sooner than later. Still no thoughts on the code? Is it right? Is it complete?
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
Interesting idea with the ICSP strip. I have a Willem programmer that I have been planning on using, and can't really afford to branch out for the moment, but it's something to think about nonetheless. Is it a good idea to have just in case I want to do some reprogramming?
It's better to have and not need it, than to need it and not have. You don't even have to solder in the header strip; just as long as in case you need that functionality, you have it. If you later decide to go with something like a PICkit-2 or PICkit-3, the transition will be relatively painless.

Or better yet, is it something I should be doing and just nix the Willem programmer?
I have not used a Willem. It may or may not work for you. Hopefully it will.

I also like the wider traces. Seems like it'll make for a longer life for the project once it's built.
You're usually better off with wider traces.

The Charlieplexing idea is a cool one, mostly because I love anything that concerns maximizing efficiency, and also because I have never built one. It may be superfluous given that I think I just want to go with variable times for the fan to be on, and not variable speeds.
I don't know for what reason the fan will serve; however it might be worthwhile to look at controlling the fan speed according to temperature rather than an absolute time or speed.

I am planning on making a remote starter for my car, so I am thinking I could put it on the fob that goes with that.
I'll strongly advise you to abandon ideas of automotive projects; there are far too many things that can go wrong.

I am also concerned about keeping costs low, so the LED's may be an extraneous cost for this project.
LEDs can be purchased very cheaply. Two tactile switches and a row of LEDs would be far less costly than a single rotary switch.
I just had in mind a power switch, and then a switch or knob to control how long the fan stays on. I have a few ideas rolling around in my head, so the charlieplexing will get used sooner than later.

Still no thoughts on the code? Is it right? Is it complete?
I don't know what this project is going to be used for.

One item that's been overlooked thus far is; how will the battery be turned off? The regulator and microcontroller will be a constant drain on the power supply until it is turned off. We don't know what the endgame is here; what is supposed to happen when the time runs out?

There is not a way to start the timer running at the moment.

There is no way that the uC can turn off the input power. If you are powering it from a battery, you will be buying a new battery pretty frequently.
 

Thread Starter

jameschristian

Joined Nov 24, 2011
58
I'll strongly advise you to abandon ideas of automotive projects; there are far too many things that can go wrong.
Ok, so no go on the car starter. It was just a thought, and having taken smoe automotive courses, I agree that there are a lot of things that come into play that may go wrong, so I will just put that idea aside.

There is not a way to start the timer running at the moment.
To start the timer, I am thinking that I will just have it read the Vcc input pin, and if it's high, have it start. I have some more code to write there.

LEDs can be purchased very cheaply. Two tactile switches and a row of LEDs would be far less costly than a single rotary switch.

I see what you are saying with the LED's and the tactile switches. I am all for using them. I will work on the design some today and upload what I come up with.

I don't know for what reason the fan will serve; however it might be worthwhile to look at controlling the fan speed according to temperature rather than an absolute time or speed.

The end design is supposed to be a fan that will air out a musty space. It just needs to come on for a short time, and then cycle down, then come on again after a while and then cycle down and repeat that process foour or five times.

I have not updated the code to reflect a recent design change, in that the down time needs to be an hour, then two hours, then eight hours, but it's not too hard to put a delay loop in there to that effect.


One item that's been overlooked thus far is; how will the battery be turned off? The regulator and microcontroller will be a constant drain on the power supply until it is turned off. We don't know what the endgame is here; what is supposed to happen when the time runs out?

Are you saying the μC cannot power itself down or that the current code doesn't have that ability built in? If it cannot do so, is there an analog way to incorporate that ability into the circuit? It seems like it can be done, what if I just set all the pins to float during the down time? Would that disengage the PIC? Because you're right, the battery would get eaten pretty quickly that way, and I certainly don't want that. What is the term for a three way toggle switch, so I can look up the part in the library? I will be working on this today and put something up by tonight.
 

SgtWookie

Joined Jul 17, 2007
22,230
Ok, so no go on the car starter. It was just a thought, and having taken some automotive courses, I agree that there are a lot of things that come into play that may go wrong, so I will just put that idea aside.
OK, good. Even professional automotive engineers make mistakes that aren't caught during the testing phases, and those mistakes routinely cost people's lives, and the auto manufacturers untold millions of dollars.

To start the timer, I am thinking that I will just have it read the Vcc input pin, and if it's high, have it start. I have some more code to write there.
Well, so it seems you will need a RESET button as well as the rotary switch - either that, or you will need to use an interrupt to re-set the timer when the rotary switch position is changed.

You'll also need to physically limit the switch travel somehow so that a non-monitored switch position cannot be selected.

I see what you are saying with the LED's and the tactile switches. I am all for using them. I will work on the design some today and upload what I come up with.
Tactile switches are very, very cheap, and quite reliable if you don't ask them to switch very much current.

Also, with the LEDs - you wouldn't necessarily have to have a whole row of them; just flash out a code to indicate what the time setting is.

You could use two switches to increase/decrease the time, and another to cycle back and fourth between ON time and OFF time.

The end design is supposed to be a fan that will air out a musty space. It just needs to come on for a short time, and then cycle down, then come on again after a while and then cycle down and repeat that process four or five times.
Since you're driving a fan, I suggest that you consider using some AA batteries instead of 9v "transistor" batteries. AA batteries will last far longer.

You will also need some way to indicate that the batteries need to be charged/replaced.

I have not updated the code to reflect a recent design change, in that the down time needs to be an hour, then two hours, then eight hours, but it's not too hard to put a delay loop in there to that effect.
Simple to do.

Are you saying the μC cannot power itself down or that the current code doesn't have that ability built in?
Well, you don't have the code implemented yet. Can't remember which flavor of C you're using, but there are a few different ways that a uC can reduce power consumption; decrease the clock speed (if using the internal clock; but you are using an xtal), take a short nap, or go to sleep.

However, the LM78L05 will still be drawing current; around 5mA as idle current. That may not seem like much, but it will eventually drain your battery.

If it cannot do so, is there an analog way to incorporate that ability into the circuit? It seems like it can be done, what if I just set all the pins to float during the down time? Would that disengage the PIC? Because you're right, the battery would get eaten pretty quickly that way, and I certainly don't want that.
That's right.

If you want the PIC to turn completely off after going through several cycles of fan on/fan off, you might use a regulator that has a shutdown function instead of the LM78L05.

What is the term for a three way toggle switch, so I can look up the part in the library? I will be working on this today and put something up by tonight.
A SPDT (single pole, double throw) toggle switch might be what you are looking for. Have a look in switch.lbr - there are a number of switches in other libraries.

Try clicking the "add component" icon, and then in the text box, put in *SWITCH* and it will show you everything that has Switch in the description field.
 

Thread Starter

jameschristian

Joined Nov 24, 2011
58
Ok, so, I went in and used four push switches instead, each to designate the different times the fan will be on, but in the process of converting to the board file some of the connections to switch 4 were lost. Any idea why? I also charlieplexed four LED's and connected them so that I can have them come on for a short time and then turn off so as to save battery life. I stayed with the nine volt battery connector, not because I don't want to go with the 2 AA's as was recommended, but but because I didn't know what connector to go with (after searching through my libraries and not finding a AA battery connector of any kind). There appear to be some connections going on with the switches that were unintended as well, though I couldn't see any actual connections on the schematic. Any thoughts there? I will be out of town this weekend but will be writing code while on vacation to accommodate this new design. Any and all thoughts are appreciated. Happy holidays!
 

Thread Starter

jameschristian

Joined Nov 24, 2011
58
Also I didn't add in a way to indicate when to recharge the batteries because of aforementioned lack of connector, but what would I use to do that?
 

SgtWookie

Joined Jul 17, 2007
22,230
Ok, so, I went in and used four push switches instead
You used slide-action SPDT switches instead of tactile switches.
Tactile switches are smaller and much less expensive. Use the uC internal pull-ups to Vdd, and have the tactile switches short the I/O pin to ground.
..., each to designate the different times the fan will be on
Expound on how you plan to do that.

..., but in the process of converting to the board file some of the connections to switch 4 were lost. Any idea why?
You "missed" when you tried to connect the switch to the wires. You have to hit the ends of the wires or pins exactly. You had overlapping pins.

If you had performed an Erc, you would have found those errors.
Erc can be performed by clicking on the Erc icon; in the schematic editor it is the bottom left icon on the left menu bar.

I also charlieplexed four LED's
You need to use resistors in series with the LEDs. Use one per uC pin connected to the LEDs.
and connected them so that I can have them come on for a short time and then turn off so as to save battery life.
That's fine.
I stayed with the nine volt battery connector, not because I don't want to go with the 2 AA's as was recommended, but but because I didn't know what connector to go with (after searching through my libraries and not finding a AA battery connector of any kind).
You can use a couple of wirepads, and connect up a battery holder like you can get from Radio Shack using wires, or perhaps a plug/jack.
There appear to be some connections going on with the switches that were unintended as well, though I couldn't see any actual connections on the schematic. Any thoughts there? I will be out of town this weekend but will be writing code while on vacation to accommodate this new design. Any and all thoughts are appreciated. Happy holidays!
Happy holidays yourself. :)

Try out the ERC function, and fix the errors. You need to place junctions where more than 2 wires meet. Don't worry about items not having a value. Once you get down to just "No pins on N$xx" and the no names complaints, save and exit Eagle. The "No pins on N$xx" won't be there next time you open the schematic.

Then go
 

SgtWookie

Joined Jul 17, 2007
22,230
I've edited your schematic & board; replaced the slide SPDT switches with tactile switches (from the Omron switch library), swapped out the side-facing LEDs with common 5mm LEDs, added three resistors to limit LED current (values TBD), rearranged the board and routed it.
 

Attachments

Thread Starter

jameschristian

Joined Nov 24, 2011
58
The redesign looks amazing! Thanks for the help, Sarge. I am leaving tomorrow for the mountains and will work up the code in my free time...
 

Thread Starter

jameschristian

Joined Nov 24, 2011
58
Here for your review is my updated code. Still am not sure if configuration files are necessary. In fact, still not sure what configuration files are for...

Rich (BB code):
#include <pic.h>
#include <delay>
#include<iostream>


TRISA=0
PORTB1=0		// LED charlieplex
PORTB2=0		// "
PORTB3=0		// "
PORTB4=1		// switch 4
PORTB5=1		// switch 3
PORTB6=1		// switch 2
PORTB7=1		// switch 1


delay_sec(int sec)


void main();
{
	while (1);
	{
		for (int x, x<=4, x++);
		{
			if (output_high(pin_B7));	//switch 1, on 1 minute
			{
				output_high(pin_A1);
				delay_sec(59);			// delay -1 second for LED flash
				output_low(pin_A1);
				output_high(pin_B3)		// LED 1 on via charlieplexing
				output_low(pin_B2)
				delay_ms(333)
				output_low(pin_B3)		// LED 1 off
				delay_ms(333)
				output_high(pin_B3)
				delay_ms(334)
				output_low(pin_B3)
			}
			if (output_high(pin_B8));	// switch 2, on 2 min's
			{
				output_high(pin_A1);
				delay_sec(119);			// 2 min delay -1 second for LED flash
				output_low(pin_A1);
				output_high(pin_B2)
				output_low(pin_B3)
				delay_ms(333)			// LED 2 on
				output_low(pin_B2)		// LED 2 off
				delay_ms(333)
				output_high(pin_B2)
				delay_ms(334)
				output_low(pin_B2)
			}
			if (output_high(pin_B9));	// switch 3, on 5 min's
			{
				output_high(pin_A1);
				delay_sec(299);			// fan on 5 min's -1 second for LED flash
				output_low(pin_A1);
				output_high(pin_B2)
				output_low(pin_B1)
				delay_ms(333)			// LED 3 on
				output_low(pin_B2)
				delay_ms(333)			// LED 3 off
				output_high(pin_B2)
				delay_ms(334)			// LED 3 on
				output_low(pin_B2)		// LED 3 off
			}
			if (output_high(pin_B10));	//switch 4, on for good, LED on for 4 seconds
			{
				output_high(pin_A1);
				output_high(pin_B1)
				output_low(pin_B2)		// LED 4 on for four seconds
				delay_ms(4000)
				output_low(pin_B1)		// LED off
			}

			return()
		}	
	}
}


void delay_sec(int secs)  // function to enable use of seconds via 'delay_ms'
{
   for(int ms=0;ms<secs;ms++)
   {
      delay_ms(1000);      // delay 1 second
 

SgtWookie

Joined Jul 17, 2007
22,230
You know, you're going to have to use interrupts or else you'll sit there waiting for what seems like forever for the uC to react to you pushing buttons.

The buttons are on RB4-RB7. You should have weak pull-ups enabled, and you need to detect when any of those four pins change to zero. Then you need to react right away, and acknowledge that the command was received. Otherwise, the human will get frustrated, impatient, and wind up taking a sledgehammer to the blasted thing.
 

Thread Starter

jameschristian

Joined Nov 24, 2011
58
Got a book from the library and read up on configuration words. Can't really find anything definite on this chip on getting them written correctly but haven't dug very far yet. I may just try a bunch of permutations until one works. I noticed a difference between the code Nerdegutta posted earlier and the datasheet on this chip, being that this chip has a 0/1 logic for each configuration word, and I am not sure of the correct syntax to get the word to register a 1 or a 0. I just went with the configuration word and then a "=0" or "=1" because it seemed logical. We'll see if it compiles :) I also considered what the Sarge said re: timing of the LED's and the user waiting for them to flash, and just figured I'd rework the code so that the timing for the fan happens after the LED's flash, and then factor in the timing to make the fan turn on for exactly one minute, two minutes, etc. I also edited the code to reflect the correct button position.

I'm looking forward to getting some more reading done, and finishing up this project so I can get to work on my next one, so I'll be compiling and testing this code in a simulator later this week and will post results.

Rich (BB code):
#include <pic.h>
#include <delay>


 __config ( _XT_OSC & _WDT_OFF & _PWRTE _ON & _CP_OFF);

TRISA=0;

TRISB1=0;	        // LED charlieplex
TRISB2=0;		// "
TRISB3=0;		// "
TRISB4=1;		// switch 4
TRISB5=1;		// switch 3
TRISB6=1;		// switch 2
TRISB7=1;		// switch 1


delay_sec(int sec)


void main();
{
	while (1);
		{
			if (RB4=1);	//switch 1, on 1 minute
			{
				RA1=1;
				RB3=1;		// LED 1 on via charlieplexing
				RB2=0;
				delay_ms(200);
				RB3=0;		// LED 1 off
				delay_ms(200);
				RB3=1;
				delay_ms(200);
				RB3=0;
				delay_sec(59.4);		// delay -1 second for LED flash
				RA1=0;
				
			}
			if (RB5=1);                   	// switch 2, on 2 min's
			{
				RA1=1;
				RB2=1;
				RB3=0;
				delay_ms(200);			// LED 2 on
				RB2=0;		                // LED 2 off
				delay_ms(200);
				RB2=1;
				delay_ms(200);
				RB2=0;
				delay_sec(119.4);		// 2 min delay -1 second for LED flash
				RA1=0;
				)
			}
			if (RB6=1);	// switch 3, on 5 min's
			{
				RA1=1;
				RB2=1;
				RB1=0;
				delay_ms(200);			// LED 3 on
				RB2=0;
				delay_ms(200);			// LED 3 off
				RB2=1;
				delay_ms(200);			// LED 3 on
				RB2=0;
				delay_sec(299.4);		// fan on 5 min's -1 second for LED flash
				RA1=0;		// LED 3 off
			}
			if (RB7=1);	//switch 4, on for good, LED on for 4 seconds
			{
				RA1=1;
				RB1=1;
				RB2=0;		// LED 4 on for four seconds
				delay_ms(4000);
				RB1=0;		// LED off
			}

			return()	
	}
}


void delay_sec(int secs)  // function to enable use of seconds via 'delay_ms'
{
   for(int ms=0;ms<secs;ms++)
   {
      delay_ms(1000);      // delay 1 second

Any thoughts?
 
Last edited:

Thread Starter

jameschristian

Joined Nov 24, 2011
58
Also thinking about going with a different (read: more modern) chip. Any thoughts on which one I should use? Something with similar outputs and inputs would be great. I figure that way I can use the more modern config words. I hope everyone had/is having a happy holiday season. Grandma said to say hello :).
 

Thread Starter

jameschristian

Joined Nov 24, 2011
58
Tried to compile my program and no dice. The configuration words were not recognized by the default header file. I am using the Microsoft Visual C++ compiler Express 2010 if that matters. Does anyone know where to find the pic.h header file for the PIC16f84A chip? Thanks in advance!
 
Top