Chip with simple program for Toy

Pooh Bear wrote:
ehsjr wrote:


John Woodgate wrote:

I read in sci.electronics.design that ehsjr
ehsjr@bellatlantic.net
wrote (in <ggEXe.6619$i86.6486@trndny01>) about 'How to detect
power
cutout for PC?', on Mon, 19 Sep 2005:


Here's a circuit that adds delay. You add
1 part - C1 a large electrolytic capacitor.

12 volt
DC relay
------ -----
| (||) |---+---| / |---+
--| (||) | |+ ----- |
--| (||) | [C1] |
| (||) | | |
| (||) |---+-------------+
------


This is DANGEROUS RUBBISH. YOU HAVE AN ELECTROLYTIC CAPACITOR
CONNECTED
TO A LOW-IMPEDANCE AC SUPPLY. IT WILL EXPLODE, LATER IF NOT SOONER.

You must have missed the earlier post. This post showed
only the addition of the cap.

Ed


Which won't do any good anyway !

Do you like being led by the blind ( and stupid ) ?

Graham



Thanks for the assessment. Now, as to the
cap, why won't it do any good?

Ed
 
"petrus bitbyter" <pieterkraltlaatditweg@enditookhccnet.nl> schreef in
bericht news:432f397e$0$154$3a628fcd@reader2.nntp.hccnet.nl...
"Alexander" <electricdummy@hotmail.com> schreef in bericht
news:dgmm81$f2f$1@news1.zwoll1.ov.home.nl...

"John Fields" <jfields@austininstruments.com> schreef in bericht
news:dh7ti15gi1i9ll5d9kmbrgvbbnsljbpejb@4ax.com...
On Sun, 18 Sep 2005 23:22:03 +0200, "petrus bitbyter"
pieterkraltlaatditweg@enditookhccnet.nl> wrote:


Once you have a 555 clock running you can hook up an old CD4013B like
drawn
below. This type of components runs on power supplies from 3 to 20V. Of
course you have at least one problem left as these type of components
can
sink only a few mA of current. So your LEDs will be pretty dim or you
have
to use high efficiency LEDs. The series resistors can also be much lower
then calculated as the outputs have an internal resistor inside. The
best
thing you can do is using an extra IC, a CD4050B. This one contains six
buffers which are able to sink enough current to drive a LED.


Vcc 3-20V +-----+-----+-----+-----
| | | |
.-. .-. .-. .-.
| | | | | | | |
| | | | | | | |
'-' '-' '-' '-'
| | | |
| | | |
V V V V
- - - -
| | | |
| | | |
| +--------+ |
| | | |
| | +--------------+
.----. | | .---- | |
+-----|D0 Q|---+--|-----|D1 Q|---+ |
| | _| | | _| |
| +--|> Q|o-----+ +--|> Q|o-----+
| | '----' | '----' |
| | CD4013B(a) | CD4013B(b) |
Clock | | | |
----------+-----------------+ |
| |
+-----------------------------------+

---
Ah, yes... the quadrature encoder! Good one! It didn't even cross
my mind. I must be slipping...


--
John Fields
Professional Circuit Designer

And You call yourself a Professional Circuit Designer???
Ok, most of the time we have solutions that are not suitable for a
beginner (PIC 10F series?).

Alexander
A.C.E. (Applied Communications Engineer)


So why shouldn't he call himself a Professional Circuit Designer? He often
contributes circuits in the electronics newsgroups.

PIC10F2xx will be suitable for fixed frequency. I'd go for a 12F675
because
there's no need for extra components but one potentiometer for the
variable
frequency that was asked for.

The point is however that the OP seems to have hardly any skills in
electronics so I doubt whether he can reed the schematics we provided.
That's not to blame the OP. After all this is a "basics" group so he put a
good question on the right place. But that's also why I try to keep it as
simple as possible and leave it to the OP to ask further if he needs to.

petrus bitbyter
Exactly some people take to soon a PIC, GAL, FPGA or any other device. Most
of the times this are more experienced people who need a flexible design or
know that in the future the design could get more functions.
I had a simple design, when it was finished and in production for half a
year, the customer wanted a redesign with a lot more functions. All it took
was 2 days of programming and debugging. The PCB didn't change although the
customer thought it did ;).

Alexander
 
