PIC12F629 beginner needs help

A

Allen Bong

Guest
Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz. Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select. That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button. And how do I calibrate the internal
osc freq using OSCCAL bits? Can someone here help?

Thanks.

Allen
 
In article <77adeea0-6360-4f5b-a267-
c05128984ae8@s11g2000prs.googlegroups.com>,
allenbsf6502@gmail.com says...
Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz. Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select. That used up all the gpio pins and
nothing was left for the osc and reset.
For a reset, one way around this could be to
reset when both Start AND Stop are pressed
together. Think of it as the PIC version of
Ctrl-Alt-Del.

You could also have one switch alternate
3min/5min/3min/5min, rather than 1 switch for
each.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button. And how do I calibrate the internal
osc freq using OSCCAL bits? Can someone here help?
Try to find some project code for that micro
online. You should be able to find some with the
configuration codes for INTOSC mode.

As to OSCCAL, I can't help you there.

Thanks.

Allen
 
On Sun, 14 Nov 2010 18:44:01 -0800, Allen Bong wrote:

I dont know how to configure it to internal oscillation
_config (_INTRC_OSC_NOCLKOUT & ...)
 
On Nov 15, 4:37 pm, Nobody <nob...@nowhere.com> wrote:
On Sun, 14 Nov 2010 18:44:01 -0800, Allen Bong wrote:
I dont know how to configure it to internal oscillation

        _config (_INTRC_OSC_NOCLKOUT & ...)

Thanks, That would solve half my problem.

Allen
 
On Nov 15, 11:26 am, Randy Day <randy....@sasktel.netx> wrote:
In article <77adeea0-6360-4f5b-a267-
c05128984...@s11g2000prs.googlegroups.com>,
allenbsf6...@gmail.com says...

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

For a reset, one way around this could be to
reset when both Start AND Stop are pressed
together. Think of it as the PIC version of
Ctrl-Alt-Del.

You could also have one switch alternate
3min/5min/3min/5min, rather than 1 switch for
each.



I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Try to find some project code for that micro
online. You should be able to find some with the
configuration codes for INTOSC mode.

As to OSCCAL, I can't help you there.





Thanks.

Allen- Hide quoted text -

- Show quoted text -
Hi Randy,

My circuit looks like below:


+----+----+------+
| | | |
.-. .-. .-. |
| | | | | | |
|R| |R| |R| | VCC
'-' '-' '-' +----+---------------------+
| | | | |
| | | | 12f629 |
| | | .----o-----. 330 LED |
| +-----------ogp5 gp0o--|___|---|<---+
| | | | | ___ |
+----|-----------ogp4 gp1o--|_R_|---+ |
| | | | | | |
| | +------oMCLR gp2o-----+ | |/
| | | '-----o----' | +--|
| o | | | | |>
|=|> | | === | |
STOP| o | |START GND | |
| | o | ___ | .-.
| | |=| VCC -|_R_|---+ | |
=== | o | | | |100
GND | | | o '-'
| o | |=|> 2/5 B | __ /|
|=|> === | o +-| | |
3/5 M| o GND | +-|__| |
| | | \|
| === == === GND GND
GND


(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)

I am not sure what you meant by pressing 2 keys together to cause a
Reset. Do you mean when both keys are detected together would cause
a jump to address 0x0000? Then that's a good idea. I would give it a
try
to see if it works.


Allen
 
In article <ee0980bf-d7a7-44ba-9407-
73dc637a086e@o23g2000prh.googlegroups.com>,
allenbsf6502@gmail.com says...
On Nov 15, 11:26 am, Randy Day <randy....@sasktel.netx> wrote:
[snip]

I am not sure what you meant by pressing 2 keys together to cause a
Reset. Do you mean when both keys are detected together would cause
a jump to address 0x0000? Then that's a good idea. I would give it a
try
to see if it works.
That's the idea I wanted to get across...

Hope it works for you.
 
Allen Bong wrote:
I am not sure what you meant by pressing 2 keys together to cause a
Reset. Do you mean when both keys are detected together would cause
a jump to address 0x0000? Then that's a good idea. I would give it a
try
to see if it works.

Why would it need a reset if it's running well enough to even read the
keypresses?

