M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

This is the place to talk about and share things related to CNC plasma machines using UCCNC

M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby beefy » Sat Oct 22, 2016 11:13 pm

The thread I previously started about this matter seemed to drift onto other things so I'm starting a new thread about it.

So at present is it safe to say we don't have a way of taking advantage of the laser output for synchronous torch on/off control during motion ??

I can work out a way to accomplish this with "external intelligence" (boy that sounds hi-tech :lol: ) but first wanted to make sure I'm not wasting my time if there's a way I haven't thought of using just UCCNC as it stands.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby Robertspark » Sat Oct 22, 2016 11:32 pm

Yeah.... I've got the same problem..... tested it this evening...

Can't use m3 m10, then m11 and m5 on the same pin.

I was going to use an attiny85 set as an OR gate, and then change its state once both pins were active to an AND gate.... would require the use of two output pins though... but I've got spare on the uc300eth

(The same thing could be done internally within uccnc if we had a checkbox telling uccnc it was setup as a plasma.... that way the code could take the shared pins and change their operating mode from an OR gate to an AND gate once both m3 and m10 were active....)

Sorry hope this isn't tainting your thread
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby beefy » Sun Oct 23, 2016 2:24 am

Hi Rob,

no you are not tainting my thread at all, you are actually on exactly the same page as me.

At present I'm looking at putting the functionality in the THC I'm working on but it could also be done with a few logic gates or like you are trying, a small micro.

I think this is a good one for a new feature suggestion, I'm going over to that section of the forum now.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby Robertspark » Sun Oct 23, 2016 9:44 am

Here's an Arduino Sketch for the ATTINY85 I've done (in the last 1/2 hr), not tested it yet, bit to add as I like some debounce + deal with timer rollover, but the general arrangement is there of my ideas for external hardware.

Code: Select all
// Arduino ATTINY85 Sketch for M3/M5 + M10/M11 AND OR Gate Operation for 2 Inputs to drive 1 Plasma Torch Output
// Robertspark 23/10/2016
// http://highlowtech.org/?p=1695

// requires, 2 input pins, 1 output pin, 5v ATTINY, Set clock to 8Mhz (1mHz default), and internal clock.

// to do, debounce + timer rollover.

int m3Pin = 3;     // M3-M5 (Spindle Input Pin)
int m10Pin = 4;    // M10-M11 (Sync Laser Input Pin)
int outputPin = 0; // Output Pin
int m3Val = 0;     // variable to store the m3Pin read value
int m10Val = 0;    // variable to store the m5Pin read value
int gate = 0;      // gate value (0 = OR, 1 = AND)


void setup()
{
  pinMode(m3Pin, INPUT);        // sets the digital pin 3 as input
  pinMode(m10Pin, INPUT);       // sets the digital pin 4 as input
 
  pinMode(outputPin, OUTPUT);   // sets the digital pin 0 as output
}

void loop()
{
  m3Val = digitalRead(m3Pin);   // read the M3input pin
  m10Val = digitalRead(m10Pin);   // read the M5input pin

  if (gate == 0)  // OR Gate
  {
    if (m3Val == 1 || m10Val == 1) // OR Gate Output
    {
      digitalWrite(outputPin, 1);    // sets the outputPin HIGH
    }
    if (m3Val == 0 && m10Val == 0)
    {
      digitalWrite(outputPin, 0);    // sets the outputPin LOW
    }
   
    if (m3Val == 1 && m10Val == 1) // set GATE HIGH only when both inputs are HIGH (ON) (ie M3+M10)
    {
      gate = 1;    // set GATE HIGH
    }
  }


  if (gate == 1)  // AND Gate
  {
    if (m3Val == 1 && m10Val == 1) // AND Gate Output (both inputs must be high)
    {
      digitalWrite(outputPin, 1);    // sets (keeps) the outputPin HIGH
    }
    else                          // either an M5 AND/OR an M11 has been issued (one or both inputs are low)
    {
      digitalWrite(outputPin, 0);    // sets the outputPin LOW
    }
      if (m3Val == 0 && m10Val == 0) // set GATE LOW only when both inputs are LOW (OFF) (ie M5+M11)
      {
        gate = 0;    // set GATE LOW
      }
  }
 
}
// END OF SKETCH


