CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

K40 laser water control

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PrinceNai



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

K40 laser water control
PostPosted: Sun Apr 21, 2019 9:35 pm     Reply with quote

Dear All,

I recently bought a cheap laser cutter, which will be operated by my friend that has time, will and ideas of what to do with plastics. After spending some time on the net we decided to make a water cooling system that is a little better than just relying on the temperature inertia of 10l tank of water. The idea is this:

The controller will have the control over a peltier driven cooling tank, it will measure two temperatures and will be checking if the water pump is working by means of a Hall effect water flow sensor. All the data will be shown on an 4x20 LCD, with a piezo buzzer to wake up the operator if something goes wrong. Two things can. Either the temperature of the water is too high for some (as yet unknown) time or the pump dies. In either case it will shut down the laser tube.

It is a very simple project with respect to the code, so I don't need any coding assistance, at least not so far. What I would need is some input of where (the water tank definitely, the other location is probably at the exit of the laser tube) and how fast I should measure the temperature. Maybe PID control is needed. It is also meant as a project for all potential laser enthusiasts that read this.

I know I'm stretching the usage of this forum, but I've found the ideas and replies here very useful for uncounted number of times and that is why I'm asking and posting this. So if you administrators find this out of the playing field, just delete the topics and forgive me for wasting your time.

I will make a PCB board for this that will accept 20 and 40 pin PIC-s. I only need one, but the Chinese guys will send me at least 20 for the same price. If there will be any interest, the rest of them will be available for free, just for the price of shipping.

I whipped together a skeleton of a code for the controller (the temperature measuring is working 100%), just a sketch. It uses just the first temperature sensor. It is still in a process of going from floats to integers, flow sensor hasn't arrived yet and the program is missing the timing, output actions and very likely some possible "problem" scenarios. That is where your input would be much appreciated. How to do it correctly.



Code:

#include    <thermo_1820.h>
#include    <string.h>
#include    <i2c_Flex_LCD_driver.c>          //LCD driver
#include    <1wire_2_sensors.c>
#include    <ds1820_2_sensors.c> 
       
//float          Temperature1 = 0;                     //temperature from 1820 in deg. Celsius
//float          Temperature2 = 0;                     //temperature from 1820 in deg. Celsius   
signed int16         Temperature1 = 0;                     //temperature from 1820 in deg. Celsius
float          Temperature2 = 0;                     //temperature from 1820 in deg. Celsius   


#define WATER_TOO_HOT 220
                               
// *********************** FUNCTIONS ******************************************
void Service_Temperature1 (){
                                                                                         
//   Temperature1 = DS1820_read1();                     // change to correct DS1820 pin in 1Wire.c
   DS1820_read1();
   Delay_Cycles(1);
   Delay_ms(30);             
   lcd_gotoxy(1,1);                                                                                         
   Delay_ms(30);                                                                                     
   lcd_putc("Water tank: ");                               
   Delay_ms(30);
   printf(lcd_putc,"%3.1w", Temp3);
   Delay_ms(30);
   lcd_putc('\xDF');                         // degree sign, works!!!         
   Delay_ms(30);
}

void Service_Temperature2 (){
                                                                                         
   Temperature2 = DS1820_read2();                     // change to correct DS1820 pin in 1Wire.c
   Delay_Cycles(1);
   Delay_ms(30);                               
   lcd_gotoxy(1,2);                                                                                         
   Delay_ms(30);                                                                                     
   lcd_putc("Laser tube: ");                               
   Delay_ms(30);
   printf(lcd_putc,"%3.1F", Temperature2);
   Delay_ms(30);
   lcd_putc('\xDF');                         // degree sign, works!!!         
   Delay_ms(30);
}                             
                                   

#INT_TIMER1                                           
void  TIMER0_isr(void) {
   output_toggle(PIN_B5);                                                 
}

void main() {     
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);      //50 ms overflow
   enable_interrupts(INT_TIMER1);                                                                                     
   enable_interrupts(GLOBAL);
//   port_b_pullups(true);                                               
   lcd_init();                // init LCD   
   Delay_ms(100);
   lcd_putc('\f');            //CLEAR lcd     
   lcd_gotoxy(1,1);
   Delay_ms(100);
   lcd_putc("K40 WATER CONTROL");
   delay_ms(2000);                                                       
   lcd_putc('\f');            //CLEAR lcd     
   lcd_gotoxy(1,1);
                                                   
   while(TRUE){                                         
                                                 
      Service_Temperature1 ();     
      Service_Temperature2 ();                       
     
 // ...........CHECK WATER TEMPERATURE AND TURN ON COOLING IF NEEDED...........
      if(Temp3 > WATER_TOO_HOT){
         output_low(PIN_C6);
         lcd_gotoxy(1,3);             
         lcd_putc("WATER COOLING IS ON ");
         
      }
      else{                                                                                   
         output_high(PIN_C6);
         lcd_gotoxy(1,3);             
         lcd_putc("WATER COOLING IS OFF"); 
      }
// ................ CHECK IF THE WATER PUMP IS WORKING.........................
                                           
      if(TRUE){
         lcd_gotoxy(1,4);                                         
         lcd_putc("WATER IS CIRCULATING");           
      }
      else{                                                         
         lcd_gotoxy(1,4);                           
         lcd_putc("PUMP IS NOT WORKING ");                 
     
      }
// .............. MEASURE FOR HOW LONG THE WATER IS TOO HOT ...................

                                         
                                       
// ............................................................................
     
   }
                                                 
}


