so this is much different that what i had thought
so you want to track the change in position of the encoder to inc/decrement the speed of a motor?
... and you're using the servo as a speed indicator?
so this is much different that what i had thought
so you want to track the change in position of the encoder to inc/decrement the speed of a motor?
... and you're using the servo as a speed indicator?
The servo was a proxy for the ESC.
ESCs can use the exact same signal as a servo for speed control, so here to simplify for us the OP transferred the problem, expecting that none of us would know that.
Here's a thousand words on my current understanding of the matter
HTH
a7
Why are you using a 600 ppr quadrature encoder for this task?
thanks
that and the picture helps
Good morning, yes, I saw it in the past but may be I should make a revision of PID control.
Many thanks @JCA34F ![]()
Many thanks for your help @sherzaad
You all are being vital for my research. Many thanks ![]()
Good morning @gcjr .
The idea is to attach the encoder to the car's transmission, taking advantage of the considerable rpm reduction from the engine to the transmision, thanks to the gear ratio. So, Im not using the pwm signal given by @sherzaad to control a servo, but this signal is going to be used to control a brushless esc, taking advantage that the control signal is similar on a servo and in a esc.
I think you understood the idea correctly ![]()
I have chosen this encoder because it wass the only one that can work on high rpm and match with my budget @cattledog
Thank you ![]()
Good afternoon.
I had just tried to upload the code that @sherzaad gived to me, and i have a compilation error:
"Compilation error: 'TCNT1' was not declared in this scope"
/*
Encoder details: 600pulses/rev
Max rpm to be registed 4500rpm -> 2,700,000pulses/min -> 45000pulses per second
*/
/*using Timer1 exernal clock input a pulse counter
Therefore cannot use Servo.h library since it also uses timer1.
Therefore using ServoTimer2.h instead
*/
#include <ServoTimer2.h>
#define PERIOD 1000 //1000ms
ServoTimer2 myservo;
uint32_t oldTime;
void setup() {
//Serial.begin(115200);
myservo.attach(2); // attach a pin to the servos and they will start pulsing
//----------------------
noInterrupts();
TCNT1 = 0; //reset timer1 counter register
TCCR1A = 0x00; //reset timer 1 A register
TCCR1B = 0b00000111; //set up timer1 to use external clk T1 (pin D5 on UNO)
TIMSK1 &= ~(1 << OCIE1A); // turn off the timer1 interrupt
interrupts();
//----------------------
oldTime = millis();
}
void loop() {
uint16_t pulse_cnt, servo_angle;
//check pulse count and update servo position every 1s
if (millis() - oldTime >= PERIOD) {
noInterrupts();
pulse_cnt = TCNT1; //get counter value
TCNT1 = 0; //reset counter value
interrupts();
oldTime = millis();
servo_angle = map(pulse_cnt, 0, 45000, 0, 90);
myservo.write(servo_angle); //update servo postion
}
}
what exact type of microcontroller are you using?
what exact type of board is active in the arduino-IDE?
Good afternoon @StefanL38 . Im using a original Arduino nano 33iot, with its micro-controller. I dont know if you are asking for another information. Thanks.
I have selected the arduino 33iot board, in the correct port. @StefanL38
remember: you should post the exact type of microcontroller that you are using in the very first post
The arduino 33iot has a SAMD21 Cortex®-M0+ 32bit microcontroller.
The error you are getting is because TCNT1 is a microcontroller- internal
microcontroller-specific hardware of Atmega328-microcontrollers
that a SAMD21 Cortex®-M0+ 32bit does not have.
Hello again @StefanL38 .
Sorry for my mistake, I'm a total begineer with arduino projects.
Could you tell me please what can i do to solve this problem?
Many thanks for your help.
before we go on.
please describe what the REAL overall purpose of all this is.
You are taking the rpm from the transmisstion instead of the engine itselfs
you create a ESC-control-signal for an ESC.
What shall the ESC and the brushless-motor do?
Are you planning to synchronise the rpm of brushless-motor with the nitro-engine?
What is this for a car. A RC-model-car?
Or
a real person-car?
Does this car have gears which would mean that depending on the gear you need to create different rpms on the brushless-motor?
Or is the brushless-motor directly connected to the the wheels?
You have asked a detail-question about a pretty complex project as a beginner.
It might be that a different approach might be better suitable.
That is the reason why you should answer all these questions
best regards Stefan
Its okay @StefanL38 .
Im making a hybrid rc car from an old nitro rc car.
I've machined a new aluminium chassis, because I added a center differential to asume the possible rotation speed differences between the front axle and the rear axle. In simple words, the rear axle and the front axle are connected with a a mechanical diff between them, instead of making a rigid assembly. The addition of the diff has been done asuming that they will be rotational speed differences between the axles.
The front side of the center diff will be powered by the electric motor and the rear side of the center diff will be powered by the nitro engine.
My intention is that the encoder will be attached to the nitro engine's spoor gear using a reduction train to achieve the rotational speed that the encoder admits.
Then, this signal will be transfered to the arduino, and then arduino will create a pwm signal to control the esc having the income of the nitro engine's speed.
So, the system will be a closed loop system.
Like you know, nitro rc engines rev extremely high and their rev range its also very wide.
Just to make sure. If the Arduino iot33 can handle the maximum rpm.
what will be the maximum rpm that can occur on the output of the nitro engine's spoor gear using a reduction train ?
As an ATSAMD21 microcontroller is newer as an Atmega328 it should be possible.
Do you have a backwards gear? In your application the driving-direction could be determined by the servo that controls forward / backward.
This means the problem reduces to simply measuring the rpm.
I haven't used an arduino IO33. But I guess there are multiple ilbraries for measuring rpm with a Arduino 33iot
This library works with SAMD21-microcontrollers
Hey @StefanL38. The maximum rpm that i want to measure will be 4500. My encoder is suitable until 5000. I want to leave a 500 rpm margin as a security margin.
Im not intended to program a backwards gear, but i think it will be important to let the arduino know that we are giving throttle (throttle servo's signal different to neutral or brake).
Thanks for all your help.
This means the maximum-frequency is 4500 rpm / 60 sec/min * 600 pulses per rotation = 45 kHz.
One pulse every 22 microseconds. Should be doable with an arduino 33io. But I guess it requires using the counter-module inside the microcontroller.