Archives
-
Coding for servo motor
hi all ..
i made a code for a servo motor which keep rotating from left to right
but its not working…
on search i came to know dt it requires a pulse of 55hz with ON time of around in between 2.4 ms to 1.0 ms for full rotation left and right.
to generate this i made a timer which counts for 0.1 ms and if i need to genrate a pulse of 1.4 ms, make the timer to overflow 14 times…and so on ..
but it is not working.
here is the code attched CODE:
#includeltreg51.hgt
sbit SIGNAL =P0^1;
void delay(void);void main(void)
{
unsigned char i,j;
while(1)
{
for (j=0;jlt11;j++) //this will flow the 11 pulses with ontime of 1.5 ms and off time 16.7ms
{ for (i=0;ilt15;i++) //this will make the on state for 1.5ms
{
SIGNAL=0xFF;
delay();
}for (i=0;ilt167;i++) //this will make the off state for 16.7 ms.so that total on+off time is equal to around 18ms which is 55hz pulse.
{
SIGNAL=0X00;
delay();
}
}for (j=0;jlt11;j++) //this will flow the 11 pulses with ontime of2.4 ms and off time 15.7ms
{
for (i=0;ilt24;i++)
{
SIGNAL=0xFF; //this will make the on state for 2.4 ms
delay();
}for (i=0;ilt157;i++) //this will make the on state for 15.7 ms
{
SIGNAL=0×00;
delay();
}
}
}
}void delay(void) //THIS TIMER MAKES DELAY OF 0.1ms
{
TMOD=0×20;
TH1=-92;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}Related Forum Messages
- Frequency Counter or Meter in 8051 C
- Help me with the code
- Need help on servo motor based Robotic Arm using 89C51 micro controller
- RFID BASED AUTO TOLL PLAZA(8051 C program)
- ADC0804 to PIC16f877a
- Servo Motor interface with PIC
- Urgent stepper motor problem
- Control motor with PWM
- Servo control using port
- Rs 485 protocol based dc motor speed control using pwm with ats8952
- Need help using Serial port to communicate with motor.
- Getting error in program as well as have some problem in con
- Stepper motor controll with AT89C51
- CR servo control using millis
- Where shall I put the ‘background timer’ for my project?
- 8051 timer test
- 5×7 Led Dot Matrix using 8051 (Programming in C )
- External interrupts: Help me out.
- Timer 0 in Atmega 32
- Waveform decoding with 8051 coding problem
I m building frequency meter till 1Mhz range. I saw the project of Ajay and got some idea. on that i m trying to bulid freq meter. I m getting the output as on LCD alphabets/ascii charaters for ex if i give 80Hz for T1 character 'P' is displaying on LCD. how to convert that P to 80. My upper limit to display is 1000000Hz(1Mhz), how can i display this on LCD CODE: #include ltreg51.hgt sbit e=P2^2; sbit rw=P2^1; sbit rs=P2^0; sbit D7=P0^7; void delay(unsigned int i); void lcdcmd(unsigned char val); void lcddata(unsigned char val); void lcdinit(); void checkbusy(); void main() { unsigned char val,i; ...i am posting my code to just display characters in lcd with a keyboard. please help me with the problem in the code. CODE: #includeltreg51.hgtsbit en= P0^1; sbit rs= P0^0; void cmd(int ); void ldata(char ); void delay(); void main() { cmd(0x38); delay(); cmd(0x0e); delay(); cmd(0x01); delay(); cmd(0x06); delay(); ...hi everyone, im working on a proj SERVO MOTOR BASED ROBOTIC ARM using 89C51 micro controller..im using 5 servo motors in the proj. im new to usage of servos. i know that diff servos uses diff pulse widths for its left,right,neutral positions..the servo im using is:TOWER PRO MG995(Digi High Speed)..im facing few problems in the motor rotations.. im using +5v(dc) for the motor..the signal pin of the servo is connected to the microcontroller port pin via 10k resistor.initially ive started working on one servo and im also giving the code ive developed for that. can the same code be used by all ...Respected Sir/Maam; I am working on 8051.We are doing programming in 8051 C.I am having a doubt related to STEPPER motor.Our project is on RFID BASED AUTO TOLL PLAZA.This is the program that I have written for forward motion and reverse of stepper motor.Will you please help me whether this program is correct or not and also to stop the motor at a particular instant what changes I need to make in this. #includeltreg51.hgt #define ld P1 #define stepper P2 sbit obj = P3^1; sbit led = P3^2; void msdelay(unsigned int); void delay(unsigned int); void UP(); void DOWN(); void main() { unsigned char j,k; ld = 0xFF; obj = 1; while(1) { //unsigned char m1[]= "WELCOME"; //unsigned char ...Hello, friends i need some help for my project. i am trying to hook up the output from ADC to the pic. what i did was hooking ADC output directly to PORTC of the pic (all 8 bits). is it the correct way? What i am trying to do is, i am using two ADC one hooking to PORTC and output of the other one hooking up to PORTD. ADC input is light sensor. I am comparing the two ports. Pls give me some idea how am i suppose to do it. Below here is my code of comparing the ...Hi everybody can anyone help me... // include //========================================================================== #include ltpic.hgt // this sample code is using 16F877A !! // configuration //========================================================================== __CONFIG ( 0x3F32 ); //configuration for the microcontroller // define //========================================================================== #define servo RB2 #define MHZ *1000L /* number of kHz in a MHz */ #define KHZ *1 /* number of kHz in a kHz */ // Value x must not more that 255 #define DelayUs(x) { unsigned char _dcnt; \ _dcnt = (((x)*(20MHZ))/(24MHZ))|1; \ while(--_dcnt != 0) \ continue; \ _dcnt = (((x)* (20MHZ))/(24MHZ))|1; \ while(--_dcnt != 0) \ continue; } // function (every function must have a function prototype) //========================================================================== void DelayMs(unsigned char y); // Value y must not more that 255 // delay ms // main function (main fucntion ...Hi, hope you are doing well guys. i'm working on a bipolar stepper motor using pic 18f458 and l293d as a bridge the circuit is connected exactly the same way you showed in the tutorial. the motor should work as follows: when ever i gave it 1 to pin 2 in register c the motor rotate clockwise then it stops waiting the next signal that i will give to pin 2 in register c. but the problem is that when i run the below code the motor goes crazy it rotates clockwize then after a while it starts rotating anticlock wise or ...hello all, I am currently working on AT89C51CC01 project to control speed of motor. My first task is when i connect controller to motor then there is no PWM signal(All pins are high of P1)..then when the state of P2_2 pin is changed then controller start to generate PWM signal. please check this code. CODE: #include ltstdio.hgt #include "reg_c51.h" void Init_PCA(void) { CMOD = 0x02; // Setup PCA timer CL = 0x00; ...Hi, i connected a servo signal to RD7 in PIC18F4455. I have done the experiment for the servo movement left = 500us, right = 2ms. I use the delay to work out the pulse but it doesnt work. The servo was just stop here. Is there any problem with my code? how can i fix it? void main (void){ TRISD=0b00000000; PORTD=0b00000000; PORTDbits.RD7=0; Delay1KTCYx(5); //delay for 20ms PORTDbits.RD7=1; Delay100TCYx(5); //delay for 2ms while(1) } PS:using Fosc=1MHzhi... i have the schematic for rs 485 protocol based dc motor speed control using pwm with ats8952.in the my coding part the code is helpful in rotating the motor... i need help in finding out the speed and pulse width...the crystal i used is of frequency 11.0592mhz.. i am linking d schematic and code with this post... can u help me out??? student.pdf CODE: #includeltreg51.hgt// delay(unsigned char); receive(unsigned char ); sbit motor=P2^7; //0,1 PINS USED FOR SERIAL COMMUNICATION sbit RE=P3^2;//ACTIVE LOW PIN NO:12 sbit DE=P3^3; //ACTIVE HIGH PIN NO:13 unsigned char r,recv; main() { RE=0; DE=0; motor=0; while(1) { ...I'm creating a project using Morse code. However, rather than sound or lights, i am creating a device which will mimic a signal light used by sailors. To make this I'm using an old set of blinds, motor shield and a stepper motor to turn the blinds open and close. I have established my code to create the Morse code on the blinds however at its current stage I have to manually write each letter to be spelled out on the blinds in my code. I would like to somehow use the serial port to enter whatever message a user ...Hello Sir/Madam, I am rotating my DC motor (having `12v,100rpm) in clockwise,anticlockwise direction and also stop motor for some time and this thing i am doing by using atmega8 but nothing is happening as i am connecting L293D(E,0,1)) with portD(0,1,2) of atmega8 and connecting M+ and M- to motor pins .Please go through my coding and error which i am getting as well as circuit please help me Program #include ltavr/io.hgt #includeltutil/delay.hgt #define L293D_A PORTD_0 //Positive of motor #define L293D_B PORTD_1 //Negative of motor #define L293D_E PORTD_2 //Enable of L293D // Function Prototypes void rotate_f(void); //Forward run funtion void rotate_b(void); ...Hey.... I want to controll Stepper motor with At89c51.. and i made simulation in proteus.. and program made in keil . . . but i cant make loop for it.... it will rotate only one rotation so, can Anybudy help me for making loop...???.. for full rotation.... this is the fig. and this is code for it... #includeltat89x51.hgt void delay(unsigned int); void main (void) { P2_4=0; delay(30000000000); P2_4=1; delay(30000000000); P2_2=0; delay(30000000000); P2_2=1; delay(30000000000); P2_3=0; delay(30000000000); P2_3=1; delay(30000000000); P2_1=0; delay(30000000000); P2_1=1; delay(30000000000); } void delay(unsigned int itime) { int i; for(i=0;iltitime;i++); }Im trying to get a vex continuous rotation servo to sweep from full speed forward to full speed reverse, by using similar code as sweep example in arduino. But I have to control many servos and sensors so cant use delays for pwm timing. Which is why Im trying to use millis as replacement (like in Blink without delay example). Here is my sketch: #include ltServo.hgt Servo testservo; void setup () { Serial.begin(9600); testservo.attach(6); //pin 6 is where the white signal line from vex goes to } void loop() { int pos=40; //arbitrary starting speed in range of 0-180 unsigned long prevtime=0; ...Hi, Just a quick overview I'm working on a ultrasonic rangefinder project. The general idea (this is the newer idea I'm going to implement) is that it generates a 40Khz square wave pulse via a CTC hardware interrupt and starts a 'timer,' PB0 waits patiently for a echo pulse, when an echo is received on this pin this will perform an edge-triggered interrupt and stop the timer. The timer value is recorded here. The time that is measured is the total transit time for the pulse to reach the object and come back. Dividing this by 2 would give the ...Hello I started testing the timer functions, and I found a small code on the web which is simulate a PWM signal. It's uses the timer0, and i think it's blinking the 1.7 port. But it's doesn't work, i can't build the program because it's shows that error messages: Assigning to non-lvalue 'TR0' Assigning to non-lvalue 'TF0' Here is the code: Code: Select all // define ON and OFF states #define on 1 #define off 0 // long and short delay functions void delay_on(); void delay_off(); main() { TMOD = 0x01; // initialise TMOD for Timer 0 in mode 1 while(1) // repeat this { P1_7_bit = on; // output pin high delay_on(); // 800 us delay P1_7_bit ...Guys i m making a Scrolling text using 5x7 display with 8051 but i m having a problem that i m unable to figure out that how to scroll a text i wrote this test code but it keeps displaying 'A' .. plz can sumbody tell me what is the prob with this code...... i ll very thankful..... #includeltreg51.hgt int count[5]={0x08,0x10,0x20,0x40,0x80}; int A[5]= {0x7F,0x98,0x98,0x7F,0x00}; int Blank[5]= {0x0F,0x00,0x00,0x00,0x00}; int c; int i,j ; int z; void delay(unsigned int msec) // Function to provide time delay in msec. { for(i=0;iltmsec;i++) for(j=0;jlt1275;j++); } void scroll() interrupt 1 { TL0=0x36; //Reloading Timer0 TH0=0xA6; for(z=0;zlt5;z++){ P2=~A[z]; P3=count[z]; delay(1); P2=0xFF; } } void main () { TMOD=0x11; //Intialize Timer 0 TL0=0x36; //Reloading Timer0 TH0=0xA6; IE=0x82; // Enable Timer 0 interrupt TR0=1; //Start Timer 0 while(1){ for (c=0;clt5;c++){ delay(100); for ...Hello everyone. Presently i am trying to execute external interrupt in p89v51rd2. Here is the sample code what i referred. 1. Is there any corrections in the program. 2. I have tried passing 5 volt and also ground signal to P3^2 amp P3^ 3 (int0 and int1) . Is it the correct procedure so that led connected to port 0 will blink? Plz. help me out. //example-5: detect an external interrupt on P3.2 and P3.3. indicate on LEDs connected on P0.0 amp P0.1 #includeltP89V51Rx2.hgt //#includeltreg51.hgt sbit op1=P0^0; // LED1 as output on P0.0 sbit op2=P0^1; // LED2 as ouput on P0.1 void delay(void); // 10 ms delay void intrupt0(void) interrupt ...Hello, I need accurate delay in miliseconds in my application, and therefore I used delay.h header file to get delay. I am using codevision avr compiler. But the functions of delay.h does not give me the accurate delays. I am using 16MHz of crystal. So to get the accurate delay, I moved to timer. I've studied timer and initialize the timer and enable the interrupt for timer overflow. In isr I am blinking led for testing but the interrupt is not coming, and led doesn't get blink. The timer code is given below. Can you please help me to get ...i wana decode a simple wave form genertaing from one controller and the other controller is programed to decode it ......i write simple code for this here but it is not working i dnt know what is the problem in this or there are other methods one can use for decoding wave form...here is the code Transmiter: ________________________________________ #includeltreg51.hgt sbit sw=P2^0; sbit sw1=P2^1; unsigned int x,g; sbit relay=P1^6; void delay(x) { for(g=0;gltx;g++) { TMOD=0x01; TH0=0xFC; TL0=0x67; TR0=1; while(TF0==0); TR0=0; TF0=0; } } void main() { while(1) { if (sw==0) { sw1=1; delay(2); sw1=0; delay(4); sw1=1; delay(8); sw1=0; delay(4); } } } __________________________________________________ __ RECIVER: __________________________________________________ ____ #includeltreg51.hgt sbit sw=P2^0; sbit sw1=P2^1; unsigned int x,g; sbit relay=P1^6; void delay(x) { for(g=0;gltx;g++) { TMOD=0x01; TH0=0xFC; TL0=0x67; TR0=1; while(TF0==0); TR0=0; TF0=0; } } void main() { relay=0; while(1) { if(sw==0) { delay(2); { if(sw==1) { delay(4); { if(sw==0); { delay(8); { if(sw==1) { delay(4); relay=1; } } } } } } } } } __________________________________________________ ___ here is the protious simulation...
