Hello Guest it is July 05, 2025, 05:47:47 AM

Author Topic: Arduino ModBus MPG problem  (Read 30250 times)

0 Members and 1 Guest are viewing this topic.

Arduino ModBus MPG problem
« on: July 24, 2024, 01:58:29 PM »
Hi everyone, I dont normally post on here although I get a lot of my information from these forums.
I have a problem and just can't solve it, any help or point me in the right direction would be helpful.

I have developed an Arduino - Modbus interface everything is working and data is going up and down but I cant resolve one problem, its on the MPG. This is where I am at

I have fed a rotary encoder into an Arduino2560, the Arduino does the counting up and down and the number transfers to MACH 3 and I use Brains to put the number into MPG1 count DRO.
Its the number format that has me baffled.
If I have the MPG in velocity or step/velocity or single step mode the number at rollover goes from positive, through zero and counts down -1,-2,-3 and so on just as expected of a signed integer.
If I use multi step the number goes from positive, through zero and instead of -1 it goes to 65537 (or whatever the 16 bit number is, cant remember exactly) and my axis goes off on a massive move.
The modbus reads the number as the two's compliment and passes it to the DRO, the numbers on the brains  viewer does not change, but the DRO reads differently on multi step mode.

Am I doing something basically wrong in trying to get an MPG working in this way, why does MACH3 display a different number format for the same integer.
I have tried all the possible number formats in the Arduino, nothing different happens.
If I move the MPG positive and the axis positive then zero the axis the axis will then move negative as my integer starts to go down, again when I go through zere count the number goes back to 65537, as if its an unsigned integer.

Any ideas, I'm pulling my hair out, everything on my pendant and control stations are working well, just stuck on this

thanks in anticipation
servomac
Re: Arduino ModBus MPG problem
« Reply #1 on: July 25, 2024, 07:21:21 AM »
I wonder if the instructions for the C92 may shed some light on what you are doing:
https://cnc4pc.com/modbus-server-b.html
The MPG of this panel reads the MPG as an encoder:
https://cnc4pc.com/touch-screen-cnc-console.html

Arturo Duncan
https://cnc4pc.com
Re: Arduino ModBus MPG problem
« Reply #2 on: August 29, 2024, 01:20:29 PM »
Hi all
after reading as many posts have finally found out what I was doing wrong. I was writing my MPG value into DRO101-DRO 0 count. I now put it into Mach variable MPG 1 count, everything is working fine now
thanks for looking
Re: Arduino ModBus MPG problem
« Reply #3 on: January 06, 2025, 05:10:16 AM »
I know this is an old topic, but I recently completed my MPG Modbus project using an Arduino Nano. I’d like to share my work with everyone, especially those who might still need a solution for this project.

Here’s the link to all the necessary files, including the schematic, Arduino code, libraries, Modbus configuration, and brain files:
Download all project files: https://drive.google.com/file/d/1RCqZE5Sm1XjVu3dWGHoqVzvn4y1ScfLY/view

For installation instructions, check out this video tutorial that demonstrates how to use my Modbus and brain files:
Installation Video Tutorial: https://www.youtube.com/watch?v=5W5xKhg3cWQ&t=0s

If you want to create your own Modbus configuration and brain files, I’ve also created a step-by-step guide video:
Guide to Creating Modbus Configurations and Brain Files: https://www.youtube.com/watch?v=a6yTJGKSlRg&t=0s
Re: Arduino ModBus MPG problem
« Reply #4 on: January 06, 2025, 05:32:21 AM »
Hi
thanks for your interest and sharing your project.
I have been down the same road and got everything working
attached a few pics of my project, i'm busy documenting everything now
not got a google account but would be interested in your brains files for compare
"Brains" was the nighmare part of the project
regards
Servomac
Re: Arduino ModBus MPG problem
« Reply #5 on: January 06, 2025, 05:43:12 AM »
You have nice project!
When I started this project, I faced quite a few challenges. I have experience in microcontroller programming (STM32, GD32, etc.) and also possess Arduino programming skills. However, configuring Modbus and using Brain in Mach3 took me some time to learn. Understanding the difficulties users might encounter, I decided to share a detailed guide. I hope it will be helpful to everyone.
Dont need google acount to download my file, just click ang chose download if you interest
Re: Arduino ModBus MPG problem
« Reply #6 on: January 06, 2025, 06:28:04 AM »
Hi
tried to download from your link, it wants a google account and password before I can do anything.
Could you post your brains on here
many thanks
servomac
ps another pic supplied if your interested
Re: Arduino ModBus MPG problem
« Reply #7 on: January 06, 2025, 07:12:46 AM »
Here is the download link for my project from the Mediafire server. It includes both the Modbus configuration file and the brain file. However, the brain file is directly related to the Arduino source code and the creation and division of bytes in the Modbus configuration. They are directly connected, so comparing your file with mine doesn't hold much significance. I organize the data in the Modbus registers into 3 registers, each 16 bits (2 bytes). You can see this more clearly in the Arduino source code.
https://www.mediafire.com/file/5ldyl4loyz4xfxs/MPG_MODBUS.rar/file
Re: Arduino ModBus MPG problem
« Reply #8 on: January 06, 2025, 10:57:10 AM »
hi
never got to look at your coding
did not like cookie policy of mediafire, never sign up for using my data and there was no decline option and could not get past that page.
thanks for your input though
regards
servomac
Re: Arduino ModBus MPG problem
« Reply #9 on: January 15, 2025, 09:40:45 PM »
Hello servomac! can you show me how to cal caculate MPG tickcount ? i only send counter of timer 1 to "MPG tickcount". Is it correct?
MPG count is counter from encoder i can understand but MPG TickCount is not very clearly
« Last Edit: January 15, 2025, 09:43:13 PM by ngochoangimsat »