Re: Independent PWM signal output
Hello.
I have now programmed an Arduino that makes the 0-5v signal in Pul and dir signals for a stepper motor.
Now I can regulate the pump for my minimum amount of cooling via the GUI.
It would be nice to have a slider like the speed and feed override.
Is there another way to display the current status of the PWM signal? (Apart from the red / green lights)?
Re: Independent PWM signal output
This sounds cool, but I personally would have used I2C to talk to the Arduino as you could then just send exact numbers that would give more precise control and more likely a larger range of speeds. I control my spindle doing something like this as I found the analog output from the board not to be vary accurate, but also my spindle didn't respond in a linear way and was often out by 5-10%. I now use I2C to a small board that talks RS485 to the VFD and it is now exact.
1 Attachment(s)
Re: Independent PWM signal output
USB communication with external hardware is powerful and very useful thing.
Unless I have simple modules I prefer to use it. This way I can implement all logic in MCU.
Regarding sliders. I attached Btn file with some interesting examples. I'm sure you'll find it uswful.
1 Attachment(s)
Re: Independent PWM signal output
1. There are couple of examples with Arduino included in API folder
2. Button with menu is not enough? See image.
3. You can display your value in state panels as a number.
Re: Independent PWM signal output
I followed the following tutorial.
But I can't find the parameter to display the PWM signal anywhere, not even in the Doko PDFs.
In addition, I would like to only display certain LEDs of the inputs and outputs. So e.g. only LED from input 1 and 2.
https://planet-cnc.com/create-custom...-tng-software/
Re: Independent PWM signal output
Re: Independent PWM signal output
Sample folder contains StatePanels with state panels examples. Most of parameters are included.
Re: Independent PWM signal output
Quote:
Originally Posted by
PlanetCNC
3. You can display your value in state panels as a number.
How can I do that. Which parameters do I have to enter. The state.txt files in the Sampels folder do not help me because this example is not available there.
Also on my second question how I can only display a single LED of the output / input / limit, I can't find it there.
Re: Independent PWM signal output
[QUOTE=tantemay;2414856... Also on my second question how I can only display a single LED of the output / input / limit, I can't find it there.[/QUOTE]
OK. Find it.
Re: Independent PWM signal output
After a long search I have now found it. But I'm still looking for a way to display a single PWM LED.
Re: Independent PWM signal output
Code:
param _hw_output_duty1 0 "MMS-Level:"
How do I have to change the code so that the displayed value is divided by 50?
Re: Independent PWM signal output
expr: "res = _hw_output_duty1 / 50" 1 "My Value"
1 Attachment(s)
Re: Independent PWM signal output
Quote:
Originally Posted by
PlanetCNC
expr: "res = _hw_output_duty1 / 50" 1 "My Value"
Do not work.
I don't mean in the Bnt.txt, I mean the State.txt file.
Re: Independent PWM signal output
use expr without ":"
expr "res = _hw_output_duty1 / 50" 1 "My Value"
Re: Independent PWM signal output
Thanks that works fine.
---
I have one more question about the buttons.
Is it possible to make a button that increases the current value of the PWM signal each time it is pressed?
Re: Independent PWM signal output
Quote:
Originally Posted by
theRat
This sounds cool, but I personally would have used I2C to talk to the Arduino as you could then just send exact numbers that would give more precise control and more likely a larger range of speeds. I control my spindle doing something like this as I found the analog output from the board not to be vary accurate, but also my spindle didn't respond in a linear way and was often out by 5-10%. I now use I2C to a small board that talks RS485 to the VFD and it is now exact.
would you mind detailing how you did this to control your spindle speeds?
Re: Independent PWM signal output
Quote:
Originally Posted by
mharter11
would you mind detailing how you did this to control your spindle speeds?
Sorry for the slow reply, I have been in hospital to have a hip replaced.
The general concept is to have an atmel microcontroller (I used a ATTiny1614) connected to the Mk3/4 SD&I2C header. The circuit also has a SN6517B rs485 transceiver connected to a USART on the ATTiny and then off to the RS485 pins on the VFD over a twisted pair cable.
For the software on the ATTiny I originally implemented all the commands needed to control a NowForever vfd, which kept the M3/4/5 scripts quite straightforward, but the problem with this was that if it was to be used for another brand of vfd the ATTiny would need new code. So I have since changed it so that the ATTiny only does the comms and has no idea about the required protocol and now the Plantet CNC scripts deal with the protocol. This means that the code on the ATTiny doesn't need to change to implement controlling different vfd's, just new scripts.
The board I designed also has a TCA9535 on it (I2C expander) to allow for control of up to 16 relays (my board has 4 on it, and drivers for 2 off board relays).
So for me now I have a bunch of scripts to help with turning the spindle on/off and controlling the speed. This is part of what I have for controlling my NowForever VFD.
M3.gcode
Code:
;set spindle speedO<SetSpindleSpeed> call
;turn on spindle pump
#<_i2c_output_0> = OR[#<_i2c_output_0>,#<_coolant_pump>]
O<SetI2COutput0> call
;run forward
O<SetSpindleRun> call [1]
O<PlanetCNC> if [#<_spindle_delay_start> GT 0]
O<Delay> if [#<_spindlespeed> GT 18000]
G04 P[#<_spindle_delay_start>*2]
O<Delay> elseif [#<_spindlespeed> GT 12000]
G04 P[#<_spindle_delay_start>*1.5]
O<Delay> else
G04 P#<_spindle_delay_start>
O<Delay> endif
O<PlanetCNC> endif
M3
SetSpindleSpeed.sub
Code:
;Control NOWFOREVER spindle speed
O<SetSpindleSpeed> sub
;fill buffer with parameters to set spindle speed
#<speed_lo> = SHR[[#<_spindlespeed>*100/60],8]
#<speed_hi> = AND[[#<_spindlespeed>*100/60],255]
(array,4000,1,#<_vfd_addr>,16,9,1,0,1,2,#<speed_lo>,#<speed_hi>)
O<Crc16> call [4002] [#4000-1]
#<crc> = [#<_return>]
O<test> if [EXISTS[#<_rs485_debug>]]
(print,crc=#<crc,0>)
O<test> endif
;add the crc16 value to the end of the buffer
#[4001+#4000] = AND[#<crc>,255]
#[4002+#4000] = SHR[#<crc>,8]
#4000 = [#4000+2]
;print request buffer if debug is on
O<test> if [EXISTS[#<_rs485_debug>]]
#<size> = [#4000]
(print,Request Size=#<size,0>)
#<i> = 0
O<print1> repeat [#4000]
#<q> = [#[4001+#<i>]]
(print,#<q,0>)
#<i> = [#<i>+1]
O<print1> endrepeat
O<test> endif
;zero the return count and send the buffer to the i2c bus
#<count> = 0
O<loop1> do
#<err> = 0
#4100 = 0
M66 H38 Q4001 E#4000 R4100 D4 ;set the spindle speed
O<test> if [EXISTS[#<_rs485_debug>]]
#<size> = [#4100]
(print,Response Size=#<size,0>)
#<i> = 0
O<print1> repeat [#4100]
#<q> = [#[4101+#<i>]]
(print,#<q,0>)
#<i> = [#<i>+1]
O<print1> endrepeat
O<test> endif
#<count> = [#<count>+1]
O<error1> if [ACTIVE[] AND [#4100 NE 3]]
O<test1> if [#<count EQ 5]
(dlgname,Spindle Error, opt=1)
(dlg,Failed to set spindle speed, typ=label, x=20, w=280, color=0xffa500)
(dlg,Response size wrong, typ=label, x=20, w=280)
(dlgshow)
M2
O<test1> else
#<err> = 1
O<test1> endif
O<error1> endif
;check the crc16 of the response
O<Crc16> call [4101] [#4100-2]
#<crc> = [#<_return>]
O<error2> if [ACTIVE[] AND [[#4102 NE AND[#<crc>,255]] OR [#4103 NE SHR[#<crc>,8]]]]
O<test2> if [#<count EQ 5]
(dlgname,Spindle Error, opt=1)
(dlg,Failed to set spindle speed, typ=label, x=20, w=280, color=0xffa500)
(dlg,Response crc wrong, typ=label, x=20, w=280)
(dlgshow)
M2
O<test2> else
#<err> = 1
O<test2> endif
O<error2> endif
;check that the request didn't have a bad crc
O<error3> if [ACTIVE[] AND [#4101 NE 0]]
O<test3> if [#<count EQ 5]
(dlgname,Spindle Error, opt=1)
(dlg,Failed to set spindle speed, typ=label, x=20, w=280, color=0xffa500)
(dlg,Request crc wrong, typ=label, x=20, w=280)
(dlgshow)
M2
O<test3> else
#<err> = 1
O<test3> endif
O<error3> endif
O<loop1> while [#<err> EQ 1]
;pause to give time for the rs485 vfd comms to complete
G04 P0.02
;now reqest for the vfd response
#4000 = 2
#<w> = 0
O<wait> do
G04 P0.01
;zero the return count and send the buffer to the i2c bus
#4100 = 0
M66 H38 Q4000 E1 R4100 D10 ; request the response data
O<test> if [EXISTS[#<_rs485_debug>]]
#<size> = [#4100]
(print,Response Size=#<size,0>)
#<i> = 0
O<print2> repeat [#4100]
#<q> = [#[4101+#<i>]]
(print,#<q,0>)
#<i> = [#<i>+1]
O<print2> endrepeat
O<test> endif
;check the crc16 of the response
O<test> if [#4101 EQ 0]
O<Crc16> call [4102] [#4100-3]
O<test> else
O<Crc16> call [4101] [#4100-2]
O<test> endif
#<crc> = [#<_return>]
O<error2> if [ACTIVE[] AND [[#[4100+#4100-1] NE AND[#<crc>,255]] OR [#[4100+#4100] NE SHR[#<crc>,8]]]]
O<test4> if [#<w> EQ 5]
(dlgname,Spindle Error, opt=1)
(dlg,Failed to set spindle speed, typ=label, x=20, w=280, color=0xffa500)
(dlg,Response crc wrong, typ=label, x=20, w=280)
(dlgshow)
M2
O<test4> else
#4101 = 1
O<test4> endif
O<error2> endif
#<w> = [#<w>+1]
O<test> if [ACTIVE[] AND [#<w> EQ 5]]
(dlgname,Spindle Error, opt=1)
(dlg,Failed to set spindle speed, typ=label, x=20, w=280, color=0xffa500)
(dlg,Response timeout, typ=label, x=20, w=280)
(dlgshow)
M2
O<test> endif
O<wait> while [#4101 NE 0]
O<test> if [EXISTS[#<_rs485_debug>]]
(print,Wait loops=#<w,0>)
O<test> endif
O<SetSpindleSpeed> endsub
CRC16.sub
Code:
; function to calculate the modbus crc16 of a buffer; takes 2 input parameters
; 1. start address of the buffer
; 2. count of bytes in buffer
; returns the crc16 value
O<Crc16> sub
#<start> = #1
#<count> = #2
#<crc> = 65535
#<i> = 0
O<Loop1> repeat [#<count>]
#<crc> = XOR[#<crc>,[#[#<start>+#<i>]]]
#<j> = 0
O<BLoop> repeat [8]
O<if1> if [AND[#<crc>,1] EQ 0]
#<crc> = SHR[#<crc>,1]
O<if1> else
#<crc> = XOR[SHR[#<crc>,1],40961]
O<if1> endif
#<j> = [#<j>+1]
O<BLoop> endrepeat
#<i> = [#<i>+1]
O<Loop1> endrepeat
O<Crc16> return [#<crc>]
O<Crc16> endsub
I have been meaning to write this all up properly and publish on a website, but I haven't had the time. I am also not sure if there is enough interest to make it worthwhile.
Cheers
Simon