Thanks,
Rich
 
On Nov 16, 3:18 am, Rich Grise <ri...@example.net.invalid> wrote:
Allen Bong wrote:

I am not sure what you meant by pressing 2 keys together to cause a
Reset.  Do you mean when both keys are detected together would cause
a jump to address 0x0000?  Then that's a good idea.  I would give it a
try
to see if it works.

Why would it need a reset if it's running well enough to even read the
keypresses?

Thanks,
Rich
Hi Rich,

I think I get caught here..... First I said I used up all the port
pins and there is no pin left for a reset button on the MCLR. Then
Randy suggested a software reset by pressing 2 buttons, so it seems
that didn't totally solve my problems. My question should be "How do
I do an auto Power on Reset leaving the MCLR pin alone so I can use it
as a PORT pin?"

I guess the question is clearer now.

Allen
 
On Nov 15, 1:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:
On Nov 16, 3:18 am, Rich Grise <ri...@example.net.invalid> wrote:

Allen Bong wrote:

I am not sure what you meant by pressing 2 keys together to cause a
Reset.  Do you mean when both keys are detected together would cause
a jump to address 0x0000?  Then that's a good idea.  I would give it a
try
to see if it works.

Why would it need a reset if it's running well enough to even read the
keypresses?

Thanks,
Rich

Hi Rich,

I think I get caught here.....  First I said I used up all the port
pins and there is no pin left for a reset button on the MCLR.   Then
Randy suggested a software reset by pressing 2 buttons, so it seems
that didn't totally solve my problems.  My question should be "How do
I do an auto Power on Reset leaving the MCLR pin alone so I can use it
as a PORT pin?"

I guess the question is clearer now.

Allen

I usually use this configuration. The power-up timer delays startup by
72 milliseconds to allow the supply to reach operating level. No reset
needed, just turn off the power and back on.


__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON &
_INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF


CP_OFF ------- (Code protection off)
WDT_OFF ---- (Watch Dog Timer off)
BODEN_OFF -- (Brownout detection off)
PWRTE_ON -- (Power up timer enable)
INTRC_OSC -- (Internal 4 MHz oscillator, no clock out)
MCLRE_OFF -- (Master clear/ reset off)
CPD_OFF --- (Data Code Protection off)

-Bill
 
In article <5a2f1a13-22ab-4aa9-9f50-
80aecf0a0567@v28g2000prn.googlegroups.com>,
allenbsf6502@gmail.com says...

[snip]

Why would it need a reset if it's running well enough to even read the
keypresses?

Thanks,
Rich

Hi Rich,

I think I get caught here..... First I said I used up all the port
pins and there is no pin left for a reset button on the MCLR. Then
Randy suggested a software reset by pressing 2 buttons, so it seems
that didn't totally solve my problems. My question should be "How do
I do an auto Power on Reset leaving the MCLR pin alone so I can use it
as a PORT pin?"
I was trying (poorly) to get across the idea
that you can use switches in combination to call
different functions, not just reset.

Insisting on having the mclr line available
as a port pin automatically presumes your
code must work, since mclr isn't available
for resets. Your only real option is power-off.

---------

Picking nits here, but you can use a 2-button
combo to cause a reset; the mclr line button
just has to be one of them:

<pseudocode>
detect press of Button2 ; not the mclr button
set bit 5 of CONFIG register ; mclr is now a reset line
set your flags for Button2

loop until Button2 is released
clear bit 5 of CONFIG ;set mclr back to port pin
</pseudocode>

Setting bit 5 makes the MCLR line active while
Button2 is pressed. If the MCLR button doesn't
get pressed, Button2 behaves as usual. Yes,
your code has to be running normally, but it
can issue a hard reset if you really want it
to.

---------

Other options to free up the mclr line:
- alternating two states with one button
(stop/start or 3min/5min, for example)
- using 2-button combinations to call other
functions.
- use a short button press to signal one state,
hold the button longer to signal another
state.

If you can't make your switches multi-function
in some fashion, your options are pretty much
a) reset by cutting the power, or
b) get a micro with more pins.
 
On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:
Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all. You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC
 