Seems to verify fine as ATTINY 85, 8Mhz Internal

Build options changed, rebuilding all

Sketch uses 854 bytes (10%) of program storage space. Maximum is 8,192 bytes.
Global variables use 15 bytes (2%) of dynamic memory, leaving 497 bytes for local variables. Maximum is 512 bytes.
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby beefy » Sun Oct 23, 2016 5:56 pm

Cheers Rob,

I started off with Arduino but then went to AVR and "normal" C. If you ever do that Atmel Studio / GCC may drive you potty when debugging (one of the reasons I left Arduino) and single stepping. The optimisation causes the single stepping to do plain weird things. I'm now looking at migrating to Codevision AVR which single steps nicely in the debugger at low optimisation.

Just a thought in case you ever move to AVR/C too. You'll also get much more compact code than what the Arduino spits out, especially if you have the compiler set at optimise for size.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby Robertspark » Sun Oct 23, 2016 6:07 pm

Thanks Keith for the heads up, I tend to use arduino for proof of concept... cut paste, copy code etc breadboard quickly...

With a single operation like this, the attiny85 is perfect by being compact, although im not sure about am the arduino overhead or the lack of interrupt pins....

I was this evening looking at pic32 development boards (... i wonder why ;) ).... more curious than for this application... keep wondering about thc ... 200mhz, 500ksps 10bit ADC?.... think neuron runs 16 bit.... I've got a separate 16bit higher sample rate ADC (think spi).... too many projects and not enough time.... (at present run a mini THC from po-mo / Denis in Russia)...
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby cncdrive » Sun Oct 23, 2016 7:45 pm

Rob,

If you are not very familiar with PIC microcontrollers yet then avoid the PIC32, it is a very complex microcontroller with lots of pitfalls, especially the MZ series.
It was basicly designed to be programmed with modules with a software called Harmony which I would say is totally useless if you want to really understand what you doing and what is exactly happening in the micro, and programming it in C is hard because of the complexity of this micro.
If you need a fast microcontroller then go with the 30F or 33F series, they are 16bits micros, not as fast as the 32 series, but is light-years easier to learn and use it.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby Robertspark » Sun Oct 23, 2016 8:27 pm

Balazs, thank you very much for that, very much appreciated, it's just a learning journey for me
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby Robertspark » Mon Nov 07, 2016 11:35 pm

ATTiny 85-20PU, via Atmel Studio

much faster code, set on 16mhz (-20puu version), using the internal clock

And very small (compared to arduino sketch below.... which needs a tweak...):
Program Memory Usage : 158 bytes 1.9 % Full
Data Memory Usage : 1 bytes 0.2 % Full

Code: Select all
/*
 * PlasmaM3M10.c
 *
 * Created: 07/11/2016 18:13:55
 * Author : robertspark
 */

#include <avr/io.h>

//#define _BV(bit) (1<<(bit))
#define bit_is_set(sfr,bit) (_SFR_BYTE(sfr) & _BV(bit))
#define bit_is_clear(sfr,bit) (!(_SFR_BYTE(sfr) & _BV(bit)))

// GET BIT from register address (p) and bit (m)
//#define bit_get(sfr,bit) ((_SFR_BYTE(sfr)) & (_BV(bit)))
// SET BIT at register address (p) and bit (m)
#define bit_set(sfr,bit) ((_SFR_BYTE(sfr)) |= (_BV(bit)))
// CLEAR BIT at register address (p) and bit (m)
#define bit_clear(sfr,bit) ((_SFR_BYTE(sfr)) &= ~(_BV(bit)))

// NOP short processor delay (1 cycle delay)
#define _NOP() do{__asm__ __volatile__ ("nop"); } while(0)

unsigned char gate = 0;

