/*
* Project name:
Custom Motor Controller FWD, RWD STOP
* Copyright:
None
* Description:
A start switch is pressed and the motor begins to rotate forwards until a
limit switch is hit, then the motor reverses back to initial position
*/
#define motorCtrlLineA GPIO.F0
#define motorCtrlLineB GPIO.F1
#define startSwitch GPIO.F2
#define limitSwitch GPIO.F3
// Global scope vars
char motorRun = 0;
char lSWCount = 0;
void main()
{
ANSEL = 0; // Configure AN pins as digital
CMCON = 7; // Turn off the comparators
TRISIO = 0b00001100; // configure pins of GPIO
GPIO = 0; // Clear port ...
while(1)
{
if (motorRun == 0) // Flag set denoting that motor is on?
{
if (startSwitch == 0) // User press start switch?
{
motorRun = 1; // Flag on denoting that motor is running
}
}
else // :: Motor running FORWARDS until limit switch is hit :: //
{
if (lSWCount == 0)
{
// Rotate motor forwards
motorCtrlLineA = 1;
motorCtrlLineB = 0;
// Limit switch it?
if (limitSwitch == 0)
{
lSWCount = 1; // Set flag denoting that motor is to be reversed
}
}
else // :: Motor running BACKWARDS until limit switch is hit :: //
{
// Reverse motor
motorCtrlLineA = 0;
motorCtrlLineB = 1;
// Limit switch it? Cease operation if so
if (limitSwitch == 0)
{
// Motor off
motorCtrlLineA = 0;
motorCtrlLineB = 0;
// reset vars ready for next cycle
motorRun = 0;
lSWCount = 0;
}
}
}
}
}
What's a 16F629? Microchip doesn't make one of those.A 16F629 is like a 2-cent part if you know the right people?
There is logically no need with the way in which it is coded.plus you havnt taken switch bounce into consideration......
while(1)
{
if (motorRun == 0) // Flag set denoting that motor is on?
{
if (startSwitch == 0) // User press start switch?
{
motorRun = 1; // Flag on denoting that motor is running
}
}
here's the parts list for my design:That works out overall being so much cheaper. That software took me like 30 mins to write. Much faster. Much easier. Far more manageable.
You'd have to have rocks in your head to do it any other way.
It is a different way of thinking altogether. You lose one old skill set and gain a new when you cross over. I used to be better with discrete and not so good with micros, now it is the other way around!But I guess I must (?) admit that things always become at least 10X cooler when you unnecessarily throw a microcontroller into the mix.
I've played around with arduino plenty and I like it alot. I have been on the cusp of buying a PIC programmer for over a year now; I keep getting to the point where I think my arduino won't handle the application and I have no choice, and then I find another way.It is a different way of thinking altogether. You lose one old skill set and gain a new when you cross over. I used to be better with discrete and not so good with micros, now it is the other way around!
by Aaron Carman
by Jake Hertz
by Aaron Carman