On Nov 16, 5:16 pm, Randy Day <randy....@sasktel.netx> wrote:
In article <5a2f1a13-22ab-4aa9-9f50-
80aecf0a0...@v28g2000prn.googlegroups.com>,
allenbsf6...@gmail.com says...

[snip]

Why would it need a reset if it's running well enough to even read the
keypresses?

Thanks,
Rich

Hi Rich,

I think I get caught here.....  First I said I used up all the port
pins and there is no pin left for a reset button on the MCLR.   Then
Randy suggested a software reset by pressing 2 buttons, so it seems
that didn't totally solve my problems.  My question should be "How do
I do an auto Power on Reset leaving the MCLR pin alone so I can use it
as a PORT pin?"

I was trying (poorly) to get across the idea
that you can use switches in combination to call
different functions, not just reset.

Insisting on having the mclr line available
as a port pin automatically presumes your
code must work, since mclr isn't available
for resets. Your only real option is power-off.

---------

Picking nits here, but you can use a 2-button
combo to cause a reset; the mclr line button
just has to be one of them:

pseudocode
detect press of Button2 ; not the mclr button
set bit 5 of CONFIG register ; mclr is now a reset line
set your flags for Button2

loop until Button2 is released
clear bit 5 of CONFIG   ;set mclr back to port pin
/pseudocode

Setting bit 5 makes the MCLR line active while
Button2 is pressed. If the MCLR button doesn't
get pressed, Button2 behaves as usual. Yes,
your code has to be running normally, but it
can issue a hard reset if you really want it
to.

---------

Other options to free up the mclr line:
- alternating two states with one button
  (stop/start or 3min/5min, for example)
- using 2-button combinations to call other
  functions.
- use a short button press to signal one state,
  hold the button longer to signal another
  state.

If you can't make your switches multi-function
in some fashion, your options are pretty much
a) reset by cutting the power, or
b) get a micro with more pins.
OK, I get the general concept of how to use 2 buttons 'making'
together to get the function of a 3rd button. I will apply it in my
future project when I get the codes working.

The other method of alternating 2 functions with one button has to be
indicated visually (eg an LED), or else I would know which function I
am in.

The long and short duration technique is nice and I wonder if you have
some codes for me to try out?

At the moment, my task is very simple and I dont plan to use a bigger
chip. My program assembled to 138 words only so I will apply all the
techniques above to reduce the hardware.

Thank you very much for your time and I have learnt a great deal from
you today.

Regards,

Allen
 
On Nov 16, 6:03 pm, Varactor <morefl...@gmail.com> wrote:
On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:



Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all.  You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC- Hide quoted text -

- Show quoted text -
Do you mean like the circuit below? My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed. If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right? Good
idea !!!!


Allen




VCC VCC
| |
12F675 .-. o |
.------. | | |=| "A"
| | 4.7K | | o |
| | '-' |
| | | |
| | 2.5V | |
| AN0|--------+----+
| | | |
| | | |
| | .-. o |
| | | | |=| "B"
'------' 4.7K | | o |
'-' |
|
| |
=== == GND GND



(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)
 
On Nov 17, 6:46 am, Allen Bong <allenbsf6...@gmail.com> wrote:
On Nov 16, 6:03 pm, Varactor <morefl...@gmail.com> wrote:









On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all.  You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC- Hide quoted text -

- Show quoted text -

Do you mean like the circuit below?  My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed.  If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right?  Good
idea  !!!!

Allen

                       VCC  VCC
                        |    |
         12F675        .-.   o |
        .------.       | |     |=| "A"
        |      |  4.7K | |   o |
        |      |       '-'   |
        |      |        |    |
        |      |  2.5V  |    |
        |   AN0|--------+----+
        |      |        |    |
        |      |        |    |
        |      |       .-.   o |
        |      |       | |     |=| "B"
        '------'  4.7K | |   o |
                       '-'   |
                        |
                        |    |
                       ===  ==>                        GND  GND


