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.

Timer Problem

Status
Not open for further replies.

moki

New Member
I need help. I built a circuit using a PIC16f628 for timing. On power up a relay must be energised after a delay set on a dip switch (RA1, RA2, RA3). A microswitch is connected on RA0. When the microswitch is closed momentarily, the relay must switch off for a time period set on a dip switch (RA4, RA5, RA6), and then switch on again. I have written the program in assembler. It seems to work in the MPLAB simulator, but when I program the chip and use it in circuit strange things seem to happen. The timing does not seem to function. The relay (on RB1) does not come on unless RA1, RA2 and RA3 is high. The dip switches have 10k pull up resistors. I have attached the code. After spending many hours on this I am not sure what is wrong. Any help will be apperciated! The time code was generated by the Delay Code Generator found on the PICLIST.
 

Attachments

  • SM_timer.zip
    1.8 KB · Views: 94
Your code is quite hard to follow as you use actual locations rather than labels for variables.

Variables are normally placed in the cblock area and so you would give your variables sensible names such as Multiplier for the time multiplier location,
Code:
		cblock	0x20	;start of general purpose registers
		d1		;used in BaseTime 30 sec delay routine
		d2		;used in BaseTime 30 sec delay routine
		d3		;used in BaseTime 30 sec delay routine
[COLOR="Blue"]		Multiplier	;used to count number of 30 sec delays[/COLOR]
		endc

You can then use,
Code:
Time5		movlw	5h		;put value of 5 in time register (29)
		movwf	Multiplier	;instead of 0x29
		call	BaseTime	;call timer routine
		retlw	00		;return

You are also using a very long winded way to convert A1-A3 into a variable delay. This is how I would do it,
Code:
PowerOn_Time
		rrf	PORTA,W		;move porta bit 1-3 into W bit 0-2
		andlw	b'00000111'	;keep only the lower bits
		addlw	1		;add 1 so 0 to 7 becomes 1 to 8
		movwf	Multiplier	;this is how long to delay
DelayLoop	call	Delay30		;delay for 30 seconds
		decfsz	Multiplier,F	;repeat x times
		goto	DelayLoop	;not finished so loop
		return			;finished so return

As to why your code isn't working I don't know.
Some suggestions,
Have you got decoupling capacitors?
Have you put a diode across the relay?
Is your supply good enough to power the relay?

Maybe you could post a diagram or picture of your circuit.

HTH,

Mike.
 
Thanks for the help. I managed to get my original program working. The problem was the programmer. I am using a TOPWIN programmer - TOP2004 (Chinese). Not sure what this thing is doing. I eventually programmed the micro with my home built programmer and Nigel Goodwin's software (never fails to work!) and it worked. I then implemented the changes which u suggested - nice , neat and compact!

The TOPWIN programmer is doing something with the configuration word. When I read the micro back, the config seems to have changed. I still got to figure this one out. I don't know if anyone else has had any experience with this programmer.

Nigel's WinPicProg is still tops!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top