Hello Guest it is April 23, 2024, 02:08:19 PM

Author Topic: Pwm pokeys57cnc mach4  (Read 2703 times)

0 Members and 1 Guest are viewing this topic.

Pwm pokeys57cnc mach4
« on: July 27, 2019, 12:12:28 PM »
hi,

i would like to modify the duty cycle of pwm pins inside a macro and i don't find the way to do it, if someone could post an exemple or give me some advice i'll we be happy

thx
Re: Pwm pokeys57cnc mach4
« Reply #1 on: July 28, 2019, 08:25:29 AM »
i'm slowly getting things to work,

Code: [Select]
function m6()

local inst = mc.mcGetInstance()

selectedtool = mc.mcToolGetSelected(inst)


currenttool = mc.mcToolGetCurrent(inst)


local signalinv = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2) --deverouillage, contacte relais pour inversion moteur

local signalfait = mc.ISIG_INPUT2

function GetpokReg(regname) -- fonction pour lire le registre du pokeys
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_42447/%s", regname))
return mc.mcRegGetValueString(hreg)

end
--regval = GetpokReg("PWM 18 duty")


function WritepokReg(regname, regvalue) -- fonction pour ecrire sur registre pokeys
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_42447/%s", regname))
mc.mcRegSetValueString(hreg, tostring(regvalue))

end
--WritepokReg("PWM 18 duty", 25)





mc.mcCntlSetLastError(inst, "Changement demandé "..tostring(currenttool).."a"..tostring(selectedtool))
wx.wxMilliSleep(1000)



if (selectedtool == currenttool)then

mc.mcCntlSetLastError(inst, "inutile")
wx.wxMilliSleep(1000)

--regval = GetpokReg("PWM 18 duty")
--mc.mcCntlSetLastError(inst, regval)
--wx.wxMilliSleep(1000)

end

mc.mcCntlSetLastError(inst, "changement en cour")  -- debut du changement
mc.mcCntlGcodeExecute(inst, "G00 Z-5.0")

mc.mcSignalSetState(signalinv, 1)
WritepokReg("PWM 18 duty", 0.9)


local switchH = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2)
local switchstate = mc.mcSignalGetState(switchH)


if (switchstate == 1)then --controle de l'état du capteur position tourelle'

mc.mcCntlSetLastError(inst, "degagement capteur")
wx.wxMilliSleep(1000)
local check2 = mc.mcSignalWait(inst,signalfait, mc.WAIT_MODE_LOW,10) --on attend 5 sec max que le capteur soi degagé

if (check2 ~= 0)then --controle degagement capteur arrivé tourelle

mc.mcCntlCycleStop(inst)
mc.mcCntlSetLastError(inst, "Annulé capteur bloqué")
wx.wxMilliSleep(1000)
mc.mcCntlCycleStop(inst)

end

mc.mcCntlSetLastError(inst, "capteur degagé")
wx.wxMilliSleep(1000)

end


mc.mcCntlSetLastError(inst, "en cours attente capteur tourelle")
local check = mc.mcSignalWait(inst,signalfait, mc.WAIT_MODE_HIGH,15) --on attend 15 seconde que le capteur passe a 1

if (check ~= 0)then --controle arrivé en position tourelle
WritepokReg("PWM 18 duty", 0) --le capteur n'est pas passé a 1 pwm et relais au repos/vérouillage
mc.mcSignalSetState(signalinv, 0)
mc.mcCntlSetLastError(inst, "Annulé probleme tourelle")
wx.wxMilliSleep(1000)
mc.mcCntlCycleStop(inst)

else --le capteur est passé a 1 on coupe tout puis repasse le pwm a 30
WritepokReg("PWM 18 duty", 0) -- pour maintenir la tourelle
mc.mcSignalSetState(signalinv, 0)
WritepokReg("PWM 18 duty", 0.3)
mc.mcCntlSetLastError(inst, "changement ok !")
mc.mcToolSetCurrent(inst, selectedtool)
wx.wxMilliSleep(1000)


end
end
if (mc.mcInEditor() == 1)then
m6()
end


the pwm is ok but the macro seems to run multiple time at least 2 sometime 3

