Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

__delay_ms() is not working why ? using PIC16f877a and hitech compiler

Status
Not open for further replies.
I'm back. Did you manage to compile the project I uploaded?

If it compiled successfully we can just send the main file back and forth.

I'll working on your program now.
 
I'm back. Did you manage to compile the project I uploaded?

If it compiled successfully we can just send the main file back and forth.

I'll working on your program now.

hello sir today I have worked on the circuit and test the servo motor bu it does not work properly I am really disapointed :( , also the delay_ms dose not work :(, I really dun know what to do . plz help me, I attach the circuit diagram ,
I just need to rotate the servo clockwise and then stop it for some seconds and then rotate it counter colckwise (same degree), here is data sheet of servo which I am using , I have read it many times but it does not make any sence to me. can you fix it sir ? just servo part plz , thanks
 

here is datasheet and circuit schematic , i just need the code for rotating servo clockwise and counter clock wise
thank you for your help
 

Attachments

  • Capture.PNG
    Capture.PNG
    41.9 KB · Views: 116
  • 5687_9948_1.pdf
    437.3 KB · Views: 156

I've looked over your code and I can see a few potential problems. However, before I deal with them I would like you to test the servo with the attached project.

The project is compiled for a 16F84A, 4MHz OSC in config.h and uses RB5 as the signal lead to the servo, so change accordingly and recompile. What you are attempting in your code is to generate PWM through software, the test project does the same and has been tested with a GWS S03N STD Servo I had lying around.

I also check the PWM wave form on the scope and it is accurate. Let me know the outcome of the test. I notice the servo drew a considerable current during parts of the routine, which is why I used a 16F84A as a sacrificial lamb.

Everything else is working correctly in your project except the servo is that correct?

We'll get this figured out!
 

Attachments

  • PWMSimpleTest.zip
    30 KB · Views: 106
By-the-way, the 16F877A actually has the ability to generate PWM via hardware and I noticed you initially start to configure the registers to use it, but ultimately you attempted to use software to generate the PWM via delays such as the test code I uploaded. You may want to think about actually using the hardware features of the chip, which has 2 PWM channels available. Do you have an interrupt and interrupt service routine (ISR) experience?

I'll be up till about 3AM, it's now 1:39AM. So get back with me ASAP.
 
I've looked over your code and I can see a few potential problems. However, before I deal with them I would like you to test the servo with the attached project.

The project is compiled for a 16F84A, 4MHz OSC in config.h and uses RB5 as the signal lead to the servo, so change accordingly and recompile. What you are attempting in your code is to generate PWM through software, the test project does the same and has been tested with a GWS S03N STD Servo I had lying around.

I also check the PWM wave form on the scope and it is accurate. Let me know the outcome of the test. I notice the servo drew a considerable current during parts of the routine, which is why I used a 16F84A as a sacrificial lamb.

Everything else is working correctly in your project except the servo is that correct?

We'll get this figured out!

yes sir everything is working well, just servo motor stuck with me
thanks
 

Hi,

Your finally back online. Let me know if servo works with the attacted project above, after you make the changes of course.

Thanks

I forgot to ask whether your using the PICC Lite, STD or PRO version of the compiler? I believe only the PRO version has the __delay_ms() and __delay_us().

Let me know, if you don't have the PRO version I'll code the routines up in a separate file for you.
 
Last edited:
Hi,

Your finally back online. Let me know if servo works with the attacted project above, after you make the changes of course.

Thanks

I forgot to ask whether your using the PICC Lite, STD or PRO version of the compiler? I believe only the PRO version has the __delay_ms() and __delay_us().

Let me know, if you don't have the PRO version I'll code the routines up in a separate file for you.

Hi
actually i can't see any attached file ? can u upload it again ?
second is My compiler is hitech but i think is PICC.
when u upload it i can test it again, thanks for your help
BTW what is your name sir? what is your major ? :)

---------- Post added at 16:18 ---------- Previous post was at 16:17 ----------

o sorry now I see the attached codes , thanks

---------- Post added at 16:27 ---------- Previous post was at 16:18 ----------

Hi I make new project wizard, then put the config and main file in same directory as project is, then add the source file (main.c) and add the confige to header , then it gives me this error :

HI-TECH PICC-Lite COMPILER (Microchip PICmicro) V9.60
Copyright (C) 1984-2006 HI-TECH SOFTWARE
Error [499] ; . undefined symbol:
___delay_us (main.obj)

I think you are right the problem is with compiler , by the way this program seems good , I really do want to test it but I can't it gives me error
 

Open header file and edit as you want, I think you will be helped this

I did sir
but I how can I change it ? the only things that I can change is 400000mhz to 20000000 which I did. but still error ocured because of delay_us syntax :|

---------- Post added at 20:22 ---------- Previous post was at 19:12 ----------

Hi as I could not use the __delay_us(); so I just write the program as you can see in below:
while (t<200){
t++;

for(e=1;e<=50; e++){
servo = 1;
delayy(700);
servo = 0;
delayy(19300);
}

for(e=1;e<=50; e++){
servo = 1;
delayy(1800);
servo = 0;
delayy(18200);}

break;
}


I have use my own delay which is not precise , anyhow I face one more problem again. the problem is I dun know where to put these lines in my program, where ever I put the other parts dun work, I mean I change the value if sensor but it does not act, LCD does not show that the value is changed and the alarm is deactivated, it is because this has loop also but there should be some solution which i dun know. thanks

did u find the way that can let me to use this syntax __delay_us(); ??
thanks
 

I really appreciate that , thanks alot man , im sure this can be solution, you know what? this is group assignment but I am alone and dun have group mate, every group includes 4 person and they project is much lower than my project but I dun know why my lecture forces me to do everything lonely. anyway thanks a lot . I must bring your name on my acknowledgement , what is your name ?
thanks
 

I did sir
but I how can I change it ? the only things that I can change is 400000mhz to 20000000 which I did. but still error ocured because of delay_us syntax :|

---------- Post added at 20:22 ---------- Previous post was at 19:12 ----------

Hi as I could not use the __delay_us(); so I just write the program as you can see in below:
while (t<200){
t++;

for(e=1;e<=50; e++){
servo = 1;
delayy(700);
servo = 0;
delayy(19300);
}

for(e=1;e<=50; e++){
servo = 1;
delayy(1800);
servo = 0;
delayy(18200);}

break;
}


I have use my own delay which is not precise , anyhow I face one more problem again. the problem is I dun know where to put these lines in my program, where ever I put the other parts dun work, I mean I change the value if sensor but it does not act, LCD does not show that the value is changed and the alarm is deactivated, it is because this has loop also but there should be some solution which i dun know. thanks

did u find the way that can let me to use this syntax __delay_us(); ??
thanks

Can I see the header file which you edited please upload it
Did you try with anther compiler or IDE
 
Last edited:
Your problem is not your compiler.

Your version of PICC doesn't include __delay_ms() and __delay_us(), so I created my own delay routines delay_ms() delay_us() they're actually macros like the PICC PRO uses. They are both contained in the header delays.h and you can use it in future projects. They are based on _delay() routine which is hopefully common with all PICC compilers.

Change the the settings discussed before and recompile this test program first.

DO NOT add the code to your main project until you have tested it with your servo.

If you do add it your main project after testing it, you'll need to copy the delays.h to your source directory along side the config.h and PR11.c files and then add it to your project via "Add files to project" under the project menu.

Let me know the success or failure. If it fails to recompile post error listings.

Goodluck
 

Attachments

  • PWMSimpleTest.zip
    30.6 KB · Views: 89
You may want to upgrade your compiler version to 9.81. It is available from Hi-Tech for free running as Lite version:

**broken link removed**

9.60 is getting a little long in the tooth.

---------- Post added at 20:34 ---------- Previous post was at 18:56 ----------

Hi,

I found a copy of Hi-Tech PCC v9.60 Lite and unfortunately it doesn't have the _delay() function.

Therefore, I think it would be a very good idea to download v9.81 and install it. Both v9.60 and v9.81 can coexist.

**broken link removed**

You select the desire compiler rev by:

menu Project -> Build Options... -> Project

Then in the "Build Options for Project" dialog box select the Driver Tab

Select the v9.81 in the "Available drivers" box and hit "Move Up" button until it's at the top of the list.

Hit "Apply" button and followed by the "Ok" button and then recompile the PWM test program.

This should take care of your delay problems.
 
Last edited:
hi I have good news, today I unistalled the mplab and hitech compiler and then just inistal new mplab , after I run the program and then there is no error ho00oo0ra :D
i test the servo motor with some sample it works well, keep in touch Im gonna go other parts of project
thanks alot
 

I'm glad to hear it. Also, now just drop a copy of the delays.h I wrote into your source directory and you have __delay_ms() and __delay_us() like the PRO version.

thanks man now the problem is I dun know where to put servo codes withing my program, because I just want to servo rotate one time , but if I put it in main loop it won't to stop, I have idea to use while and break

int t=0;
while (t<20){

t++
.
.
.
.
.
break;
}

do u think is it good idea?
I also put it before the while at beginig of program but problem is while program is compiling first servo motor rotates then it will show the value on LCD, do u get what i mean ?
thanks
 

If all you need is just one rotation the just copy the code within the loop and paste it into subroutine like your servomotor(). Then you just call your subroutine anywhere you like.

Code:
void servomotor(void)
(

             unsigned int i;
	
	//set IO port for servo pin 
	TRISB = 0b00000000;			//servo motor is RB1
	PORTB = 0b00000000;			//clear port B

		//****************************************************
		//
		//Delay determine the servo motors position
		//Try change the value for different position 
		//
		//Value in __delay_xs() function is unsigned long
		//Calculate the timing correctly or servo damage could result!!
		//
		//****************************************************		
		for(i=0;i<50;i++)		//continues pulse for 50 times
		{
			servo=1;			//set servo pin high
			delay_us(700);	//delay	0.7ms
		
			servo=0;			//set servo pin low
			delay_us(19300);	//delay 19.3ms
		}
		
				
		for(i=0;i<50;i++)		//continues pulse for 50 times
		{
			servo=1;			//set servo pin high
			delay_us(1800);	//delay	1.8ms	
								
								
			servo=0;			//set servo pin low
			delay_us(18200);	//delay 18.2ms
								
		}	
			

}

Remember, you most likely with have to drop a copy of delays.h and config.h into your source directory and then add them to the project.

Did you know Microchip bought Hi-Tech, which is why their new MPLAB installation comes with the Hi-Tech PICC Lite compiler.

I glad things are working out for you on the project.

---------- Post added at 15:57 ---------- Previous post was at 15:50 ----------

Actually, another forum member just told me the new Hi-Tech PICC Lite version with MPLAB has the __delay_ms() and __delay_us() like the PRO version.

Let me know if that is true, if that is the case you won't need delays.h.

---------- Post added at 16:02 ---------- Previous post was at 15:57 ----------

Also if you have another sample you would like to use, just zip it and upload it. I'll help make a subroutine out of it for you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top