On Tue, 20 Sep 2005 21:51:08 +0200, "Alexander"
<electricdummy@hotmail.com> wrote:


Exactly some people take to soon a PIC, GAL, FPGA or any other device. Most
of the times this are more experienced people who need a flexible design or
know that in the future the design could get more functions.
I had a simple design, when it was finished and in production for half a
year, the customer wanted a redesign with a lot more functions.
---
Had you known what you were doing and optimized your customer's
requirements in the first place, the second effort would not have
been necessary. However, since two extra days' worth of programming
and debugging were needed because of your stupidity and your
client's inability to sort it all out, you got a nice fat check. No?


--
John Fields
Professional Circuit Designer
 
Terry Pinnell wrote:
Agreed. I could probably have made a movie of it in the time it would
take a PIC-er to just get started! Here it is:
http://www.terrypin.dial.pipex.com/Images/LED-Sequencer4MB.wmv
thanks for this great freakin link!!!!

mk5000

"...aside from uknova.com. Anyone know any good ones?
While uknova is a good site for certain shows, I find that you usually
get zero response to requests for stuff not already torrented. The
fact that the mods don't allow you to bump your requests on the forum
doesn't help either, as the volume of traffic means that your post
soon drops off the page... "-- a single locust
 
On Tue, 20 Sep 2005 17:15:02 +0000, Terry Pinnell wrote:

ehsjr <ehsjr@bellatlantic.net> wrote:


It was another damn "use a PIC" post. Some of these posters drive
me crazy. Never a "Wow John, you sure put a lot of work into that,
nice job!" Never a complete project, with a schematic and source
code. Just "you could use a PIC". Hell, if you did what those
pic-ophiles do, your posts would say "use a soldering iron."
One thing's for sure - we can't criticize the PIC designs posted as
solutions to requests from posters. I'll tell you this, I'll put
any one of the solutions you've offered in the newsgroup against
all of the posted "PIC solutions", combined. Your solutions are
always great. Theirs are non-existant.