This macro will be for the emco C 5 cnc atc, output2 control a relay to inverse the dc motor, pin18 pwm drive dcdriver a 90% duty while changing tool, then 30% for the reverse to lock the turret  and input2 is used to check if the turret has moved
Re: Pwm pokeys57cnc mach4
« Reply #2 on: July 28, 2019, 10:19:19 AM »

i'm slowly getting things to work,

Code: [Select]
function m6()

local inst = mc.mcGetInstance()

selectedtool = mc.mcToolGetSelected(inst)
currenttool = mc.mcToolGetCurrent(inst)

local signalinv = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2) --deverouillage, contacte relais pour inversion moteur
local signalfait = mc.ISIG_INPUT2

function GetpokReg(regname) -- fonction pour lire le registre du pokeys
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_42447/%s", regname))
return mc.mcRegGetValueString(hreg)

end
--regval = GetpokReg("PWM 18 duty")


function WritepokReg(regname, regvalue) -- fonction pour ecrire sur registre pokeys
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_42447/%s", regname))
mc.mcRegSetValueString(hreg, tostring(regvalue))

end
--WritepokReg("PWM 18 duty", 25)

if (mc.mcInEditor() == 1)then
m6()
end



mc.mcCntlSetLastError(inst, "Changement demandé "..tostring(currenttool).."a"..tostring(selectedtool))
wx.wxMilliSleep(1000)



if (selectedtool == currenttool)then

mc.mcCntlSetLastError(inst, "inutile")
wx.wxMilliSleep(1000)

--regval = GetpokReg("PWM 18 duty")
--mc.mcCntlSetLastError(inst, regval)
--wx.wxMilliSleep(1000)

else

mc.mcCntlSetLastError(inst, "changement en cour")  -- debut du changement
mc.mcCntlGcodeExecute(inst, "G00 Z-5.0")

mc.mcSignalSetState(signalinv, 1)
WritepokReg("PWM 18 duty", 0.9)


local switchH = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2)
local switchstate = mc.mcSignalGetState(switchH)


if (switchstate == 1)then --controle de l'état du capteur position tourelle'

mc.mcCntlSetLastError(inst, "degagement capteur")
wx.wxMilliSleep(1000)
local check2 = mc.mcSignalWait(inst,signalfait, mc.WAIT_MODE_LOW,10) --on attend 5 sec max que le capteur soi degagé

if (check2 ~= 0)then --controle degagement capteur arrivé tourelle

mc.mcCntlCycleStop(inst)
mc.mcCntlSetLastError(inst, "Annulé capteur bloqué")
wx.wxMilliSleep(1000)
mc.mcCntlCycleStop(inst)

end
end

mc.mcCntlSetLastError(inst, "capteur degagé")
wx.wxMilliSleep(1000)




mc.mcCntlSetLastError(inst, "en cours attente capteur tourelle")
local check = mc.mcSignalWait(inst,signalfait, mc.WAIT_MODE_HIGH,15) --on attend 15 seconde que le capteur passe a 1

if (check ~= 0)then --controle arrivé en position tourelle
WritepokReg("PWM 18 duty", 0) --le capteur n'est pas passé a 1 pwm et relais au repos/vérouillage
mc.mcSignalSetState(signalinv, 0)
mc.mcCntlSetLastError(inst, "Annulé probleme tourelle")
wx.wxMilliSleep(1000)
mc.mcCntlCycleStop(inst)


else --le capteur est passé a 1 on coupe tout puis repasse le pwm a 30
WritepokReg("PWM 18 duty", 0) -- pour maintenir la tourelle
mc.mcSignalSetState(signalinv, 0)
WritepokReg("PWM 18 duty", 0.3)
mc.mcCntlSetLastError(inst, "changement ok !")
mc.mcToolSetCurrent(inst, selectedtool)
wx.wxMilliSleep(1000)
end
end
end


the pwm is ok but the macro seems to run multiple time at least 2 sometime 3

This macro will be for the emco C 5 cnc atc, output2 control a relay to inverse the dc motor, pin18 pwm drive dcdriver a 90% duty while changing tool, then 30% for the reverse to lock the turret  and input2 is used to check if the turret has moved