Please help my son! 16F628A timer circuit/program

killivolt

Joined Jan 10, 2010
835
Soon maybe your son can run programs to control Trains or something. Could be a fun project.



Regards,
kv
 
Last edited:

Thread Starter

Tigthwad

Joined Oct 27, 2009
31
Just an update. The code is working so far. My son went a bit wild and added 6 LED in a Red/White/Blue/Red/White/Blue circle and is making them loop around. He got to learn how to divide the delay up so he could have 7 states for the LEDs to be in to make them appear to be looping. He also got to learn how to adjust the delay for the relay to account for different sized wheels to cover the same distance....and he thought he wouldn't really need Algebra!

He is working on the hardware now...moving the bits to a circuit board and soldering everything (using a socket for the chip to protect it and allow it to be changed if needed). I will post a picture when he is done.

His final bit I need to learn more about....how to control the angle of a servo based on the timer (set angle and hold it, set back to baseline when timer runs out etc).
 

thatoneguy

Joined Feb 19, 2009
6,359
Task list:
Add relay to circuit and make sure it functions as intended
find out what a prescaler is and how to compute it
find out how an interrupt is incorporated and write them as needed
I posted how to interface a a relay a while back, the LTSpice simulation and circuit.

A prescaler is for counting. uCs run on a clock that is fast (MHz speed). If you don't want to make event happen every 200 microseconds, you need a prescaler, all that means is "scale" the clock to a lower frequency. e.g. for every 255 pulses in, output one pulse, the timer now has slowed down a great deal.

Interrupts are intricate, but simple once you know the concept. They can interrupt the main() loop at any time based on an event, run some code (short as possible in the Interrupt Service Routine/ISR), then it returns to running the main code exactly where it left off. Use of interrupts is an excellent way to stop wasting processor cycles in delay statements, or continually polling a port. There are many tutorials around that explain interrupts, even on this forum.

Glad you have the first part working!
 

t06afre

Joined May 11, 2009
5,934
Good to hear you made it to the finishing line. As I understood the deadline was to day. Learning programming is much to take things step by step. Not try to understand everything at the same time
 

Thread Starter

Tigthwad

Joined Oct 27, 2009
31
Good to hear you made it to the finishing line. As I understood the deadline was to day. Learning programming is much to take things step by step. Not try to understand everything at the same time
Yeah, he had to have a working prototype, which he did. Learned some interesting things...the car wasn't running straight and it turned out the weight of the 9v battery was too far off center and caused the car to drift...very strange.

It will be interesting as he builds the circuit...his soldering skills are limited and he will get to learn a lot about order of placement etc.
 

Thread Starter

Tigthwad

Joined Oct 27, 2009
31
I posted how to interface a a relay a while back, the LTSpice simulation and circuit.

A prescaler is for counting. uCs run on a clock that is fast (MHz speed). If you don't want to make event happen every 200 microseconds, you need a prescaler, all that means is "scale" the clock to a lower frequency. e.g. for every 255 pulses in, output one pulse, the timer now has slowed down a great deal.

Interrupts are intricate, but simple once you know the concept. They can interrupt the main() loop at any time based on an event, run some code (short as possible in the Interrupt Service Routine/ISR), then it returns to running the main code exactly where it left off. Use of interrupts is an excellent way to stop wasting processor cycles in delay statements, or continually polling a port. There are many tutorials around that explain interrupts, even on this forum.

Glad you have the first part working!
I need to keep on this for myself...for him the code works and while it isn't efficient he has enough overhead that it doesn't matter...he isn't trying to do multiple processes together. Wrapping my head around it will be the first step.
 

Thread Starter

Tigthwad

Joined Oct 27, 2009
31
Just wanted to give a quick update for all those who helped out on this project. My son completed his circuit and his program in time for the initial competition. The timer worked exactly as needed! They had an initial scare when they learned their laser targeting system used to account for the slight arc the car traveled in was not allowed. They came up with a last minute manual solution involving a bit of sticky note and were able to carry on successfully. They won first place and are progressing on to the state level.
 
Top