Agreed. I could probably have made a movie of it in the time it would
take a PIC-er to just get started! Here it is:
http://www.terrypin.dial.pipex.com/Images/LED-Sequencer4MB.wmv
This took 5 minutes to code (adapted another project). 15 if you include
the setup, programming, testing, and bugfix (I inadvertently forgot to
call init(), and it didn't work the first time). Only one chip, a pot, 5
resistors, and 4 leds. Sadly, I don't have a movie camera, or I would
record it. This is compiled with the free 'hitech lite' C compiler, and is
downloaded to a pickit 1 using lawlor's usb_pickit for linux.

The PIC12F675 is an 8 pin uC, which supports ADC, timer interrupts, and
such. Pin 7 is used as the ADC input, so changing the voltage changes the
rate of change of the display, from once every 2 seconds to as fast as it
can go. The period is about Vin/Vcc * 2048 for Vin > 0.

Pin 6, 5, 3, and 2 are A, B, C, and D. Pin 4 is the reset, pin 1 is Vcc,
and pin 8 is GND. A-D can source up to 20mA, so a 1k resistor between it
and the LED limits current to about 3.5mA.

(for the curious, it uses a 1ms interrupt to do delays. The result of
the high byte of the AD is between 0 and 255. Thus 8 * AD is from 0 to
2040, and just delaying that number of ms interrupts provides the ability
to change the period from fast to slow)

BTW, I'm sure we all appreciate JF's and Terry's efforts to help people
out. I wish everybody's posted circuits were as well thought out, tested,
and nicely presented as the ones they post.

Regards

---------------------------------------------------------------------------
#include <pic.h>

__CONFIG(UNPROTECT & BORDIS & MCLREN & PWRTDIS & WDTDIS & INTIO);

unsigned int g_ticks; /* Ticks since startup */

#define TICKS_PER_SECOND 1000

#define LED_A GPIO1
#define LED_B GPIO2
#define LED_C GPIO4
#define LED_D GPIO5

void init_gpio(void)
{
GPIO = 0;
}

void init_tmr0(void)
{
/* prescaler is 1:4, GPIO pullups are disabled */
OPTION = 0x81;
}

void init_tmr1(void)
{
T1CON = 0; /* Disabled */
}

void init_comparator(void)
{
CMCON = 0x7; /* Turn off the comparator */
VRCON = 0x0;
}

void init_a2d(void)
{
ANSEL = 0x11; /* Fosc/8 and RA0 is analog */
ADCON0=0x00; // Left justify output
ADON=1; // turn on the A2D conversion module
}

void init_ee()
{
}

void init_interrupts(void)
{
INTCON = 0xA0;
}

void init(void)
{
OSCCAL = _READ_OSCCAL_DATA();

TRISIO = 0x01; /* RA0 is ad input, rest are outputs */

init_gpio();
init_tmr0();
init_tmr1();
init_comparator();
init_a2d();
init_interrupts();
}

unsigned int get_voltage (void)
{
GODONE=1; /* initiate conversion */

while(GODONE) /* wait for result */
{
continue;
}

return ADRESH;
}

void wait_ms(unsigned int x)
{
unsigned int temp = g_ticks + x;
while (temp != g_ticks);
}

void main(void)
{
int state = 0;

init();

LED_A = 1;
LED_B = 1;
LED_C = 0;
LED_D = 0;

for (;;)
{
unsigned int ms_to_wait = get_voltage() * 8;

wait_ms(ms_to_wait);
switch(state)
{
case 0:
LED_A = 0;
LED_C = 1;
state++;
break;

case 1:
LED_B = 0;
LED_D = 1;
state++;
break;

case 2:
LED_C = 0;
LED_A = 1;
state++;
break;

case 3:
LED_D = 0;
LED_B = 1;
state = 0;
break;
}
}
}

static void interrupt isr(void)
{
T0IF = 0;
TMR0 = 6;

g_ticks++;
}
 
I read in sci.electronics.design that ehsjr <ehsjr@bellatlantic.net>
wrote (in <yU3Ye.8551$T55.8172@trndny06>) about 'How to detect power
cutout for PC?', on Wed, 21 Sep 2005:
He said:
"Shoving a cap across even a DC output won't result in a
noticeable time delay!"
Will it?
--
Regards, John Woodgate, OOO - Own Opinions Only.
If everything has been designed, a god designed evolution by natural selection.
http://www.jmwa.demon.co.uk Also see http://www.isce.org.uk
 
On Tue, 20 Sep 2005 17:06:27 -0500, John Fields
<jfields@austininstruments.com> wrote:

On Tue, 20 Sep 2005 21:51:08 +0200, "Alexander"
electricdummy@hotmail.com> wrote:


Exactly some people take to soon a PIC, GAL, FPGA or any other device. Most
of the times this are more experienced people who need a flexible design or
know that in the future the design could get more functions.
I had a simple design, when it was finished and in production for half a
year, the customer wanted a redesign with a lot more functions.

---
Had you known what you were doing and optimized your customer's
requirements in the first place, the second effort would not have
been necessary. However, since two extra days' worth of programming
and debugging were needed because of your stupidity and your
client's inability to sort it all out, you got a nice fat check. No?
---
Sorry, that was uncalled for.

--
John Fields
Professional Circuit Designer
 
"John Fields" <jfields@austininstruments.com> schreef in bericht
news:lrn2j1tcfufkitajc8vu8otim25vv1rbg8@4ax.com...
On Tue, 20 Sep 2005 17:06:27 -0500, John Fields
jfields@austininstruments.com> wrote:

On Tue, 20 Sep 2005 21:51:08 +0200, "Alexander"
electricdummy@hotmail.com> wrote:


Exactly some people take to soon a PIC, GAL, FPGA or any other device.
Most
of the times this are more experienced people who need a flexible design
or
know that in the future the design could get more functions.
I had a simple design, when it was finished and in production for half a
year, the customer wanted a redesign with a lot more functions.

---
Had you known what you were doing and optimized your customer's
requirements in the first place, the second effort would not have
been necessary. However, since two extra days' worth of programming
and debugging were needed because of your stupidity and your
client's inability to sort it all out, you got a nice fat check. No?

---
Sorry, that was uncalled for.

--
John Fields
Professional Circuit Designer
So was my remark several post ago.

The fact was that I anticipated the client's inablity to know what he
wanted.
So I build it the way I could easily adapt it for his future needs.

As A mattor of Facts I suggested the sings he later wanted in the first
place, but NO way listen!

And Yes there was a nice fat check!!!

Alexander
 
ehsjr wrote:

The addition of the cap adds a delay
No it doesn't.

that is useful to
ignore power "blips", and the circuit is within the
restriction of "newbie trying to find my way". So saying
"it won't do any good anyway" makes one wonder what
that other poster had in mind. As it turns out, that poster
seems not to understand what adding the cap does.
Funny that !

I've designed more power supplies than you could shake a stick at.

He said:
"Shoving a cap across even a DC output won't result in a
noticeable time delay!"
Indeed it won't.

It simply makes the reservoir cap bigger and reduces ripple.

To make a delay you need an *RC* network !

You don't seem equipped even to understand the very basics of electricity.

Graham
 
On Fri, 23 Sep 2005 21:27:29 +1200, Jasen Betts wrote:

Now, if you really insist on letting a cap discharge, just amplify
it. :) Use a MOSFET, although you'd probably want to use another
transistor for a little positive feedback so you'd get a snap
action - I don't know if you'd want your MOSFET to be in the linear
region for 2-3 minutes. :)

