Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

OFF-the-wall idea for momentary ON switch

MrDEB

Well-Known Member
Looking to build a digital kitchen timer that shuts off after timing out and/or a 10 second delay waiting for user input.
Here is the screenshot of the on/off section of the kitchen timer. Going to use an 18Fxxxx pic
maybe need a diode on the pic output pin to prevent applying voltage to the unpowered pic.
Screenshot (38).png
unpowered pic?
 
If the user changes the desired time shouldn't the delay restart?
User sets desired TIME but before the timer starts the user changes the desired time BEFORE THE GREEN led IS ENABLED.

How do you know when the user has finished setting the desired time and isn't just slow doing it?

I've probably completely misunderstood what you've said so feel free to completely ignore the above.

Mike.
 
After the user inputs the desired TIME, the pic automatically starts timing after 10-15 second delay.

You need a GO button. If I enter 2 minutes, I want to know when 2 minutes have elapsed, not 2 minutes + some delay. What if I want 87 seconds? Or an hour?
 
You need a GO button. If I enter 2 minutes, I want to know when 2 minutes have elapsed, not 2 minutes + some delay. What if I want 87 seconds? Or an hour?
Then use a clock that works differently. The timer on my oven can't be set to 87-seconds. Can yours?
 
I've probably completely misunderstood what you've said so feel free to completely ignore the above.

Mike.
You have missed something.
Re-read the first line of the OPs first post. It's interesting how much bad advice he is getting - and how many attempts members have made to negotiate is simple specification.
 
You have missed something.
Re-read the first line of the OPs first post. It's interesting how much bad advice he is getting - and how many attempts members have made to negotiate is simple specification.
Maybe I have but these threads get so confusing. Four pages and you want to ignore everything and send me back to the first post!

Mike.
 
disregard post#80 my mistake
going to just add a lighted tactile switch for TIMER START

Please don't blindly accept my answers/critisms, or anybody else's for that matter. Try to figure out what the points are and how you might address them. For example, I asked what happens if somebody wants 87 seconds. I got the idea you were thinking in terms of integer (whole):minutes. What if 90 seconds is the right answer? What if they want an hour? Have you considered what durations people might want?

What if they do want a hour? You don't have any provision to turn off the LED backlight – it would eat the batteries.

You're building a timer. Take the bigger view. How might somebody want to use a timer? A short time to time an egg. 15 minutes to time a Covid test. Three hours and 20 minutes to time the Thanksgiving turkey. Will they use a timer to tell them when a week's gone by? Probably not.

A little thought before you draw a dozen schematics can make things a lot easier, and prevent the "Why didn't I plan for....." later.
 
I read the Original post and my question still stands. Care to explain as you obviously understand this better than I?

Mike.
The user adjusts the set-time and, after 10-seconds of no adjustments, the kitchen timer starts. Exactly like he said it. I don't know how else it can be interpreted.

It's a "kitchen timer", not a stopwatch. If he wants to bake a cake, the 10-seconds delayed start makes no difference.
 
I have added a lighted tactile switch and, yes, contemplated adding more input to change the desired time.
I originally used a microwave as an example. It has 10 seconds, 30 minutes, 1 minute and 5 minutes.
Yes hours is a good choice to include. Still considering different functions BUT want to keep it simple
Post #89 helps explain my post#80
 
yes the backlight on the LCD has yet to make its appearance on the project Been tied up with the Marguerita sign project and getting my b.
ebook cover.jpg
ook published
 
Well got back to this project and considering something other than a bunch of buttons. maybe a pot? and use ADC??
Code:
Device = 18F43K22
Clock = 16
// int osc and IO pin libraries
Include "intosc.bas"

#option DIGITALIO_INIT = true       // automatically call setalldigital
Include "setdigitalio.bas"

#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
Include "LCD.bas"
Include "convert.bas"
Include "utils.bas"
//SWITCHES
Dim SWT_0 As PORTB.0
Dim SWT_1 As PORTB.1
Dim SWT_2 As PORTB.2
Dim SWT_3 As PORTB.3
Dim SWT_4 As PORTB.4
Dim SWT_5 As PORTB.5
Dim SWT_6 As PORTB.6
Dim SWT_7 As PORTB.7
//LEDS

