I posted how to interface a a relay a while back, the LTSpice simulation and circuit.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
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.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
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.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!
by Jake Hertz
by Jake Hertz
by Duane Benson
by Aaron Carman