int main(void)
{
   bit_set (PORTB, PB3); // set port B, PB3 with internal pullup resistor
   bit_set (PORTB, PB4); // set port B, PB4 with internal pullup resistor

   bit_set (DDRB, DDB0); // set port B, DB0 as output
   
start_again:

    while (1)
    {
      _NOP();
      
      if ( bit_is_set( PINB, PINB3 ) &&  bit_is_set( PINB, PINB4 ) )
      {
         bit_clear ( PORTB, PB0 );
         gate = 0;
         _NOP();
         goto start_again;
      }
      
      if ( gate == 0 ) // OR gate
      {
         if ( bit_is_clear( PINB, PINB3 ) || bit_is_clear( PINB, PINB4 ) )
         {
            bit_set ( PORTB, PB0 );
         }
         if ( bit_is_clear( PINB, PINB3 ) &&  bit_is_clear( PINB, PINB4 ) )
         {
            gate = 1;
         }
         _NOP();
         goto start_again;
      }
      
      if ( gate == 1 ) // AND gate
      {
         if ( bit_is_clear( PINB, PINB3 ) &&  bit_is_clear( PINB, PINB4 ) )
         {
            bit_set ( PORTB, PB0 );
            _NOP();
            goto start_again;
         }
         if ( bit_is_clear( PINB, PINB3 ) ||  bit_is_clear( PINB, PINB4 ) )
         {
            bit_clear ( PORTB, PB0 );
            _NOP();
            goto start_again;
         }            
      }
   }   
}
// End of code

Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M10 / M11 FOR SYNCHRONOUS TORCH ON/OFF

Postby beefy » Wed Nov 09, 2016 5:34 am

Hi Rob,

here's my take on it using a mega328p but the code will be easily modified to any other AVR.

I'm using the idea of a mode output from UCcnc (input to the AVR). Then you can use gcode (macro), plugin, screen button, etc to put the AVR in "normal" mode or "synchronous" mode where it only listens to M10/11.

Now remember, in UCCNC, loss of M3 (i.e. M5) will also take away M10. And also in UCCNC you can't have M10 without first having M3. My code takes advantage of that to simplify things. So basically if the AVR is in "synchronous" mode it's only listening to M10/11 and ignores M3.

By the way if you Google about "GOTO" in C programming there's a zillion hits about it being a bad way of programming. I haven't looked into the reasons why but I just take the clever guys word for it, got enough on my plate at the moment without hurting my brain any more.

This code is based on active high inputs and outputs so if I made this circuit I'd use "pull DOWN" resistors on the inputs. With a noisy plasma environment I prefer external pull up/down resistors that allow plenty current to give better noise immunity.

I did this code with Codevision so it's got some slight differences from Atmel Studio. I initially tried in AS but when I did the single stepping the execution went stupid as usual. I put the optimisation to off in AS then it single stepped fine but that generates really crap lengthy code and I've found sometimes it just doesn't work. I do the same code with Codevision on low optimisation and it just works. Maybe I'm thick or something but I don't know how others survive with AS.

Code: Select all
/*
 * M3 M10 SYNCH CONTROL.c
 *
 * Created: 9/11/2016 3:51:59 PM
 * Author: BEEFY
 * NOTE - inputs and outputs are active HIGH so will need pull DOWN resistors
 */

#include <io.h>
#include <stdint.h>

#define      synchMode     (PINB & (1<<PINB2))   // Pin B2 input to set normal or synchronous torch on/off mode
#define      M3            PINB & (1<<PINB3)   // Pin B3 as input for spindle on/off (M3/M5)
#define      M10           PINB & (1<<PINB4)   // Pin B4 as input for laser on/off (M10/M11)

#define      Torch_ON      PORTB |= (1<<PORTB0)
#define      Torch_OFF     PORTB &= ~(1<<PORTB0)

void main(void)
{
   DDRB &= ~((DDB2) | (1<<DDB3) | (1<<DDB4));      // Port B2, B3 and B4 as input
   DDRB |= (1<<DDB0);                        // Port B0 as output

   while (1)
   {
      if (synchMode == 0)        // NOT in synchronous torch on mode
      {
         if (M3)
         {
            Torch_ON;
         }
         
         else
         {
            Torch_OFF;
         }
      }

      else                  // Then we ARE in synchronous torch mode
      {
         if (M10)            // Requires M10 for torch to fire (and M10 requires M3 in any case)
         {
            Torch_ON;
         }
         
         else               // Torch off if lose M10 (and loss of M3 (M5) will cause loss of M11 too)
         {
            Torch_OFF;
         }
      }
   }
}


I single stepped through it all and I think I covered every scenario but if you see anywhere that I stuffed up, or any improvements, please let me know.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Next

Return to CNC Plasma

Who is online

Users browsing this forum: No registered users and 0 guests