Dim led0 As PORTC.0  //HOURS+
Dim led1 As PORTC.1  //HOURS-
Dim led2 As PORTC.2  //MINIUTES+
Dim led3 As PORTC.3  //MINIUTES-
Dim led4 As PORTC.4  //SECONDS+
Dim led5 As PORTC.5  //SECONDS-
Dim led6 As PORTC.6
Dim led7 As PORTC.7

Dim x As Byte
Dim TIME As Byte
Dim Hrs_p As Byte  'hours plus
Dim Hrs_m As Byte  'hours minius
Dim Min_p As Byte  'miniutes plus
Dim Min_m As Byte   'miniutes minius
Dim Sec_p As Byte    'Seconds plus
Dim Sec_m As Byte   'Seconds minius.
Dim Hours As Byte
Dim Miniutes As Byte
Dim seconds As Byte
//Dim Timeer_value String

  // set switch port to inputs and enable pullups
    TRISB = $ff                // set as inputs
    WPUB = $ff                // enable pullups on all PORTB pins
    INTCON2.bits(7) = 0        // set bit RBPU = 0 turns on pullups
    TRISC = 0                                                       
    TRISA = 0
    TRISD = 0
    
//set beginning values   
    Hrs_p = 00      'hours plus
    Hrs_m = 00      'hours minus
    Min_p = 00      'miniutes_plus
    Min_m = 00      'miniutes minius
    Sec_p = 00      'seconds plus
    Sec_m = 00'seconds minius
    hours = 0
    miniutes = 0
    seconds = 0
    
 For x = 0 To 7     //set all portc LED off
 PORTC.bits(x) = 0
 Next   
    
    While (true)
    
    
    if SWT_0 = 0 then hours = (Hours + 1) end if    //add 1 hour
    if hours > 12 then hours = 0 end if             //12 hour limit
    if SWT_1 = 0 then Hours = (hours - 1) end if    //subtract hours
    if hours > 12 then hours = 0 end if
    
        if swt_3 = 0 then miniutes = (miniutes + 1) end if
        if miniutes >= 60 then hours = hours + 1 miniutes = 0 end if      //add 1 to hours
        if swt_4 = 0 then miniutes = (miniutes - 1) end if
        
            if swt_5 = 0 then seconds = (seconds + 1)  end if   //add seconds
            if seconds = 60 then miniutes = miniutes + 1  seconds = 0 end if
            if swt_6 = 0 then seconds = (seconds - 1) end if   //subtract seconds
           ' if seconds < 0 then seconds = 0 end if
    
    
 
     WriteAt(1,1,"HRS   MIN   SEC")
     writeat(2,1,"                 ")   //redresh display
      WriteAt(2,3,DecToStr(hours))
      WriteAt(2,7,DecToStr(miniutes))
      writeat(2,11,dectostr(seconds))
      DelayMS(300)
   ' If SWT_0 = 0 Then
    'LED0 = 1
    'For x = 0 To 7
     '   PORTC.bits(x) = 1
      '  DelayMS(1000)
       ' PORTC.bits(x) = 0
        'DelayMS(1000)
        'Next
        
 Wend
this code is clunky but it works for hours and miniutes.
 
How to show you don't understand basic concepts without saying so.

Screenshot_20240110_162146_Edge.jpg



A quick glance shows some problems are edge cases.
 
The part I pictured will do the job – it just shows a fundamental lack of understanding.

The "edge cases" I refer to are around incrementing and decrementing where carries are involved. I think some of the less than / greater than tests are backwards. Sometimes people fail to test what happens at the edges.
 
For MrDEB education, let me explain my above comment.

Code:
For x = 0 To 7     //set all portc LED off
 PORTC.bits(x) = 0
 Next

This loop runs through 8 times and generates a whole lot of machine code to set each bit of PortC to zero.

This command does the same thing in one step.

Code:
PortC = %00000000

The percent sign indicates a binary number of 8 bits, all set to zero.

%00000000 (binary) = 0 in decimal.

Code:
PortC = 0

Same result as above. All bits set to zero.