Yes, that would be OK for 2 buttons. To get more you need to think
about binary coding and about each button being a part of a digital to
analog converter. The press of each button adds in a current which is
then measured. So, if each button is connected to the pin via a
resistor to Vcc and each resistor value goes as a power of 2 then the
voltage on that pin, measured by a resistor to ground will be binary
coded. The limit is the precision of the resistors and the A/D
converter. With a 10 bit converter you could easily code > 4 buttons
(the theoretical maximum is the bit resolution of the converter, but
with only 5% resistors the maximum is 4) ... Just make sure you use
the whole range of the converter.

With an A/D converter pin you can do a lot of tricks.

Cheers MC
 
On Nov 17, 3:17 am, Varactor <morefl...@gmail.com> wrote:
On Nov 17, 6:46 am, Allen Bong <allenbsf6...@gmail.com> wrote:



On Nov 16, 6:03 pm, Varactor <morefl...@gmail.com> wrote:

On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all.  You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC- Hide quoted text -

- Show quoted text -

Do you mean like the circuit below?  My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed.  If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right?  Good
idea  !!!!

Allen

                       VCC  VCC
                        |    |
         12F675        .-.   o |
        .------.       | |     |=| "A"
        |      |  4.7K | |   o |
        |      |       '-'   |
        |      |        |    |
        |      |  2.5V  |    |
        |   AN0|--------+----+
        |      |        |    |
        |      |        |    |
        |      |       .-.   o |
        |      |       | |     |=| "B"
        '------'  4.7K | |   o |
                       '-'   |
                        |
                        |    |
                       ===  ==> >                        GND  GND

Yes, that would be OK for 2 buttons. To get more you need to think
about binary coding and about each button being a part of a digital to
analog converter.  The press of each button adds in a current which is
then measured. So, if each button is connected to the pin via a
resistor to Vcc and each resistor value goes as a power of 2 then the
voltage on that pin, measured by a resistor to ground will be binary
coded. The limit is the precision of the resistors and the A/D
converter. With a 10 bit converter you could easily code > 4 buttons
(the theoretical maximum is the bit resolution of the converter, but
with only 5% resistors the maximum is 4) ... Just make sure you use
the whole range of the converter.

With an  A/D converter pin you can do a lot of tricks.

Cheers MC- Hide quoted text -

- Show quoted text -
The circuit below would detect 4 switches at 5v, 3.75, 2.5, 1.25v
idealling at 0V. Would
this setup work? How many switches can I connect to my 12F675 running
at 4 MHz, 4.5V Vcc
with 1% resistors if the setup works?

Regards,

Allen


VCC
+----+
T | |
--- | .-.
12F675 +---o o----+ | |
.-----. | | |1k
| | | T '-'
| | | --- |
| | +------+-o o----+
| | | |
| | | .-.
| | | | |
| | | | |1k
| | | T '-'
| | | --- |
| AN1|----+---+--+-o o----+
| | | | | |
'-----' .-. | | .-.
| | - | | |
10k| | ^ | | |1k
'-' | | T '-'
| | | --- |
+---+ +-o o----+
| |
| .-.
GND | |
| |1k
'-'
|
GND


(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)
 
On Nov 17, 1:17 pm, Allen Bong <allenbsf6...@gmail.com> wrote:
On Nov 17, 3:17 am, Varactor <morefl...@gmail.com> wrote:









On Nov 17, 6:46 am, Allen Bong <allenbsf6...@gmail.com> wrote:

On Nov 16, 6:03 pm, Varactor <morefl...@gmail.com> wrote:

On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all.  You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC- Hide quoted text -

- Show quoted text -

Do you mean like the circuit below?  My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed.  If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right?  Good
idea  !!!!

Allen

                       VCC  VCC
                        |    |
         12F675        .-.   o |
        .------.       | |     |=| "A"
        |      |  4.7K | |   o |
        |      |       '-'   |
        |      |        |    |
        |      |  2.5V  |    |
        |   AN0|--------+----+
        |      |        |    |
        |      |        |    |
        |      |       .-.   o |
        |      |       | |     |=| "B"
        '------'  4.7K | |   o |
                       '-'   |
                        |
                        |    |
                       ===  ==> > >                        GND  GND

