Did anyone come across a circuit that can monitor the state of some
switches?
The general idea is to monitor the state of any switch (high/low) and
measure the elapsed time that the switch is on or off.
any circuit or idea will be most appreciate.
Tal wrote :
> Did anyone come across a circuit that can monitor the state of some
> switches?
> The general idea is to monitor the state of any switch (high/low) and
> measure the elapsed time that the switch is on or off.
> any circuit or idea will be most appreciate.
>
> Thanks
I must be missing something here...
A circuit to measure elapsed time ?
Using a PIC seams in line with the general topic of this maillist :-)
A pin with the internal pullup enabled maybe ?
Tal wrote :
> Did anyone come across a circuit that can monitor the state of some
> switches?
> The general idea is to monitor the state of any switch (high/low) and
> measure the elapsed time that the switch is on or off.
> any circuit or idea will be most appreciate.
>
> Thanks
I must be missing something here...
A circuit to measure elapsed time ?
Using a PIC seams in line with the general topic of this maillist :-)
A pin with the internal pullup enabled maybe ?
>
> Tal wrote :
> > Did anyone come across a circuit that can monitor the state of some
> > switches?
> > The general idea is to monitor the state of any switch (high/low) and
> > measure the elapsed time that the switch is on or off.
> > any circuit or idea will be most appreciate.
> >
> > Thanks
>
> I must be missing something here...
>
> A circuit to measure elapsed time ?
> Using a PIC seams in line with the general topic of this maillist :-)
> A pin with the internal pullup enabled maybe ?
>
> Is this an old thread ?
>
> Jan-Erik.
>
>
_________________________________________________________________
Send instant messages to anyone on your contact list with MSN Messenger
6.0. Try it now FREE! http://msnmessenger-download.com
First, I admit that I have no idea how to write a code for pic's. this is
the reason I ask for help.
What I am looking for is very simple, a circuit that start when a switch is
pressed for a brief time I call it "start".
this switch is ignored if pressed again until "reset" switch is activate.
another switch is activating a led while is pressed alternately this I call
it "running".
the "reset" switch function in this way: if the switch is pressed for lets
say 10 seconds (no less) then a buzzer is activate. any time less then 10
sec will keep the circuit running (led is blinking while "running" is
alternately pressed) and "start" switch is ignored.
if "reset" is activated more than 10 sec then "start" switch can start the
circuit all over again, and so on. like a loop.
> What I am looking for is very simple, a circuit that start when a switch
is
> pressed for a brief time I call it "start"
Detect Start switch (I presume a pushbutton)
Assuming switches connected to Port A and active high
#define start_sw porta,0
#define reset_sw porta,1
In your code
test_sw btfss start_sw ;wait for a "1" to appear on porta,0
goto test_sw ;else loop while "0"
> this switch is ignored if pressed again until "reset" switch is activate
So don't test start_sw again until reset
============================
> another switch is activating a led while is pressed alternately this I
call
> it "running"
Don't quite understand that function.
============================
> the "reset" switch function in this way: if the switch is pressed for lets
> say 10 seconds (no less) then a buzzer is activated
reset btfss reset_sw ;wait for a "1" to appear on porta,1
goto reset ;else loop while "0"
What you could do hear is start a timer interrupt that can be used to
measure how long reset_sw is depressed. The settings will depend
on which PIC and how fast
For example, an F6228 running at 3.2768MHz
Timer1 free-running will generate 12.5 interrupts/second = 125 in
10 seconds
Enable the interrupts on the first detection of reset_sw being pushed
and each time there's an interrupt, test for both reset_sw depressed
and interrupt counter = 125. If reset_sw is not depressed then 0 the
counter. If counter = 125 then do the reset. Having reset_sw on portb,0
or other external interrupt source might make it easier to detect a press,
depending on your code
about the "running" switch: the machine have a part that move alternately
all the time (forward - backward) so each time the moving part is crossing
the middle of it's travel it press a switch (can be a reed relay or
something else..) so I want to see by light from a distance that the part is
moving and doesn't in hold/stop position. Ex.: monitoring a turning plate
that finish each turn by activating the switch/reed relay etc...
> about the "running" switch: the machine have a part that
> move alternately all the time (forward - backward) so each
> time the moving part is crossing the middle of it's travel it
> press a switch
OK, that's something that an external interrupt pin would be
useful for. When the switch is activated by this moving piece
of machinery it can alert the PIC a couple of ways.
One is to use the INT flag to store this event. Whether or not
the external interrupt is enabled, INTF will be set by a switch
transition until your code resets it. You could look for this flag
as part of the Timer1 ISR. If it's set, turn a LED on for a Timer1
interrupt period. An 80ms flash is quite noticeable, but you
could keep the LED on for the duration of a counter driven by
Timer1 IRQs
#define led porta,2
ISR
-----
bcf led ;turn LED off by default
btfss intcon,intf ;test for external event
goto process_timer1_irq ;no, carry on with no LED lit
bcf intcon,intf ;yes, clear flag
bsf led ;light LED
bcf tmr1if ;clear Timer1 flag
process_timer1_irq ;continue
retfie
The other way would be to have Timer0 as a counter and set it
to 0xFF. A pulse coming into RA4 will cause Timer0 to rollover
to 0x00 and set T0IF, which you can check for
> useful for. When the switch is activated by this moving piece
> of machinery it can alert the PIC a couple of ways.
Oh, another way I meant to mention was using an RC to store
the event. That way you could use a general purpose I/O pin
Set the pin as an input, C to ground and R to 5V via the switch.
When the switch closes the C will charge up and record the
closure. You can read this when your code has time. Set the
pin to an output and "0" to discharge the cap. It shouldn't need
a very big cap to do this, maybe a few nF. It depends on how
long the switch is closed for. Discharging C through a resistor,
a couple of hundred ohms, would be safe