Digistump Forums
The Digispark => Digispark (Original) Support => Topic started by: alecaksono on March 25, 2017, 02:50:46 am
-
hello guys 8) i'm newbie in digispark and coding hehe.
i have some digital servo jx pdi6221mg http://www.banggood.com/JX-PDI-6221MG-20KG-Large-Torque-Digital-Coreless-Servo-For-RC-Model-p-973947.html
this servo work with 1520us/330hz and it was my code
#include <SoftRcPulseOut.h>
#define NOW
SoftRcPulseOut servo1;
SoftRcPulseOut servo2;
int pot1 = A2;
int pot2 = A3;
int valPot1;
int valPot2;
void setup()
{
servo1.attach(1);
servo2.attach(0);
}
void loop()
{
valPot1 = analogRead(pot1);
valPot1 = map (valPot1, 0, 1023, 0, 180);
servo1.write(valPot1);
SoftRcPulseOut::refresh(NOW);
valPot1 = analogRead(pot1);
valPot1 = map (valPot1, 0, 1023, 0, 180);
servo2.write(valPot1);
SoftRcPulseOut::refresh(NOW);
}
before it, i'm use mg995 the code was work, but for 6221mg it wasnt work,
as i know the softrecpulseout work in 20ms pwm, there is someway to change it from 20ms/50hz to 330hz frequrncy?
or you guys have some trick to move my digital servo
thx for your help.
sorry my english is bad ;D
-
Hi,
You can refresh the servo with a custom refresh time by calling SoftRcPulseOut::refresh() with 1 as argument.
This is what is done below by defining NOW as 1:
As the servos are refreshed immediately, you have to wait around 3030 microseconds minus the largest pulse width of the servos in microsecond.
#include <SoftRcPulseOut.h>
#define NOW 1 // <- Very important to define NOW as 1
#define HIGH_REFRESH_FREQ_HZ 330
#define PERIOD_US (1000000UL / HIGH_REFRESH_FREQ_HZ)
SoftRcPulseOut servo1;
SoftRcPulseOut servo2;
int pot1 = A2;
int pot2 = A3;
int valPot1;
int valPot2;
void setup()
{
servo1.attach(1);
servo2.attach(0);
}
void loop()
{
uint16_t LargestPosUs;
valPot1 = analogRead(pot1);
valPot1 = map (valPot1, 0, 1023, 0, 180);
servo1.write(valPot1);
valPot2 = analogRead(pot2);
valPot2 = map (valPot2, 0, 1023, 0, 180);
servo2.write(valPot2);
SoftRcPulseOut::refresh(NOW); // A single call is sufficient for all the sevos
LargestPosUs = servo1.read_us();
if( servo2.read_us() > LargestPosUs) LargestPosUs = servo2.read_us();
// Wait for around 3030 microseconds minus the largest pulse width
delayMicroseconds(PERIOD_US - LargestPosUs); // This should warranty a constant period around 3030 microseconds (330Hz)
}
No tested, up to you!
-
thanks a lot RC Navy you have write the code for me,
i was check the pulse are 330hz or 3030ms but my servo don't move,
i get confuse with the digital servo work
i have tested the servo with servo tester its some time work,
i have tested with arduino, i used knob and sweep code from example. with sweep code the servo was work, but with knob code it wasn't work.
i have tested too with rc receiver and its work for 90 degree, beacause the pulse only 1500ms.
what should i do? i have tested your code, make digitalWrite code, even use logic level.
-
for additional,
all the tools that I use have been checked using the osciloscope,
and mostly have same signal about 20ms pulse width, and for the rc signal gave 3.3 v output signal
i have used the logic level too for the arduino knob program hope the servo work and yeah its still not work