Regards,
Samo
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Sun Apr 21, 2019 11:27 pm     Reply with quote

I'd do two things:

I'd measure the temperature at the exit of the tube.
I'd measure the flow _at the same point or just after_.

This way, the water has to be flowing through the tube to be detected
by the flow meter, and must pass the temperature sensor to be detected
by the meter.

If you detect before this point, there is always the possibility of a leak
between the flow detection point and the temperature sensor.

For simple 'emergency' detection, you don't need PID. This would be
required for control.

Your logic seems slightly wrong. You turn off the tube if the temperature
is too high, but not if the water pump fails. Remember if the pump
fails there will not be water flowing to the temperature sensor. So
there may well not be an over temperature reading....

So logic:

Test if flow?.
No. Cut laser.

Yes. Test if temperature outside threshold?.
Yes. Cut laser.

No. Run Laser.

Now I say 'threshold'. You might want to also cut the laser, if the
temperature reads as <1C. This could imply water would be frozen, or
that the temperature sensor is disconnected. Either could be failure
reasons...
temtronic



Joined: 01 Jul 2010
Posts: 9102
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 5:15 am     Reply with quote

general comments
1) use 2 flow sensors. relying on just ONE sensor is what caused the MAX8s to crash. I'd put 2nd at the tank outlet. If they're calibrated the same, the flows should be the same.

2) PID is not needed. simple bang-bang controller is fine.If you have an RTC, have it send a 1HZ interrupt. this 'triggers' the 'read the temp sensors' routine,update the display, etc. Temperature is usually a long term 'event', IE slooooow, you don't need 1,000s of updates. I run my solar controller and bldg heating systems this way since the 16C84 with no complaints.

3) a 'power up- selftest' function is needed. Confirm water flows, temp sensors agree, etc. BEFORE running 'main()'.

4) use separate pins for the temp sensors. Makes for simple coding, easier wiring.

Jay
PrinceNai



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 5:56 am     Reply with quote

Quote:

You turn off the tube if the temperature
is too high, but not if the water pump fails


As I said, the code is more of a sketch, far from finished. It will shut down the K40 in both cases, independently. Water too hot or no flow ---> shut down.

Quote:

a 'power up- selftest' function is needed. Confirm water flows, temp sensors agree, etc. BEFORE running 'main()'.


Maybe that won't be needed, because upon power-up the pump should be working, but not the laser tube itself. It fires after one loads the shape to be cut and presses go button, and that takes some time. My control is active in 2 or 3 seconds and will be monitoring things way before that.


Quote:

use separate pins for the temp sensors.Makes for simple coding, easier wiring.


That is the way it is done already. Two DS1820 sensors, two separate pins. Sorry I didn't send the whole code, you couldn't see that.

Two flow sensors are a good thing and I'll place them as you suggested, at the exit from the tube. I won't use RTC, instead I'll just use timer interrupt to make the program execute measurements and any actions approx. once every second. And WDT every 2,3s to restart if it hangs. I also think that it'll work without PID. It is a 40W laser and I have 120W cooling elements (two peltiers glued on a small water tank). The water will be cooled to some 18 degrees Celsius and laser will shut down when it comes above 20. The cooling will start as soon as it goes above 18. I'll add the check for below zero temperature, but as long as I pay the bills, that won't happen :-).
PrinceNai



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 6:07 am     Reply with quote

Once again for below 1 degree. That is the reason for two temperature sensors, but maybe I'll throw in the third. As long as two of them agree on the temperature, I'm fine.
temtronic



Joined: 01 Jul 2010
Posts: 9102
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 7:08 am     Reply with quote

re:
upon power-up the pump should be working

hmm, 'should be'. you need to confirm before, never assume. I had to replace a 10K$ xray tube as someone 'assumed' the safety circuitry was functioning.

do you use RO water for cooling ?
PrinceNai



Joined: 31 Oct 2016
Posts: 452
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Apr 22, 2019 9:16 am     Reply with quote

When the machine is powered up, the pump starts pushing the water around, but the laser itself isn't on yet. Within 2 seconds I'll have the temperatures and the indication of the water flow, so no way the laser will fire if the pump isn't working. Maybe I should add a few minutes delay at startup to ensure that the water is mixed and at the correct temperature, both in the tube and in the tank.

I'm using distilled water and am thinking of adding a TDS meter.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group