16F628A - Stops if release power switch.


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Feb 2009
    Posts
    7

    Default 16F628A - Stops if release power switch.

    I have a led chaser based on 16F628A, all A's and B's as outputs [12 leds].
    The sequence starts and... stops if i release the push button which power it, but the PIC can't keep power for itself after releasing the switch.
    I want it to execute the sequence after a short push of a button.

    What is to be done in the asm file ??

    Thanks in advance.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    change line 14 of your code...

    Does it work?

    Oh well, if we had code and schematic we could have found the problem even in ASM in a Melabs PICBasic Pro forum
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Feb 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default This is your chip speaking...

    Overdone sarcasm aside, you really do need to post the salient details if you expect any sort of helpful answer.

  4. #4
    Join Date
    Feb 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Code

    Sorry, i thought it can be simply added to whatever code...

    Here is my messy code. I couldn't have done it better. Any help would be very welcome, i needed 12-15 days of study of this pic&mpasm&icprog&stuff just to get to this level, i'm not blind yet but not far... Hope not to make an attack because of so much sitting, omg.

    It only gives some warnings, no errors and it works;

    So, the problems are;
    -1. the code does not allow the PIC to power itself and the sequence stops when i release the pushbutton that powers it. Need to fix that or i will need to sacrifice an output [12 leds] to power an electromagnetic relay etc, etc. I need it to "play" the sequence only once, after a "short touch" of a push button [not retaining]. At this moment, it plays the seq. for 8 times, don't know why... althoug no looping is specified...
    - 2. i need to "group" 2 or more delays in a shorter way; ex. "call delay 10x"... Actually, the code contains much longer delays.
    - 3. code is horrible, need help to optimize it, correct it and maybe simplifying it, without loosing the ability to preciselly&independently control al the leds.

    Thanks for your kindness, i hope my english is good enough, i'm in Romania
    .
    Code:
    	LIST	p=16F628		;tell assembler what chip we are using
    	include "P16F628.inc"		;include the defaults for the chip
    	__config 0x3D18			;config settings (osc. type etc.)
    	cblock 	0x20 			;start of general purpose registers
    		count1 			;used in delay routine
    		counta 			;used in delay routine 
    		countb 			;used in delay routine
    	endc
    	LEDA0	       Equ	0		;set constant LED = 0
    	LEDPORTA0     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA1	       Equ	1		;set constant LED = 1
    	LEDPORTA1     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA2	       Equ	2		;set constant LED = 2
    	LEDPORTA2    Equ	PORTA		;set constant LEDP0RT = 'PORTA'
    	LEDA3	       Equ	3		;set constant LED = 3
    	LEDPORTA3     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA4	       Equ	4		;set constant LED = 4
    	LEDPORTA4     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDA5	       Equ	5		;set constant LED = 5
    	LEDPORTA5     Equ	PORTA		;set constant LEDPORT = 'PORTA'
    	LEDB0	       Equ	0		;set constant LED = 0
    	LEDPORTB0     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB1	       Equ	1		;set constant LED = 1
    	LEDPORTB1     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB2	       Equ	2		;set constant LED = 2
    	LEDPORTB2     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB3	       Equ	3		;set constant LED = 3
    	LEDPORTB3     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB4	       Equ	4		;set constant LED = 4
    	LEDPORTB4     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB5	       Equ	5		;set constant LED = 5
    	LEDPORTB5     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB6	       Equ	6		;set constant LED = 6
    	LEDPORTB6     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDB7	       Equ	7		;set constant LED = 7
    	LEDPORTB7     Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDPORT	Equ	PORTB		;set constant LEDPORT = 'PORTB'
    	LEDTRIS	Equ	TRISB		;set constant for TRIS register
    	org	                0x0000		;org sets the origin, 0x0000 for the 16F628,
    					;this is where the program starts running	                LEDTRIS	    Equ	TRISB		;set constant for TRIS register
    	movlw	    0x07
    	movwf	    CMCON			;turn comparators off (make it like a 16F84)
       	bsf 	    STATUS, RP0	               ;select bank 1
                    clrf	   TRISA	                               ;set PortA all outputs
       	movlw 	    b'00000000'	               ;set PortB all outputs
       	movwf 	    LEDTRIS
    	bcf	    STATUS, RP0	               ;select bank 0
    ;--------------------------------------------------------------------------------
    Loop
                    BSF	LEDPORTA0, LEDA0	                ; RA0 ON
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
    
    	call	Delay	
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	call	Delay
               	movlw	b'11111111'
    	movwf	LEDPORT
    	call	Delay	
    	call	Delay
    	call	Delay
    	
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT
    	call	Delay
    	call	Delay
               	movlw	b'00010000'
    	movwf	LEDPORT	
    	call	Delay
               	movlw	b'00001000'
    	movwf	LEDPORT	
    	call	Delay
               	movlw	b'00010000'
    	movwf	LEDPORT	
    	call	Delay
               	movlw	b'00000000'
    	movwf	LEDPORT	
    	call	Delay
    	call	Delay	
    	   bcf	    LEDPORTA0, LEDA0	                    ; RA0 off
    ;-------------------------------------------------------------------------------------
    
    Delay	movlw	d'250'			;delay 250 ms (4 MHz clock)
    	movwf	count1
    d1	movlw	0xC7
    	movwf	counta
    	movlw	0x01
    	movwf	countb
    Delay_0
    	decfsz	counta, f
    	goto	$+2
    	decfsz	countb, f
    	goto	Delay_0
    
    	decfsz	count1	,f
    	goto	d1
    	retlw	0x00
    	end

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    I'm not sure if this is what you're looking for. I think there should be an END statement just above the Delay routine or a GOTO loop if you want to repeat the sequence.

    Code:
    	movwf	LEDPORT	
    	call	Delay
    	call	Delay	
    	   bcf	    LEDPORTA0, LEDA0	                    ; RA0 off
                 
                 END  ; if you want to stop right here
                 GOTO loop   ; if you want to repeat some section of code.  Ofcourse you have to 
                                  ; put the label 'loop' where you want it.
    ;-------------------------------------------------------------------------------------
    
    Delay	movlw	d'250'			;delay 250 ms (4 MHz clock)
    	movwf	count1

  6. #6
    Join Date
    Feb 2009
    Posts
    4


    Did you find this post helpful? Yes | No

    Default

    So far, so good. We need a schematic to solve problem #1, however.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by dene12 View Post
    I have a led chaser based on 16F628A, all A's and B's as outputs [12 leds].
    The sequence starts and... stops if i release the push button which power it, but the PIC can't keep power for itself after releasing the switch.
    I want it to execute the sequence after a short push of a button.

    What is to be done in the asm file ??

    Thanks in advance.

    a working solution :

    Keep the chip under power but in sleep mode ... you cut the power ... circuit resets and execute the chasing sequence.

    Then falls asleep.

    trick used for mini Led Torch lamps.



    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Alain,

    Weird you would say that - see attached...;o}

    dene12,

    See the attached example for one way. Note this doesn't help for your power button. The PIC needs power to operate, so just power it all the time, and give the attached example a whirl. Place a pull-up resistor on /MCLR. When you press your button it should ground the /MCLR pin.

    Note: You'll get faster responses for assembly code on the Microchip forum. If you need to tweak the example attached, visit http://forum.microchip.com/

    We normally stick to PBP BASIC around here...;o}
    Attached Files Attached Files
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink

    Hi, Bruce

    Some times ago on this Forum, we had been working on a 12F683 project for Argentina ... for "PEU" some moderator of the "CandlePower Forum".

    http://www.candlepowerforums.com/vb/....php?p=2410929

    His little shop is worth the look ...


    BTW. This "config" really works great ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    Join Date
    Feb 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Jerson, it's not working.
    Really, the last 15 lines of my sequence are crucial. I knew that before your message, but i also tried your solution and of course it did not want to take it, it gave 30 errors ! ... are crucial, don't know FOR WHAT, lol, but are crucial, haha. OMG i'm finished

    Here is my schematics;


    Thanks everybody.
    Let's see now, it's a very simple circuit. I need to solve problem 1, at least.
    Attached Images Attached Images  

  11. #11
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Alain,

    Really cool looking flashlights, but I'm not sure I would spend $180 on one..;o}

    Edit: Dene12,

    If you're using an external oscillator, and the "A" version, you'll need the modified version.

    Note your original config had it set for internal osc.
    Attached Files Attached Files
    Last edited by Bruce; - 10th February 2009 at 18:20. Reason: Using the "A" version with external osc
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  12. #12
    Join Date
    Feb 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Bruce, nice, thank you very much.
    Very nice.
    Just nice, from assembling without errors and warnings to the sequence and
    finally grouping the delays with " execute delay this number of times". Cool.
    Today i love electronics.

    I'll wait for some more answers to see if problem 1 will be completely solved, although grounding MCLR and that "sleep mode until /MCLR reset"..., almost solve the problem, looks very good ALREADY.

    Thanks again, Bruce.

  13. #13
    Join Date
    Feb 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Bruce, chaser2.asm makes the MCLR pin ssso sensible it turn the A0 led ON by just hovering the hand over the pic at about 15 cm... The circuit has transformed into a kind of "human bioelectric field detector" effective up to 15 cm
    This happened after i attached a wire to MCLR pin. The wire is now "in the air" and was intended to connect the pin to a PCB switch, but only by soldering it to MCLR pin it made everything uncontrolable...
    Before soldering the wire, the sequence was able to be started by only touching the MCRL pin with a metal, without even being conected to the GND.

    I only have here now some variable resistors 0-3K... you said something about a pull-up resistor, which i don't even imagine its shape... and function.
    Can you help ?
    This is the code chaser2;

    Code:
        LIST  p=16F628A         ;tell assembler what chip we are using
        include "P16F628A.inc"   ;include the defaults for the chip
        
        ;__config 0x3D18         ;config settings (osc. type etc.)
    
        ; similar to above with /MCLR enabled (for reset), XT osc (not internal). power-up timer on,
        ; and now you know at a glance what your config settings are.
    
        __CONFIG _CP_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _XT_OSC
    
        cblock 0x20  ;start of general purpose registers
          count1     ;used in delay routine
          counta     ;used in delay routine 
          countb     ;used in delay routine
          times      ;number of times to execute Delay loop
        endc
    
    LEDA0	    Equ  0     ;set constant LED = 0
    LEDPORTA0   Equ  PORTA ;set constant LEDPORT = 'PORTA'
    LEDA1	    Equ  1     ;set constant LED = 1
    LEDPORTA1   Equ  PORTA ;set constant LEDPORT = 'PORTA'
    LEDA2	    Equ  2     ;set constant LED = 2
    LEDPORTA2   Equ  PORTA ;set constant LEDP0RT = 'PORTA'
    LEDA3	    Equ  3     ;set constant LED = 3
    LEDPORTA3   Equ  PORTA ;set constant LEDPORT = 'PORTA'
    LEDA4	    Equ  4     ;set constant LED = 4
    LEDPORTA4   Equ  PORTA ;set constant LEDPORT = 'PORTA'
    
    ; NOTE: Removed below because RA5 = INPUT only on 16F628
    ; LEDA5	    Equ  5     ;set constant LED = 5 
    ; LEDPORTA5   Equ  PORTA ;set constant LEDPORT = 'PORTA'
    
    LEDB0	    Equ  0     ;set constant LED = 0
    LEDPORTB0   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDB1	    Equ  1     ;set constant LED = 1
    LEDPORTB1   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDB2	    Equ  2     ;set constant LED = 2
    LEDPORTB2   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDB3	    Equ  3     ;set constant LED = 3
    LEDPORTB3   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDB4	    Equ  4     ;set constant LED = 4
    LEDPORTB4   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDB5	    Equ  5     ;set constant LED = 5
    LEDPORTB5   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDB6	    Equ  6     ;set constant LED = 6
    LEDPORTB6   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDB7	    Equ  7     ;set constant LED = 7
    LEDPORTB7   Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDPORT     Equ  PORTB ;set constant LEDPORT = 'PORTB'
    LEDTRIS     Equ  TRISB ;set constant for TRIS register
    	
       org     0x0000   ;org 0 for the 16F628
    
       banksel PORTB    ;select bank 0
       movlw   0x07
       movwf   CMCON    ;turn comparators off (make it like a 16F84)
       clrf    PORTB    ;clear all port latches before setting TRIS regs
       clrf    PORTA
    
       banksel TRISA    ;select bank 1
       movlw   b'00100000'
       movwf   TRISA    ;set PortA outputs, RA5 = /MCLR input
       clrf    TRISB    ;set PortB all outputs
    
       banksel PORTB    ;select bank 0
    
    ;----------------------------------------------------------------------
    
    Loop
       BSF    LEDPORTA0, LEDA0  ; RA0 ON
       movlw  d'4'    ; execute delay this number of times
       movwf  times    
       call   Delay
    
       movlw  b'11111111'
       movwf  LEDPORT
       movlw  d'4'    ; execute delay this number of times
       movwf  times    
       call   Delay
    
       movlw  b'00000000'
       movwf  LEDPORT
       movlw  d'4'     
       movwf  times
       call   Delay
    
       movlw  b'11111111'
       movwf  LEDPORT
       movlw  d'4'
       movwf  times    
       call	  Delay
       
       movlw  b'00000000'
       movwf  LEDPORT
       movlw  d'4'
       movwf  times    
       call	  Delay
    
       movlw  b'11111111'
       movwf  LEDPORT
       movlw  d'4'
       movwf  times    
       call	  Delay
    
       movlw  b'00000000'
       movwf  LEDPORT
       movlw  d'4'
       movwf  times   
       call	  Delay
    
       movlw  b'11111111'
       movwf  LEDPORT
       movlw  d'4'
       movwf  times    
       call	  Delay
    
       movlw  b'00000000'
       movwf  LEDPORT
       movlw  d'4'
       movwf  times    
       call	  Delay
    
       movlw  b'00010000'
       movwf  LEDPORT
       movlw  d'1'
       movwf  times    
       call	  Delay
    
       movlw  b'00001000'
       movwf  LEDPORT	
       movlw  d'10'
       movwf  times   
       call	  Delay
    
       movlw  b'00010000'
       movwf  LEDPORT	
       movlw  d'1'
       movwf  times      
       call	  Delay
    
       movlw  b'00000000'
       movwf  LEDPORT	
       movlw  d'4'
       movwf  times       
       call   Delay	
       bcf    LEDPORTA0,LEDA0  ; RA0 off
       
       ; code above executes once, then PIC enters low-power sleep mode until /MCLR reset.
    
    SleepLoop 
       SLEEP            ; enter low power sleep
       GOTO   SleepLoop ; go back to sleep if it wakes up
    ;-------------------------------------------------------------------------------------
    
    Delay
       movlw   d'250'    ;delay 250 ms (4 MHz clock)
       movwf   count1
    
    d1
       movlw   0xC7
       movwf   counta
       movlw   0x01
       movwf   countb
    
    Delay_0
       decfsz  counta,f
       goto    $+2
       decfsz  countb,f
       goto    Delay_0
       decfsz  count1,f
       goto    d1
       decfsz  times    ; execute delay this number of times
       goto    Delay
    
       retlw   0x00
       
       end

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    A pull-up resistor is just a simple resistor connected between a pin (MCLR) and Vdd.
    http://www.seattlerobotics.org/encod...97/basics.html

    Everything bellow 22K would work. Usually 10K for me (in many case).
    Last edited by mister_e; - 10th February 2009 at 22:28.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Feb 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Can't do it.

    It's totally uncontrollable, even with the pull-up resistor.
    Then, I don't want 2 switches, there is nobody there to reset the pin.
    The sequence must start and play with just a push&release, very short and then must standby and wait another push-start instead reseting.

  16. #16
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default

    Too bad,

    We had a working solution ... but with PBP.

    Really sorry not to be able to help you further.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  17. #17
    Join Date
    Feb 2009
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Ace

    Quote Originally Posted by Acetronics View Post
    Too bad,

    We had a working solution ... but with PBP.

    Really sorry not to be able to help you further.

    Alain
    Alain, omg. I went back to your post with the working solution and i finally understood what you said... That post was posted before Bruce gave me the codes #1&#2 and at that time i was unable to think clearly.
    Ace, thanks for coming back, this time i did it; a NC push button on Vdd powering the chip and that was it. omg it was easy.
    Merci, Alain, thanks for coming back, omg.

    Thanks everybody subject closed; this configuration is good for a half million applications, even for tech processes which are not so complex.

Similar Threads

  1. Switch mode power supply Pic Micro
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th July 2009, 14:11
  2. Battery powered applications
    By NavMicroSystems in forum Off Topic
    Replies: 7
    Last Post: - 22nd June 2009, 08:12
  3. Replies: 3
    Last Post: - 29th April 2009, 01:45
  4. 'Soft' On/Off Power Switch
    By Art in forum General
    Replies: 19
    Last Post: - 14th November 2008, 02:54
  5. Newbie - 16F628A and switch latching
    By malc-c in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 19th May 2006, 03:35

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts