3 volt instant on - 3-5 minutes delay off for simple model train (non energized tracks)

Discussion in 'The Projects Forum' started by advarp, Jan 12, 2018.

  1. crutschow

    Expert

    Mar 14, 2008
    19,122
    5,344
    That's fine if you have the programming hardware and know how to program a PIC.
     
    be80be likes this.
  2. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    5,909
    1,384
    Yes, probably the best solution.
     
  3. advarp

    Thread Starter Member

    Jan 12, 2018
    50
    1
    Excellent, thank you!

    be80be, re the PIC, what would the schematic look like? And I would need to program it I assume? Never done that, might look up what I would need. I know about programming (probably not for PIC though), but no time lately to play, just bought kits that wait for.. retirement probably...
     
    Last edited: Jan 13, 2018
  4. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    6,901
    1,962
    That's probably because you know what a 10F200 is and you have a development system and a compiler and a programmer and programming experience - all of that assuming that a 10F200 is a programmable device of some kind..

    ak
     
  5. advarp

    Thread Starter Member

    Jan 12, 2018
    50
    1
    Programming hardware seems to be around $10 from Ebay China plus a PC and some software... But some specific advice about all this (including schematic)would be great. Can anyone program the chip for me for a nominal fee :)
     
  6. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,645
    317
    I'd send you one programed for postage and $1 for the chip
    Screenshot from 2018-01-14 00-24-08.png
     
    Last edited: Jan 14, 2018
  7. advarp

    Thread Starter Member

    Jan 12, 2018
    50
    1
    Woo-hoo! I'll message you :)

    EDIT: I am an idiot but I can't find any messaging area. I received a message when i joined but that's it... If you can send me a message to reply to it would be great...
     
    Last edited: Jan 14, 2018
  8. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    5,909
    1,384
    Hover over the right hand end of the orange bar, and then move down to inbox. That's where the conversations are. You should see start a new conversation.
     
  9. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,645
    317
    Here a simple code that will work with the 10f200 it's a basic chip not much there so this uses a delay to get your 3 minutes
    Code (Text):
    1. /*
    2. * File:   newmain.c
    3. * Author: burt
    4. *
    5. * Created on January 15, 2018, 7:29 AM
    6. */
    7. // CONFIG
    8. #pragma config WDTE = OFF       // Watchdog Timer (WDT disabled)
    9. #pragma config CP = OFF         // Code Protect (Code protection off)
    10. #pragma config MCLRE = ON       // Master Clear Enable (GP3/MCLR pin function  is MCLR)
    11.  
    12. // #pragma config statements should precede project file includes.
    13. // Use project enums instead of #define for ON and OFF.
    14. #define _XTAL_FREQ 4000000
    15. #include <xc.h>
    16. void init (){
    17.     TRISGPIO = 0B00000001;
    18. }
    19. void main(void) {
    20.     init();
    21.     if (GP0 =1){
    22.         int i = 0;
    23.         do {
    24.          GP1 = 1;  // LED ON or motor for 3 minutes
    25.           __delay_ms(1000); // 1 Second Delay
    26.             i++;
    27.         }while (i<180); //sets on time
    28.          GP1 = 0;  // LED OFF or motor
    29.    
    30.     }
    31. }
    Download mplabx and xc8 from here https://www.microchip.com/mplab/mplab-x-ide
    The zip has the hex for the 10f200
    get a pickit3 these are fine https://www.aliexpress.com/item/PICKIT3-PIC-KIT3-PICKIT-3-Programmer-Offline-Programming-Simulation-PIC-Microcontroller-Chip-Monopoly/32794808295.html?src=google&albslr=223416562&isdl=y&aff_short_key=UneMJZVf&source={ifdyn:dyn}{ifpla:pla}{ifdbm:DBM&albch=DID}&src=google&albch=shopping&acnt=708-803-3821&isdl=y&albcp=653478879&albag=34653160498&slnk=&trgt=61865531738&plac=&crea=en32794808295&netw=g&device=c&mtctp=&gclid=Cj0KCQiAv_HSBRCkARIsAGaSsrAASemEXqHQkMEeIo5siITJgGOGwF1sGf0hr94ED1FjpONmBMB59zEaApidEALw_wcB
    and you should be ready to go
     
    Last edited: Jan 15, 2018
  10. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,645
    317
    One thing tho is the pickit 3 does not like powering the chip so power the 10f200 to program it
     
  11. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    5,909
    1,384
    I see three problems with that code.
    1. There are 180 seconds in 3 minutes not 160.
    2. There is a return from a void function (newmain).
    3. The button will only work once. The 'if' block should be wrapped in a while(forever) or similar.

    It would surely be better, to extend the battery life in the off state, to sleep the uC and have the button wake from sleep.
     
  12. LesJones

    Well-Known Member

    Jan 8, 2017
    1,296
    301
    There is a clever method that is used on the Banggood component tester that does not use the sleep function. It uses the start stop push button to initially supply power to the micro controller. The micro controller than switches on a transistor which then provides power to the micro controller until it times out. This is a link to the manual which contains the schematic on the last page. I have copied the idea for use with a timer using an ATtiny13.
    This is the schematic for my timer.
    Shutdown_timer_a.png



    I think it should be possible to modify it to work on 3 volts. When it is off there is only the CE leakage current of the switching transistor,

    Les.
     
  13. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,645
    317
    while (i<160); //sets on time the poster said 3 to 5
    I said set this to what you want sorry I forgot to set it back to 180 before posting
    I shorting it and it does work each press not just a one shot deal
    The code works the return is in the if statement it returns to main and starts again

    The xc8 said you can use return for more then a value Im using to start the if statement over.

    The hex will run 3 minutes and stop each press of the button

    The 10f200 you have to poll the timer there no T0IF So like i said I used a delay the code would be easy to test each loop for a press but I don't think anyone would do that with a train going around a track.
     
    Last edited: Jan 15, 2018
  14. AlbertHall

    AAC Fanatic!

    Jun 4, 2014
    5,909
    1,384
    How about sleeping the uC?
     
  15. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,645
    317
    How about he tries it first and then see's what he really want's to add.
    sleep not a big deal to add
     
    Last edited: Jan 15, 2018
Loading...