Darken Ship - via ARMstamp

Post details of your projects here.
Post Reply
olzeke51
Posts: 366
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Darken Ship - via ARMstamp

Post by olzeke51 » Tue Sep 10, 2019 1:38 am

My man-cave has a 'submarine' motif. As a Navy Airdale that spent time on carriers,
you get used to setting different 'integrity conditions' - ie various 'General Quarters'.
One of them was to "Darken Ship" - meaning to go to RED lights for exterior openings.
'
I found the Proto-24 on sale from pcboard.ca that fit the BasicStamp 24 pin layout.
The ARMstamp/LPC11U37 duplicated those pins as well as added another 2 rows of pins.
Below is a picture of my "Set Condition Zebra" - [as I remember it] RED night lights for
my man-cave. {the Internet says it was 'Dog Zebra'}.
'
The relay board has isolated inputs. Currently only 1 relay is used. I power it from a
USB power pak, but needed the 3.3v for the A/D inputs. I loaded up the power section
in case I wanted to go a different route - scrounged parts - not pretty.
FWIW - the relays pull 90ma each - so I wired the relay power to the external 5v line;
didn't want to run all that current through the ARMstamp.
'
I had to do a 14 hour test on the A/D readings - my computer screen / screensaver would
interfere with my initial 'trigger' levels !!!! It currently uses a software timing loop and
turns off at 0730. The 'toggle' forces it on and overides the trigger level until turn off time.
'
I modified the "MultiTask.bas" file to do the different functions - RTC / monitor toggle /
sensor input/ main control functions of the relay-time-trigger level...You gotta watch out
for the amount of time you assign to each function - it can appear to hang... I ended up
using the "jump out of loop via the force interrupt method" for each task!!!
'
"Done is better than ....." - there are a few more additions I want to do - time will tell
Gary
edit Oct 13, 2019 changed picture to final version
ZEBRA.jpg
ZEBRA.jpg (148.37 KiB) Viewed 290 times



olzeke51
Posts: 366
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Darken Ship - via ARMstamp

Post by olzeke51 » Sun Oct 13, 2019 1:46 pm

Okay folks,
First - I updated the above picture
Second::
I had a hard time trying to do a 'switch debounce' routine in the MultiTask method.
So I added (in parallel) a toggle switch, with a bonus beeper!!
'
will post program after a little clean up - my USART prints seem to be doubling up !!!!
Olzeke51

basicchip
Posts: 982
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Darken Ship - via ARMstamp

Post by basicchip » Mon Oct 14, 2019 12:11 am

Buttons and switches bounce, and you have to take that into account. The easiest way is to look for a change in the button then ignore all other changes for a certain debounce time. That can vary a lot depending on the switch. I set up a simple test case on an ARMstamp with a push button between 2 pins. One pin driven low, the other pulled high by the internal resistor.

pb1.png
pb1.png (310.04 KiB) Viewed 288 times

Then some scope pix show the push is pretty clean, but release is takes about 1/2 millisecond to settle

DS1Z_QuickPrint2.jpg
DS1Z_QuickPrint2.jpg (85.91 KiB) Viewed 288 times
DS1Z_QuickPrint4.jpg
DS1Z_QuickPrint4.jpg (84.28 KiB) Viewed 288 times
And here is a program to read the debounced state of the button and display that on the LED

Code: Select all

#define LED_PIN	1

main:

IO(61)=0		' drive one side of the switch low

DEBOUNCED_PB = IN(45)		' set the default state
MAYBE_BOUNCING = 0

while 1
	nextIN = IN(45)
	if DEBOUNCED_PB <> nextIN then
		if MAYBE_BOUNCING = 0 then
			DEBOUNCED_PB = nextIN			' record the change
			MAYBE_BOUNCING = 1
			DEBOUNCE_WAIT = TIMER + 1000	' wait 1 millisecond
		else
			if TIMER > DEBOUNCE_WAIT then
				MAYBE_BOUNCING = 0
			end if
		end if
	end if
	IO(LED_PIN) = DEBOUNCED_PB
loop
	

olzeke51
Posts: 366
Joined: Sat May 17, 2014 4:22 pm
Location: South Carolina

Re: Darken Ship - via ARMstamp

Post by olzeke51 » Mon Oct 14, 2019 11:20 am

Confession time - learning point
I tested Basicchip's routine in my MultiTask program - it worked like a charm
'
So what was wrong with my ideas ??? -- TIME - I was doing 20- 50 ms time loops!
Turns out that information from the Internet is for RELAY contact bounce !!!!
'
Have a good day, y'all
Gary

Post Reply