JakoTako
Hi,

I am working on a program that will allow me to control a stepper motor via an external, dedicated TB6600 stepper motor controller. I only need direction and pulse signals to operate it. But let's focus on the pulses.
I have built a program that generates pulses with a frequency of up to 1370Hz.

[203128%2F8586196%2Fmceclip0]

Interval of cycle i set on T#0.07ms. And i got this: (this is diagram of 13 output Arduino measured with 24MHz logic analyzer.

[203128%2F8586198%2Fmceclip0]
Further reducing the program cycle time and the TON1 and TONF1 times gave worse results.
Is there any way to get higher frequency pulses? Preferably up to 10kHz.


If good results can be got, I would like to add the possibility of adjusting this frequency from 1Hz to 10kHz based on the 0-5V analog signal from the potentiometer.


Writing a simple program in the Arduino IDE, I was able to achieve 200kHz. But the C language is not for me D:
[203128%2F8586220%2Fmceclip0]

Please tell me if something like this is possible. Thank you
Reply 0 0
thiagoralves
You can’t write soft PWM pulses in ladder logic. There are tons of things happening in between cycles (scheduler, Modbus tasks, reading inputs, writing outputs, etc). You’re reducing the scan cycle to impractical values. In reality what is happening is that you’re running the scan cycle back to back with no break in between, and you still haven’t got the frequency you want (and never will).
 
You need to configure a hardware PWM that can generate pulses independently of the CPU. Use the PWM_CONTROLLER block to configure the PWM channel and you’ll get stable and reliable output pulses
Reply 1 0
JakoTako
Thank you for your reply. @thiagoralves 🙂
I took your advice and built such a circuit.
[203128%2F8587976%2Fmceclip0]

It works not bad because I managed to get even 1MHz,

[203128%2F8587978%2Fmceclip0]

but I can't get less than 244Hz and that's a problem for me. This is the lowest frequency i can get. Regardless of the PWM_FREQ value entered. I tried with different values (for qxample 1, 10, 200, 220Hz).

[203128%2F8587980%2Fmceclip0]

I need a range from 1Hz to 10kHz. 250Hz it's too much to try to get that frequency with a timer circuit i think.
Can you tell is this possible to get such a range?

Best Regards

Reply 0 0
thiagoralves
That's a limitation of the AVR chip. It cannot generate pulses with a frequency lower than 200 something Hz. You can try to generate a soft pulse using timers for frequencies lower than 250Hz. Specifically for 250Hz you need a scan cycle of 4ms or less. It is doable, as long as you don't have any comms enabled (modbus, debug, etc). Remember you're on a 8-bit chip running at 16MHz, with 2KB of RAM. Running a full blown IEC 61131-3 PLC runtime in it is already a miracle.
Reply 1 0
JakoTako
That's a limitation of the AVR chip. It cannot generate pulses with a frequency lower than 200 something Hz. You can try to generate a soft pulse using timers for frequencies lower than 250Hz. Specifically for 250Hz you need a scan cycle of 4ms or less. It is doable, as long as you don't have any comms enabled (modbus, debug, etc). Remember you're on a 8-bit chip running at 16MHz, with 2KB of RAM. Running a full blown IEC 61131-3 PLC runtime in it is already a miracle.
Thank you, for your answer.
I understand that there are some hardware limitations, but I'm surprised that the PWM controller even reaches 1Mhz and fails in the 1-200Hz range.
I thought it was something with my program, especially since I just found a topic ( https://openplc.discussion.community/post/pwm-arduino-nano-12625556?highlight=pwm&trail=15) where users reached 50Hz and control the servo in this way.

I have another question. Are there any manuals or documentation available somewhere to get a better idea of the Are there manuals or documentation available somewhere to get to know OpenPLC better?
Thank you for your time and good luck in developing this project! 🙂
Reply 0 0
Reply