Yes, that would be OK for 2 buttons. To get more you need to think
about binary coding and about each button being a part of a digital to
analog converter.  The press of each button adds in a current which is
then measured. So, if each button is connected to the pin via a
resistor to Vcc and each resistor value goes as a power of 2 then the
voltage on that pin, measured by a resistor to ground will be binary
coded. The limit is the precision of the resistors and the A/D
converter. With a 10 bit converter you could easily code > 4 buttons
(the theoretical maximum is the bit resolution of the converter, but
with only 5% resistors the maximum is 4) ... Just make sure you use
the whole range of the converter.

With an  A/D converter pin you can do a lot of tricks.

Cheers MC- Hide quoted text -

- Show quoted text -

The circuit below would detect 4 switches at 5v, 3.75, 2.5, 1.25v
idealling at 0V.  Would
this setup work?  How many switches can I connect to my 12F675 running
at 4 MHz, 4.5V Vcc
with 1% resistors if the setup works?

Regards,

Allen

                           VCC
                         +----+
                   T     |    |
                  ---    |   .-.
   12F675     +---o o----+   | |
   .-----.    |              | |1k
   |     |    |         T    '-'
   |     |    |        ---    |
   |     |    +------+-o o----+
   |     |           |        |
   |     |           |       .-.
   |     |           |       | |
   |     |           |       | |1k
   |     |           |  T    '-'
   |     |           | ---    |
   |  AN1|----+---+--+-o o----+
   |     |    |   |  |        |
   '-----'   .-.  |  |       .-.
             | |  -  |       | |
          10k| |  ^  |       | |1k
             '-'  |  |  T    '-'
              |   |  | ---    |
              +---+  +-o o----+
              |               |
              |              .-.
             GND             | |
                             | |1k
                             '-'
                              |
                             GND

(created by AACircuit v1.28.6 beta 04/19/05www.tech-chat.de)
Close, but not quite. Look at it, the top switch connects the pin to
Vcc regardless of the other switches so the pic will only see that
switch. There are a couple of ways of doing it. Try putting the
switches with their coding resistors in parallel to Vcc and all
connected to the input pin. Now, the resistor to ground from the pin
forms a voltage divider (you can also use the input resistance of the
pic alone) with the resistor to Vcc formed by variable numbers of //'d
resistors. The number of those resistors and their values determines
the voltage. So, provided each resistor value is unique, the overall
resistance from the pin to Vcc is uniquely coded by the switches.
The second way is to use each switch to short out a single resistor
from the chain (which may be simpler to think about). Again the value
of each resistor in the chain must be unique and ideally very
different (say powers of 2 (i.e. 1k, 2k, 4k, 8k). A few (fun :))
minutes with a soldering iron and a multimeter will let you see how it
works -by whatever method. Finally, if the switches are double pole
you can use a R2R ladder (you can google that). The R2R ladder is a
method used to make many D/A converters. You may also want to look up
'Gray coding' to further your knowledge of how to reliably encode
physical parameters for a computer.

Good luck!

MC
 
On Nov 17, 9:03 am, Varactor <morefl...@gmail.com> wrote:
On Nov 17, 1:17 pm, Allen Bong <allenbsf6...@gmail.com> wrote:





On Nov 17, 3:17 am, Varactor <morefl...@gmail.com> wrote:

On Nov 17, 6:46 am, Allen Bong <allenbsf6...@gmail.com> wrote:

On Nov 16, 6:03 pm, Varactor <morefl...@gmail.com> wrote:

On Nov 15, 3:44 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

Hi,

I ordered some 12f629 & 12f675 from microchip direct and wanted to
play with them.

I have a simple circuit that have a LED that flash every second, a
piezo that will buzz at 800Hz.  Plus 4 switches for Start, Stop, 2/5
beeps select, 3 min/5 min select.  That used up all the gpio pins and
nothing was left for the osc and reset.

I dont know how to configure it to internal oscillation and do a power
on rest without a reset button.  And how do I calibrate the internal
osc freq using OSCCAL bits?  Can someone here help?

Thanks.

You really don't need all those pins for those functions. Why not use
one pin for start and stop -they are exclusive after all.  You could
get away with 2 pins if you just use one switch for start and stop
functions and the analog in for the other functions. The key is to
realize that the switches can each add a different current to the
input so that by measuring the input voltage you can decide what
combinations of switches are set. You could even use just one pin with
this method ...

Hope this helps.

MC- Hide quoted text -

- Show quoted text -

Do you mean like the circuit below?  My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed.  If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right?  Good
idea  !!!!

Allen

                       VCC  VCC
                        |    |
         12F675        .-.   o |
        .------.       | |     |=| "A"
        |      |  4.7K | |   o |
        |      |       '-'   |
        |      |        |    |
        |      |  2.5V  |    |
        |   AN0|--------+----+
        |      |        |    |
        |      |        |    |
        |      |       .-.   o |
        |      |       | |     |=| "B"
        '------'  4.7K | |   o |
                       '-'   |
                        |
                        |    |
                       ===  ==> > > >                        GND  GND

Yes, that would be OK for 2 buttons. To get more you need to think
about binary coding and about each button being a part of a digital to
analog converter.  The press of each button adds in a current which is
then measured. So, if each button is connected to the pin via a
resistor to Vcc and each resistor value goes as a power of 2 then the
voltage on that pin, measured by a resistor to ground will be binary
coded. The limit is the precision of the resistors and the A/D
converter. With a 10 bit converter you could easily code > 4 buttons
(the theoretical maximum is the bit resolution of the converter, but
with only 5% resistors the maximum is 4) ... Just make sure you use
the whole range of the converter.

With an  A/D converter pin you can do a lot of tricks.

Cheers MC- Hide quoted text -

- Show quoted text -

The circuit below would detect 4 switches at 5v, 3.75, 2.5, 1.25v
idealling at 0V.  Would
this setup work?  How many switches can I connect to my 12F675 running
at 4 MHz, 4.5V Vcc
with 1% resistors if the setup works?

Regards,

Allen

                           VCC
                         +----+
                   T     |    |
                  ---    |   .-.
   12F675     +---o o----+   | |
   .-----.    |              | |1k
   |     |    |         T    '-'
   |     |    |        ---    |
   |     |    +------+-o o----+
   |     |           |        |
   |     |           |       .-.
   |     |           |       | |
   |     |           |       | |1k
   |     |           |  T    '-'
   |     |           | ---    |
   |  AN1|----+---+--+-o o----+
   |     |    |   |  |        |
   '-----'   .-.  |  |       .-.
             | |  -  |       | |
          10k| |  ^  |       | |1k
             '-'  |  |  T    '-'
              |   |  | ---    |
              +---+  +-o o----+
              |               |
              |              .-.
             GND             | |
                             | |1k
                             '-'
                              |
                             GND

(created by AACircuit v1.28.6 beta 04/19/05www.tech-chat.de)

Close, but not quite. Look at it, the top switch connects the pin to
Vcc regardless of the other switches so the pic will only see that
switch. There are a couple of ways of doing it. Try putting the
switches with their coding resistors in parallel to Vcc and all
connected to the input pin. Now, the resistor to ground from the pin
forms a voltage divider (you can also use the input resistance of the
pic alone) with the resistor to Vcc formed by variable numbers of //'d
resistors. The number of those resistors and their values determines
the voltage. So, provided each resistor value is unique, the overall
resistance from the pin to Vcc is uniquely coded by the switches.
The second way is to use each switch to short out a single resistor
from the chain (which may be simpler to think about). Again the value
of each resistor in the chain must be unique and ideally very
different (say powers of 2 (i.e. 1k, 2k, 4k, 8k).  A few (fun :))
minutes with a soldering iron and a multimeter will let you see how it
works -by whatever method. Finally, if the switches are double pole
you can use a R2R ladder (you can google that). The R2R ladder is a
method used to make many D/A converters. You may also want to look up
'Gray coding' to further your knowledge of how to reliably encode
physical parameters for a computer.

Good luck!

MC- Hide quoted text -

- Show quoted text -
Thanks very much MC,

I would need more time to digest what you have said. Google is my
best friend anyway not forgetting wikidepia as well. I will post back
here if there's anything I dont understand.

I would like to thanks those answering my post including Bill Bowden
whose web site I frequently visit to get circuit ideas. I have
another 2 more projects I am going to do: poor man's o'scope using
12F675 and a bike computer using 16F628 for my newly bought bicycle.

Cheers,

Allen.
 
