2

Author Topic: Have anyone encountered this weird problem?  (Read 1635 times)

0 Members and 1 Guest are viewing this topic.

Offline CharizardTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Have anyone encountered this weird problem?
« on: March 20, 2009, 07:56:50 AM »
I wonder has anyone encounter this problem. I wrote a code generating pulses for my servo, and i even have downloaded code provided by supplier to test the servo. In oscillator, the pulses are there, but whenever I connect to my servo, those pulses disappear and become 0v. I tested with two servos and they show the same problem. Do you guys have any idea on it?  ???thanks.

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: Have anyone encountered this weird problem?
« Reply #1 on: March 20, 2009, 10:04:15 AM »
how about a little more information?


microcontroller?

servo type?

code?

Offline CharizardTopic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
Re: Have anyone encountered this weird problem?
« Reply #2 on: March 20, 2009, 10:32:31 AM »
I am using PIC16f877 on C55S servo from this site. http://www.cytron.com.my/listProductCategory.asp?cid=90

Code: [Select]
//==========================================================================
// Project : Sample code for control single servo motors using delays
//   This project is using 16F877A with 20MHz
//   Has been try succesfully using SK40B
//  
//   Please make sure the hardware is compatible with this code
//
// Project description : This source code is used to control a servo motor.
//   Servo motor will continuosly turn from one position to another position
//   Delay is use to calculate the pulse width timing.
//   The delay timing is depend on the crystal.
//   Difference timing for difference crystal.
//
// Date : Feb 2009
//==========================================================================
//
// include
//==========================================================================
#include <pic.h>    // this sample code is using 16F877A !!

// configuration
//==========================================================================
__CONFIG ( 0x3F32 ); //configuration for the  microcontroller

// define
//==========================================================================
#define servo RB1

#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 of the program)
//==========================================================================
void main(void)
{
unsigned int i,a;

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

//servo will loop infinity
while(1) //from one position to another position
{
//*******************************************************
//
//Delay determine the servo motors position
//Try change the value for different position
//
//Value in DelayUs and DelayMs function must not more than 255
//Otherwise the timing will not accurate!!
//
//******************************************************

for(i=0;i<50;i++) //continues pulse for 50 times
{
servo=1; //set servo pin high
DelayUs(250);
DelayUs(250);
DelayUs(200); //delay 250+250+200= 700us = 0.7ms
//These delay only valid using 20MHz!

servo=0; //set servo pin low
DelayMs(19); //remain --> 20ms-0.7ms=19.3ms
DelayUs(250);
DelayUs(50); //19ms+0.250ms+0.050ms=19.3ms
//These delay only valid using 20MHz!
}

//  _                _                      _
// | |               | |                     | |
// | |               | |                     | |              ~~50 times             
// | |_____________| |____________| |____________________
// 0.7ms    19ms      0.7ms      19ms     0.7ms   19ms
// |    |
// |<-------20ms------>|

for(i=0;i<50;i++) //continues pulse for 50 times
{
servo=1; //set servo pin high
DelayMs(2); //delay 2ms
//These delay only valid using 20MHz!

servo=0; //set servo pin low
DelayMs(18); //delay 18ms
//These delay only valid using 20MHz!
}

//  ___        ___                 ___
// |   |               |   |               |   |
// |   |               |   |               |   |              ~~50 times       
// |   |________|   |_________|   |____________________
//  2ms       18ms      2ms      18ms       2ms 18ms
// |    |
// |<-------20ms------>|
}

}

//subroutine
//============================================================================
void DelayMs(unsigned char y)
{
unsigned char i;
do {
i = 4;
do {
DelayUs(250);
} while(--i);
} while(--y);
}


I program it with MPlab and PICkit2. The servo has 3wires there, red, black and white. I connected white to PIC, black to -ve / ground and red to +ve.
« Last Edit: March 20, 2009, 10:37:37 AM by Charizard »

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: Have anyone encountered this weird problem?
« Reply #3 on: March 20, 2009, 12:03:38 PM »
Can you provide a schematic? It might be an electronic issue. What are you powering the microcontroller with?
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline galannthegreat

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: Have anyone encountered this weird problem?
« Reply #4 on: March 20, 2009, 12:54:23 PM »
Check the datasheet of the servo for the tolerances and pulse range.
« Last Edit: March 20, 2009, 01:07:15 PM by galannthegreat »
Kurt

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: Have anyone encountered this weird problem?
« Reply #5 on: April 07, 2009, 10:54:48 PM »
Also, always use an oscilloscope to measure signals to make sure your code is working properly.

Offline slo

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: Have anyone encountered this weird problem?
« Reply #6 on: April 08, 2009, 04:40:59 PM »
The ground for the servo and microcontroller should be connected.  Please verify the voltage level and frequency of the pulses are what they should be before connecting the servo.  If all you saw were pulses it could be they are not the right pulses.  I have been guilty of quickly hooking up a probe, seeing a waveform and assuming everything is good without checking the scale.  Turned out the wire I was on was disconnected and acting as an antenna for EMI.  You said the pulses are there in the oscillator.  I assumed this was a typo and you meant oscilloscope.  If you are actually connecting your servo to an oscillator it would probably, heck who knows.  But it certainly wouldn't run your code.
Dustin Maki

 


Get Your Ad Here

data_list