|
|
View previous topic :: View next topic |
Author |
Message |
vineel
Joined: 19 Apr 2016 Posts: 2
|
Help to fix this error undefined identifier Motor_M1_On |
Posted: Tue Apr 19, 2016 3:57 am |
|
|
Hi! i am writing a code for joystick based wheel chair, using pic16f73.
Everything is fine, but i am getting a set of errors such as undefined identifiers Motor_M1_On, etc., which are related to dc motor.
My code is as follows:
Code: |
#include <16F73.h>
#include <stdlib.h>
#include <Motor.h>
#fuses HS, NOWDT, BROWNOUT, PROTECT, PUT
#use delay(oscillator=20M)
unsigned long duty = 0;
void dowork(unsigned int x)
{
switch(x)
{
case 116:
if(!input(pin_A0))
{
set_pwm1_duty(700);
set_pwm2_duty(700);
Motor_M1_On(150,1); //1=forward, 0=reverse
Motor_M2_On(150,1); //1=forward, 0=reverse
}
break;
case 117:
set_pwm1_duty(700);
set_pwm2_duty(700);
Motor_M1_On(150,0); //1=forward, 0=reverse
Motor_M2_On(150,0); //1=forward, 0=reverse
break;
case 51:
Set_pwm1_duty(550); //fixed duty for turnings
Set_pwm2_duty(550); //fixed duty for turnings
output_high(PIN_C5);
Motor_M1_On(100,0); //1=forward, 0=reverse
Motor_M2 On(100,1); //1=forward, 0=reverse
break;
case 52:
set_pwm1_duty(550); //fixed duty for turnings
set_pwm2_duty(550); //fixed duty for turnings
output_high(PIN_C6);
Motor_M1_On(100,1); //1=forward, 0=reverse
Motor_M2_On(100,0); //1=forward, 0=reverse
break;
}
}
void Motor_M1(int direction)
{
delay_ms(10);
if(direction == 1) //Forward
{
output_low(PIN_C0);
output_high(PIN_C5);
}
if(direction == 0) //Reverse
{
output_low(PIN_C1);
output_high(PIN_C5);
}
delay_ms(100);
}
void Motor_M2(int direction)
{
if(direction == 1) //Forward
{
output_low(PIN_C0);
output_high(PIN_C6);
}
if(direction == 0) //Reverse
{
output_low(PIN_C1);
output_high(PIN_C6);
}
delay_ms(100);
}
void main()
{
unsigned long int x=0;
unsigned long int y=0;
//Microcontroller Health Check
output_high(PIN_C5);
output_high(PIN_C6);
delay_ms(1000);
output_low(PIN_C5);
output_low(PIN_C6);
delay_ms(1000);
output_high(PIN_C5);
output_high(PIN_C6);
delay_ms(1000);
output_low(PIN_C5);
output_low(PIN_C6);
setup_adc(ADC_CLOCK_INTERNAL); //enables the a/d module
setup_adc_ports(ALL_ANALOG); //sets all the adc pins to analog
//PWM Settings
setup_timer_2(T2_DIV_BY_16, 127, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(620);
setup_ccp2(CCP_PWM); //pwm setting for motor 2
set_pwm2_duty(620);
while(1)
{
set_adc_channel(1);
delay_ms(1);
y = read_adc();
delay_ms(1);
set_adc_channel(0);
delay_ms(1);
x = read_adc();
delay_ms(1);
set_pwm1_duty(600);
set_pwm2_duty(600);
if(y < 80)
{
output_high(PIN_C5); //LED on
Motor_M1(0);
Motor_M2(0);
}
else if(y > 100)
{
output_high(PIN_C6);
Motor_M1(1);
Motor_M2(1);
}
else if(x < 80)
{
output_high(PIN_C5);
Motor_M1(1);
Motor_M2(0);
}
else if(x > 100)
{
output_high(PIN_C6);
Motor_M1(0);
Motor_M2(1);
}
set_pwm1_duty(0);
set_pwm2_duty(0);
output_low(PIN_C5);
output_low(PIN_C6);
}
}
|
Can anyone help me to fix this and suggest me right header file for dc motor control ? _________________ vineel |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Apr 19, 2016 4:36 am |
|
|
At this simple level, with only a few routines, I'd suggest not using a header file at all.
The errors you describe are because the do-work routine calls routines that are not defined/declared. But that's no more than the error message says so that should nto be a surprise.
It doesn't matter that you don't call do_work() anywhere; if it's there at all, the routines it calls, such as Motor_M1_On and Motor_M2_On, have to be defined somewhere and they aren't.
It sounds as if you are confused over basic C code structure: how, why and where routines are defined. For that you need to read a C language book or tutorial. |
|
|
vineel
Joined: 19 Apr 2016 Posts: 2
|
|
Posted: Tue Apr 19, 2016 4:48 am |
|
|
RF_Developer wrote: | At this simple level, with only a few routines, I'd suggest not using a header file at all.
The errors you describe are because the do-work routine calls routines that are not defined/declared. But that's no more than the error message says so that should nto be a surprise.
It doesn't matter that you don't call do_work() anywhere; if it's there at all, the routines it calls, such as Motor_M1_On and Motor_M2_On, have to be defined somewhere and they aren't.
It sounds as if you are confused over basic C code structure: how, why and where routines are defined. For that you need to read a C language book or tutorial. |
So do i need to define the motors m1 and m2 ? I don't have much time to work on it, and for going through books and tutorial and by the way i'm newbie. Would you be kind enough to help me with this ? I mean can you provide me small sample so that i can understand ? Anyway thanks for your help bro. _________________ vineel |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Tue Apr 19, 2016 5:23 am |
|
|
Quote: | by the way i'm newbie |
That's blatantly obvious. It's also obvious, from the formatting, that the code you posted is cut and pasted from at least two sources. The PIC you are using is one of the very earliest flash-based parts, and has been effectively obsolete for many years, but is still used occasionally for teaching purposes.
To get rid of the errors, delete the do_work routine. There may well be some errors, different to the ones you've reported, but the one's you've reported will be gone.
There are severla problems with your code, including but by no means limited to the ADC set-up. Hint: ADC_CLOCK_INTERNAL is not recommended except under very specific circumstances.
I'd expect any practical wheelchair controller to give fully proportional control, most likely by a PID loop, probably with some sort of creep/nudge capability, all of which is fully safety interlocked.
So, all that considered, this is a late college assignment, isn't it? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|