yeah, but whay are you going to power the relay with, another plugpack
plugged into the UPS ?
No. The plugpoack powers the relay while there's mains. When the
mains drop out, the cap. provides - - - Oh, wait. Not with an
amplified cap. How about the UPS battery?

back to the original design something can probably be done using an
optocoupler instead of a plugpack and relay, but a home made a cable
with a mains plug on one end and a serial plug on the other might get
some strange looks....

hmm, what's the best way to power the LED in an optocoupley from the mains,
a big honking resistor or something more subtle?

C1
|| ___
L--[680R]--||---~ /\ ~
|| / \
250v +--<->|->---+-----+
50Hz | \ / _L_ |
N-------------(--_ \/ ~T~ \ / LED
| ~~ ~ |10u ~T~ (in opttocoupler)
+-----------+-----+


now for C1

hmm 730V swing 100 times per second wanting to pass 10mA or slightly more

0.01/(730x100) = 0.139 uf rated for 250VAC

I can get 200nF seems to be a standard size

the 680 ohm resistor is there to stop the power-on surge (if ppower comes
on at one of the peaks of the AC cycle) from destroying the diodes in the
bridge... probably should be rated for 400V but only needs to be a 1/4
watt part...

the bridge needs only to be rated for 500ma and 5v1

maybe a fuse would be a good idea too, eg, 250AC 100ma

comments anyone?
1, Lose the cap in parallel with the LED
2. A bridge is overkill - put a 1N4004 or another LED in antiparallel
with the LED.
3. Remember, I = C * dV/dt. You need enough series resistance so that
if you plug it in at the line peak, it will limit the current to
something less than the LEDs' peak rating.

And a fuse never hurts. :)

Cheers!
Rich
 
"Bob Monsen" <rcsurname@comcast.net> wrote in message
news:pan.2005.09.20.22.58.43.448485@comcast.net...
On Tue, 20 Sep 2005 17:15:02 +0000, Terry Pinnell wrote:

ehsjr <ehsjr@bellatlantic.net> wrote:


It was another damn "use a PIC" post. Some of these posters drive
me crazy. Never a "Wow John, you sure put a lot of work into that,
nice job!" Never a complete project, with a schematic and source
code. Just "you could use a PIC". Hell, if you did what those
pic-ophiles do, your posts would say "use a soldering iron."
One thing's for sure - we can't criticize the PIC designs posted as
solutions to requests from posters. I'll tell you this, I'll put
any one of the solutions you've offered in the newsgroup against
all of the posted "PIC solutions", combined. Your solutions are
always great. Theirs are non-existant.

Agreed. I could probably have made a movie of it in the time it would
take a PIC-er to just get started! Here it is:
http://www.terrypin.dial.pipex.com/Images/LED-Sequencer4MB.wmv

