> -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of yamanoor sairam > Sent: 01 March 2012 18:19 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC]: Servo motor control - 12F675 >=20 > Hello All, >=20 > I apologize for not getting back to the list to let you know whether I go= t > this problem solved. Unfortunately, I could not achieve speed control of > my servo. All I am able to do is make my servo to known angles and known > rates. >=20 > To recap, I am trying to achieve speed control of my servo using PIC12F67= 5. >=20 > There seems to be a problem is using the Hitech C delay functions. You > cannot pass variables to the Hitech C delay functions. >=20 > Hence I had to work around something like: >=20 > while(i>0) > { >=20 > __delay_us(1); > } > Where i is the variable meant for changing the time delays. As suggested > on this list earlier, I had even tries using for loops. But I was not > successful at all. I read somewhere that a possible reason for the proble= m > could be that it is not possible to produce very small time delay cycles > like 1 microsecond and hence I decided to go in steps of 10 microseconds. > But neither for loops nor while loops are fixing my issue of time delay. >=20 > Since the time delay is not perfect, my voltage regulator is boiling and > the servo is not spinning at all. >=20 > If I switch my compiler from Hitech to CCS, will it solve my problem? All > I need is a function where I can pass a variable as an argument to the > delay function. I am nervous to switch the compiler because while > conducting the experiments, I switched to the MikroC IDE. I got frustrate= d > with the fact that I couldn't set config words like I could do in MPLAB. >=20 > I tried even setting macros for time delays as suggested in one of the > microchip forums. I got a lot of compiler errors and I just got frustrate= d > out of not being able to fix this problem. >=20 > I am looking forward to hearing your suggestions on fixing the time delay > issue. >=20 > Sai My suggestion is to abandon the use of software delays for this application= ; it's a horrible way of doing things that results in unreliable spaghetti = code. Instead use a hardware timer, and toggle your servo PWM in the timer interr= upt. You can handle the switch sensing and speed/position control within t= he main loop or within the timer interrupt. You get the advantage of being= able to run the PWM all the time if you want, which means your servo will = now hold in the last location and you can run any other code you need from = within the main loop without all the clunky software delays. Cheers Mike =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .