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.

User defined Time period 16f628

Status
Not open for further replies.

jagrolet

New Member
I'm trying to find an example of some assembly code for a PIC timer that will remember a user defined time. Example: User holds down a button for X time and that time is stored in EEPROM.
Now user presses a button and an led lights for the time stored in the EEPROM.
Timer would be approx 1 min. max time and I would like to have 1/8 sec. or better resolution.
I'm using a 16F628A but an example for 16f84 is fine.
Has anyone seen on the web or have a tutorial for lighting an LED for a user specified time period?
 
Hi there,

To start with,

Do you have a circuit diagram?

From your description the software would be very simple. I would suggest you have a good read of the microchip datasheet. You will probably find that all the information you need is all there.

Finding a program that someone else has done would probably be difficult for exactly what you are trying to do.

Once you have read the datasheet imperticular EEPROM reading and writing then try putting a program together yourself and then post any questions you may have about your code on here. That way people may feel more inclined to help.

If you like you like I can help on a one to one. If so just contact me via email to arrange.

Pete@customsoft.karoo.co.uk

All the best

Pete
 
Yes, I do have a circuit. I'm trying to add functionality to an existing program I wrote. 16f628 at 4 MHZ, with 8 LEDS on Port B and Two switches on Port A and a relay on Port A.
Pressing 1 button cycles thru the LEDS which have various timing routines in code, and then pressing the other button activates a relay for that time period. I wanted to add a user defined time period to one of the LEDs.
I think I can handle the Read and write EEPROM part. I have seen many examples of that. My biggest issue is creating a fraction of a second timer and counting how many 1/8th seconds have passed by, and storing a number larger than 256 in the EEPROM. I figured someone had done something similar to this or could show an example/tutorial of a blinking LED with user defined times. Im not looking for someone to write the code for me. I love learning this stuff. Thanks.
 
You can store a number larger than 256 by using more than one byte - or, you could store it as one byte, where each increment represents a specific time period (like 1 equals 1 second, 2 equals 2 seconds etc.).
 
I would try and use one of the chip's timer modules to generate an interrupt that incremented a tick_count variable which you could use for getting the timing data. Preferably one with a decent 16 bit register like TIMER1.

To do this you would need to add initialisation to enable the timer, and the GIE global interrupt enable, INTCON register to name another register. You may also need to re-structure the code start address to be after the interrupt vector at address 0x04 and add a jump instruction to skip past the interrupt code if interrupts are not already being used.

From what you say you really wouldn't need to worry too much about the precise reload value of the timer as long as you slow it down enough that it gives you the max length of time period without overflowing your tick_count, but not too slow that it ticks less than your required 8 times a second.

You will probably need a 16 bit tick_count variable as 256 1/8ths of a sec is .......32
- edit acutally that might be ok, but i prefer overkilling it.. go for 50ms interrupts and 16bit counter :)

To program a time.. zero tick_count when the button press is detected. Save the count when it is released.
To replay the time, zero the tick_count at the start and compare against the saved value.

Really, all of what you need is in the PIC datasheet for the chip :cool:
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top