This took 5 minutes to code (adapted another project). 15 if you include
the setup, programming, testing, and bugfix (I inadvertently forgot to
call init(), and it didn't work the first time). Only one chip, a pot, 5
resistors, and 4 leds. Sadly, I don't have a movie camera, or I would
record it. This is compiled with the free 'hitech lite' C compiler, and is
downloaded to a pickit 1 using lawlor's usb_pickit for linux.

The PIC12F675 is an 8 pin uC, which supports ADC, timer interrupts, and
such. Pin 7 is used as the ADC input, so changing the voltage changes the
rate of change of the display, from once every 2 seconds to as fast as it
can go. The period is about Vin/Vcc * 2048 for Vin > 0.

Pin 6, 5, 3, and 2 are A, B, C, and D. Pin 4 is the reset, pin 1 is Vcc,
and pin 8 is GND. A-D can source up to 20mA, so a 1k resistor between it
and the LED limits current to about 3.5mA.

(for the curious, it uses a 1ms interrupt to do delays. The result of
the high byte of the AD is between 0 and 255. Thus 8 * AD is from 0 to
2040, and just delaying that number of ms interrupts provides the ability
to change the period from fast to slow)

BTW, I'm sure we all appreciate JF's and Terry's efforts to help people
out. I wish everybody's posted circuits were as well thought out, tested,
and nicely presented as the ones they post.

Regards

---------------------------------------------------------------------------
#include <pic.h

__CONFIG(UNPROTECT & BORDIS & MCLREN & PWRTDIS & WDTDIS & INTIO);

unsigned int g_ticks; /* Ticks since startup */

#define TICKS_PER_SECOND 1000

#define LED_A GPIO1
#define LED_B GPIO2
#define LED_C GPIO4
#define LED_D GPIO5

void init_gpio(void)
{
GPIO = 0;
}

void init_tmr0(void)
{
/* prescaler is 1:4, GPIO pullups are disabled */
OPTION = 0x81;
}

void init_tmr1(void)
{
T1CON = 0; /* Disabled */
}

void init_comparator(void)
{
CMCON = 0x7; /* Turn off the comparator */
VRCON = 0x0;
}

void init_a2d(void)
{
ANSEL = 0x11; /* Fosc/8 and RA0 is analog */
ADCON0=0x00; // Left justify output
ADON=1; // turn on the A2D conversion module
}

void init_ee()
{
}

void init_interrupts(void)
{
INTCON = 0xA0;
}

void init(void)
{
OSCCAL = _READ_OSCCAL_DATA();

TRISIO = 0x01; /* RA0 is ad input, rest are outputs */

init_gpio();
init_tmr0();
init_tmr1();
init_comparator();
init_a2d();
init_interrupts();
}

unsigned int get_voltage (void)
{
GODONE=1; /* initiate conversion */

while(GODONE) /* wait for result */
{
continue;
}

return ADRESH;
}

void wait_ms(unsigned int x)
{
unsigned int temp = g_ticks + x;
while (temp != g_ticks);
}

void main(void)
{
int state = 0;

init();

LED_A = 1;
LED_B = 1;
LED_C = 0;
LED_D = 0;

for (;;)
{
unsigned int ms_to_wait = get_voltage() * 8;

wait_ms(ms_to_wait);
switch(state)
{
case 0:
LED_A = 0;
LED_C = 1;
state++;
break;

case 1:
LED_B = 0;
LED_D = 1;
state++;
break;

case 2:
LED_C = 0;
LED_A = 1;
state++;
break;

case 3:
LED_D = 0;
LED_B = 1;
state = 0;
break;
}
}
}

static void interrupt isr(void)
{
T0IF = 0;
TMR0 = 6;

g_ticks++;
}
What program lang did you use It looks like C to me or is it Basic?

Eric
 
Jasen Betts wrote:
Now, if you really insist on letting a cap discharge, just amplify
it. :) Use a MOSFET, although you'd probably want to use another
transistor for a little positive feedback so you'd get a snap
action - I don't know if you'd want your MOSFET to be in the linear
region for 2-3 minutes. :)


yeah, but whay are you going to power the relay with, another plugpack
plugged into the UPS ?
Yes - there's a diagram of that in a previous reply.
The idea is to keep it as simple and safe as possible per the
OP's self-described lack of familiarity with electronics.
Thus the plugpacks.

For someone experienced, it would be best to do everything
inside the UPS. It already senses when mains power drops, and
has a nice source of DC. Plenty of room to add whatever circuit
is desired - comparator based, timer, relay, your opto circuit,
whatever. It's a no-brainer.

Ed

<snip>
 
On Sat, 24 Sep 2005 13:27:44 +0000, eric wrote:

What program lang did you use It looks like C to me or is it Basic?

Eric
It is C. There is a free compiler available from http://www.htsoft.com/
which works for pic 12 and 16 series chips.
 
On 2005-09-23, Rich Grise <rich@example.net> wrote:
On Fri, 23 Sep 2005 21:27:29 +1200, Jasen Betts wrote:

hmm, what's the best way to power the LED in an optocoupley from the mains,
a big honking resistor or something more subtle?

C1
|| ___
L--[680R]--||---~ /\ ~
|| / \
250v +--<->|->---+-----+
50Hz | \ / _L_ |
N-------------(--_ \/ ~T~ \ / LED
| ~~ ~ |10u ~T~ (in opttocoupler)
+-----------+-----+


now for C1

1, Lose the cap in parallel with the LED
2. A bridge is overkill - put a 1N4004 or another LED in antiparallel
with the LED.
why do I need a diode witth a 400V breakdown voltage?

3. Remember, I = C * dV/dt. You need enough series resistance so that
if you plug it in at the line peak, it will limit the current to
something less than the LEDs' peak rating.
If I do that I may as well lose the other cap too as the resistor will
be dropping most of the voltage. also an 1N914 is rated for 100ma and
50v (or better) so that'd be enough antiparallel.

ok worst case is cap reverse charged so that's 350V from the mains and
350 from the cap = 700V, to get that below the 50mA maximum for the LED
in the 4N28 optocoupler i'd need a 14K resistor, call it 15K,5%

at 15mA RMS (ideal current for the optocoupler LED) that resistor is
going to drop 225V, so we don't need the capacitor...

L // LED
----[15K]---+->|-+
| |
230V +-|<-+
AC 1N914 |
|
-----------------+
N

the only problem is 230V*15mA=3.5 Watts, which could be inconvenient.

in the original circuit the parallel cap was to absorb is absorb the
inrush and to stabilise the ouput so it doesn't switch with every
half-cycle. so it can conveniently interface directly with a PC
for deteccting the presence of mains voltaage
the 680R is to limit the inrush to save the rectifier
resistors.

And a fuse never hurts. :)
capacitor voltage reducer
mains current detecctor mark 2

400nF
fuse 250VAC
100mA250V || 1N4001
L---o-_-~-o--[680R]--+---||---+-->|--+-[100R]-+
250V | || | | |
50Hz | | _L_ \|/
+-[2M2]--+ ~T~ ~T~ LED
| |200uF | (in opttocoupler)
+--|<--+ |
1N4001| |
N --+--------------------------------+--------+

hmm if I go to a half-wave reectifier I'll need twice as much current,
(if I want the led to remain alight inside the optocoupler)
arithmetic shows me that the 10u cap was nowhere near big
enough to absorb that inrush current (even in the original circuit).

I guess a 2.2M resistor across the 400nF cap could reduce the risk of
accidental shoock from the plug pins.

Bye.
Jasen
 
On 2005-09-24, eric <ericgundersen1@mchsi.com> wrote:
"Bob Monsen" <rcsurname@comcast.net> wrote in message
news:pan.2005.09.20.22.58.43.448485@comcast.net...
On Tue, 20 Sep 2005 17:15:02 +0000, Terry Pinnell wrote:

ehsjr <ehsjr@bellatlantic.net> wrote:


It was another damn "use a PIC" post. Some of these posters drive
me crazy. Never a "Wow John, you sure put a lot of work into that,
nice job!" Never a complete project, with a schematic and source
code. Just "you could use a PIC". Hell, if you did what those
pic-ophiles do, your posts would say "use a soldering iron."
One thing's for sure - we can't criticize the PIC designs posted as
solutions to requests from posters. I'll tell you this, I'll put
any one of the solutions you've offered in the newsgroup against
all of the posted "PIC solutions", combined. Your solutions are
always great. Theirs are non-existant.

Agreed. I could probably have made a movie of it in the time it would
take a PIC-er to just get started! Here it is:
http://www.terrypin.dial.pipex.com/Images/LED-Sequencer4MB.wmv