In article <863dfac8-adbb-4ad5-89ff-
32ea6f859b5b@j9g2000vbr.googlegroups.com>,
allenbsf6502@gmail.com says...

[snip]

The long and short duration technique is nice and I wonder if you have
some codes for me to try out?
Just air code. I'm using timer SFR names
from micros I use, so they may not apply
to the '675:

Button_Loop
btfsc GPIO, 0
goto Button_Loop

; enable 1 second timer here

Short_Loop
btfsc GPIO, 0
goto Short_Press

; loop until timer expires
btfss PIR1, TMR1IF
goto Short_Loop

; if timer manages to expire, the
; button is still pressed,
; and is considered a 'long' (>1sec)
; press.

; turn off timer here

Long_Press ; keep looping until button is released
btfss GPIO, 0
goto Long_Press

; run your 'long press' code
goto Main_Program

Short_Press
; if gpio<0> went high before 1sec,
; the button was released as a 'short'
; (<1sec) press.

; turn off timer here
; run your 'short press' code
goto Main_Program
 
On 2010-11-17, Varactor <moreflaps@gmail.com> wrote:
On Nov 17, 1:17 pm, Allen Bong <allenbsf6...@gmail.com> wrote:

Do you mean like the circuit below?  My 12f675 does have 4 analog
inputs.

So AN0 will normally be 2.5V when A nor B is pressed.  If Button A is
pressed then AN0=5V. If button B is pressed then AN0=0V, right?  Good
idea  !!!!

Allen

                       VCC  VCC
                        |    |
         12F675        .-.   o |
        .------.       | |     |=| "A"
        |      |  4.7K | |   o |
        |      |       '-'   |
        |      |        |    |
        |      |  2.5V  |    |
        |   AN0|--------+----+
        |      |        |    |
        |      |        |    |
        |      |       .-.   o |
        |      |       | |     |=| "B"
        '------'  4.7K | |   o |
                       '-'   |
                        |
                        |    |
                       ===  ===
                       GND  GND
that's one way to wire a 'push A and B ro reset the MCU'.

doesn't work to well with a low impedance supply. :)

--
⚂⚃ 100% natural
 
On Nov 17, 1:27 pm, Randy Day <randy....@sasktel.netx> wrote:
In article <863dfac8-adbb-4ad5-89ff-
32ea6f859...@j9g2000vbr.googlegroups.com>,
allenbsf6...@gmail.com says...

[snip]

The long and short duration technique is nice and I wonder if you have
some codes for me to try out?

Just air code. I'm using timer SFR names
from micros I use, so they may not apply
to the '675:

Button_Loop
        btfsc GPIO, 0
        goto Button_Loop

        ; enable 1 second timer here

Short_Loop
        btfsc GPIO, 0
        goto  Short_Press

        ; loop until timer expires
        btfss   PIR1, TMR1IF
        goto Short_Loop

        ; if timer manages to expire, the
        ; button is still pressed,
        ; and is considered a 'long' (>1sec)
        ; press.

        ; turn off timer here

Long_Press      ; keep looping until button is released
        btfss GPIO, 0
        goto Long_Press

        ; run your 'long press' code
        goto Main_Program

Short_Press
        ; if gpio<0> went high before 1sec,
        ; the button was released as a 'short'
        ; (<1sec) press.

        ; turn off timer here
        ; run your 'short press' code
        goto    Main_Program
Let me see if I understand it right.

For a short press: It enters Botton_Loop, pass the first btfsc test.
Then enable 1 sec timer, past second btfsc test. Timer 1 not yet
expired, Loop back into the Short_Loop. Release button before timer 1
expires and exit into Short_Press.

For a long press: Enters at Button_Loop, pass the first btfsc test,
set up timer 1 for 1 sec, Goes through second btfsc test and on 3rd
btfss test, also dropped into the Short_Loop until > 1 second, timer1
expires, will drop onto Long_Press loop and exit btfss when the button
is released.

Very nice, but at first glance, a bit tough to understand how it
works.

Thank you Randy for teaching me this new trick!! I'll put it into my
macro library file and include it on my next program.

Cheers,

Allen
 

Welcome to EDABoard.com

Sponsor

Back
Top