Let's say you wanted to make all the outputs high to turn all the LEDs on. A similar loop could do it.

Code:
For x = 0 To 7     //set all portc LED off
 PORTC.bits(x) = 1
 Next

But it would be easier to use this.

Code:
PortC =:%11111111

The binary number sets all bits to 1 in one step.

What does this do?

Code:
PortC = 255

256 is the decimal number equal to %11111111, so it sets all eight bits to 1.

What about this?

Code:
PortC = $FF

The $ indicates a hex number. F = %1111 in binary, so FF =:%11111111. Same thing again. All LEDs on in one step.


Finally, before I go back to sleep, think about what this would do.

Code:
While 1 = 1

     PortC = %10101010

     DelayMS(1000)

     PortC = %01010101

     DelayMS(1000)

Wend

Think it through. It's not difficult.
 
Last edited:
thanks will make corrections as noted
Well I got this simple code to work so far. Now to get it to countdown is my next step
Code:
Device = 18F43K22
Clock = 16
// int osc and IO pin libraries
Include "intosc.bas"

#option DIGITALIO_INIT = true       // automatically call setalldigital
Include "setdigitalio.bas"

#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
Include "LCD.bas"
Include "convert.bas"
Include "utils.bas"
//SWITCHES
Dim SWT_0 As PORTB.0
Dim SWT_1 As PORTB.1
Dim SWT_2 As PORTB.2
Dim SWT_3 As PORTB.3
Dim SWT_4 As PORTB.4
Dim SWT_5 As PORTB.5
Dim SWT_6 As PORTB.6
Dim SWT_7 As PORTB.7

//LEDS

Dim led0 As PORTC.0  //HOURS+
Dim led1 As PORTC.1  //HOURS-
Dim led2 As PORTC.2  //MINIUTES+
Dim led3 As PORTC.3  //MINIUTES-
Dim led4 As PORTC.4  //SECONDS+
Dim led5 As PORTC.5  //SECONDS-
Dim led6 As PORTC.6
Dim led7 As PORTC.7

Dim x As Byte
Dim TIME As Byte

Dim Hours As Byte
Dim Miniutes As Byte
Dim seconds As Byte


//Dim Timeer_value String
sub Debounce()
    delayms(50)
    end sub
    
  // set switch port to inputs and enable pullups
    TRISB = $ff                // set as inputs
    WPUB = $ff                // enable pullups on all PORTB pins
    INTCON2.bits(7) = 0        // set bit RBPU = 0 turns on pullups
    TRISC = 0                                                       
    TRISA = 0
    TRISD = 0
    

    Hours = 0
    Miniutes = 0
    seconds = 0
    
 For x = 0 To 7     //set all portc LED off
 PORTC.bits(x) = 0
 Next   
    
    While (true)
    
    
    If SWT_0 = 0 Then Hours = (Hours + 1) debounce()End If     //add 1 hour   
    If Hours > 12 Then Hours = 0 End If             //12 hour limit
    If SWT_1 = 0 Then Hours = (Hours - 1) debounce()End If    //subtract hours\
    If Hours > 12 Then Hours = 0 End If
    
        If SWT_2 = 0 Then Miniutes = (Miniutes + 1) debounce()End If
        If Miniutes >= 60 Then Hours = Hours + 1 Miniutes = 0 End If      //add 1 to hours
        If SWT_3 = 0 Then Miniutes = (Miniutes - 1) debounce()End If
        
            If SWT_4 = 0 Then seconds = (seconds + 1) debounce() End If   //add seconds
            If seconds >= 60 Then Miniutes = Miniutes + 1 seconds = 0 End If
            If SWT_5 = 0 Then seconds = (seconds - 1) debounce()End If   //subtract seconds
            if seconds < 0 then seconds = 0 end if
    
    
 
     WriteAt(1,1,"HRS   MIN   SEC")
     WriteAt(2,1,"                 ")   //redresh display
      WriteAt(2,3,DecToStr(Hours))
      WriteAt(2,7,DecToStr(Miniutes))
      WriteAt(2,11,DecToStr(seconds))
      DelayMS(300)
        
 Wend
 

New Articles From Microcontroller Tips

Back
Top