This took 5 minutes to code (adapted another project). 15 if you include
the setup, programming, testing, and bugfix (I inadvertently forgot to
call init(), and it didn't work the first time). Only one chip, a pot, 5
resistors, and 4 leds. Sadly, I don't have a movie camera, or I would
record it. This is compiled with the free 'hitech lite' C compiler, and is
downloaded to a pickit 1 using lawlor's usb_pickit for linux.

The PIC12F675 is an 8 pin uC, which supports ADC, timer interrupts, and
such. Pin 7 is used as the ADC input, so changing the voltage changes the
rate of change of the display, from once every 2 seconds to as fast as it
can go. The period is about Vin/Vcc * 2048 for Vin > 0.

Pin 6, 5, 3, and 2 are A, B, C, and D. Pin 4 is the reset, pin 1 is Vcc,
and pin 8 is GND. A-D can source up to 20mA, so a 1k resistor between it
and the LED limits current to about 3.5mA.

(for the curious, it uses a 1ms interrupt to do delays. The result of
the high byte of the AD is between 0 and 255. Thus 8 * AD is from 0 to
2040, and just delaying that number of ms interrupts provides the ability
to change the period from fast to slow)

BTW, I'm sure we all appreciate JF's and Terry's efforts to help people
out. I wish everybody's posted circuits were as well thought out, tested,
and nicely presented as the ones they post.

Regards

---------------------------------------------------------------------------
#include <pic.h

__CONFIG(UNPROTECT & BORDIS & MCLREN & PWRTDIS & WDTDIS & INTIO);

unsigned int g_ticks; /* Ticks since startup */

#define TICKS_PER_SECOND 1000

#define LED_A GPIO1
#define LED_B GPIO2
#define LED_C GPIO4
#define LED_D GPIO5

void init_gpio(void)
{
GPIO = 0;
}

void init_tmr0(void)
{
/* prescaler is 1:4, GPIO pullups are disabled */
OPTION = 0x81;
}

void init_tmr1(void)
{
T1CON = 0; /* Disabled */
}

void init_comparator(void)
{
CMCON = 0x7; /* Turn off the comparator */
VRCON = 0x0;
}

void init_a2d(void)
{
ANSEL = 0x11; /* Fosc/8 and RA0 is analog */
ADCON0=0x00; // Left justify output
ADON=1; // turn on the A2D conversion module
}

void init_ee()
{
}

void init_interrupts(void)
{
INTCON = 0xA0;
}

void init(void)
{
OSCCAL = _READ_OSCCAL_DATA();

TRISIO = 0x01; /* RA0 is ad input, rest are outputs */

init_gpio();
init_tmr0();
init_tmr1();
init_comparator();
init_a2d();
init_interrupts();
}

unsigned int get_voltage (void)
{
GODONE=1; /* initiate conversion */

while(GODONE) /* wait for result */
{
continue;
}

return ADRESH;
}

void wait_ms(unsigned int x)
{
unsigned int temp = g_ticks + x;
while (temp != g_ticks);
}

void main(void)
{
int state = 0;

init();

LED_A = 1;
LED_B = 1;
LED_C = 0;
LED_D = 0;

for (;;)
{
unsigned int ms_to_wait = get_voltage() * 8;

wait_ms(ms_to_wait);
switch(state)
{
case 0:
LED_A = 0;
LED_C = 1;
state++;
break;

case 1:
LED_B = 0;
LED_D = 1;
state++;
break;

case 2:
LED_C = 0;
LED_A = 1;
state++;
break;

case 3:
LED_D = 0;
LED_B = 1;
state = 0;
break;
}
}
}

static void interrupt isr(void)
{
T0IF = 0;
TMR0 = 6;

g_ticks++;
}



What program lang did you use It looks like C to me or is it Basic?

Eric

--

Bye.
Jasen
 
Please forgive me for replying late to you last post but with winter coming,
it seemed that these comments could be useful.

Dear Mioke

It has been awhile since we addressed this matter, but there is something
else that needs to be said about specific gravity measurements as applied to
a storage battery of the Lead-Acid type. That is that such measurements
will give very specific indications if done properly, about the condition of
the battery and which cells are actually dead.

voltage measurements on a sealed battery can only tell you if the alternator
is
is working. It might even be inaccurate on a marginal battery and lead
one to believe the battery is ok when in fact it might let you sit on a cold
day, or after sitting over night, or if the charging system is marginal .

Also a lot of times a battery may be ok but not taking a charge or sending
current to the rest of the electrical system of which it is a part thereof,
due to corroded or loose terminals.

Simple test that can help being unpleasantly surprised are: with the car
parked facing a reflective surface or light colored surface;
(a) blow the horn and judge by the sound weather it be weak and anemic or
robust and loud. Do this with the lights on and the engine off. Check and
see if the light dim appreciably when the horn is blown.

(b) Next start the engine and run it somewhat above idle speed..

(c) Do the above tests again an note any improvement. This indicates the
charging system is working properly.

(d) Turn the lights off and after a few seconds turn them back on. If the
engine slows down slightly when the lights come on means the charging
system is working and putting a load on the engine.

If after running the engine for a mile or two worth of driving or diling, it
is still misbehaving, I would check all the connections from the alternator
to the battery or regulator, (if the regular is external to the alternator,
and from the battery to the rest of the system, particulary the starter, for
loose, frayed or corroded connections.

"ALBERT C. GOOD JR." <operations@pa.net> wrote in message news:...
Hi

My recollection of the battery section that I once took and my work as a
industrial controls mechanic, is that as a battery discharges its internal
resistance increases. As the internal resistance increases the voltage
will
drop across a constant load.

Further, allowing a battery to sit with the acid in it and not charged is
one of the worst things that can happen to a battery aside from freezing.

When a battery has been sitting for extended periods, the material on the
plates turns into more or less insoluble lead sulfate crystals. This
reduces the surface area in the active battery approximating a permanent
discharged condition.

There is a process that allows such batteries to sometimes be saved, but
it
has some dangers and you are well advised to get in the net and take a
look
at some of the interesting information that battery manufactures post.

Al.

"Mike" <no_spam@comcast.net> wrote in message
news:buSdnYoOltC7jV7cRVn-3w@comcast.com...
A while back, I had a brand new battery that sat for a long time,
eventually
loosing its charge. It was slow-charged for several hours until the
battery
voltage read ~ 12/12.5 volts. I was actually having problems with the
battery handling a load; cranking for 4-5 seconds revealed a slow-down
on
the starter. I proceeded to do a gravity test, which the battery failed.
I
brought the battery into Sears where they put the battery on some
cutting-edge technology machine that didn't use gravity testing. I was
actually arguing with the manager because he was telling me that gravity
tests are very inaccurate. How can this be? Battery acid has greater
gravity
than plain water, which makes up most of the fluid in a dead battery,
thus
causing the "balls" to drop in the tube. This was a while ago, but the
thought just popped in my head...

Thanks
 
In article <71bq03-6hc.ln1@news.compass.net.nz>, jasen-b@free.net.nospam.nz
says...
On 2005-09-27, Davy <zhushenli@gmail.com> wrote:

Hello all,

I am reading TI's datasheet. And What's One-Wait-State On-Chip ROM
mean? Can it be reprogrammable like Flash?

one wait state means it's half as fast as the cpu,
No, as Jerry Avins said, it means that there is an extra cycle (wait state)
between the address and read portion of the access cycle.

if it was user
programmable they'd probably call it PROM,EPROM,FLASH or EEPROM.
--
Keith
 
Hi Jasen,

Thank you :)

I have one more question. If I have no on-chip Flash on TI's DSP, how
to protect my code? For everyone can copy my code from Flash and
produce another product?

All the best,
Davy
 
On 2005-09-29, Davy <zhushenli@gmail.com> wrote:
Hi Jasen,

Thank you :)

I have one more question. If I have no on-chip Flash on TI's DSP, how
to protect my code? For everyone can copy my code from Flash and
produce another product?
yes they can.

one option is to set the circuit in resin to make it hard to access the flash
another is to use a DSP with built in read-protectable PROM etc. if you
intend to produce large quuantities (eg ten thousand) TI can make them
already programmed (so called mask ROM)

Bye.
Jasen
 
I've been looking at all the different kinds of connectors at molex.com.

There are tens of thousands!

I also looked at digikey.com and mouser.com - they are more complicated
to use than molex.com

I just want to know this: if I have a defective connector in my hand (a
2-pin female connector that plugs in vertically to a male connector on a
pcb), what is the process for zeroing in on the part number on molex.com?

I spent an hour and gave up. They have a search screen that allows you
to specify # of conductors, spacing of connectors, friction or positive
lock, AWG, maximum current, etc. Every combination turned up connectors
that look nothing like mine.

I can always just clip off the female connector and solder wires to the
male header pins, but I'd rather not
 

Welcome to EDABoard.com

Sponsor

Back
Top