Sari la conținut
ELFORUM - Forumul electronistilor

Dual pulse timer


voodoo

Postări Recomandate

  • Răspunsuri 29
  • Creat
  • Ultimul Răspuns

Top autori în acest subiect

Top autori în acest subiect

Imagini postate

fara display momentan; ce display ai/vrei sa folosesti?

1602 clasic, sau cel cu intefata i2c?

#define buton 2
#define releu 3 //pin catre element actionare; releu, tiristor...
int stare[] = {0,1,0,1,0};	//stop puls pauza puls
int durata[] = {-1,100,100,100,1000}; //durate asociate ms
int nrPasi = sizeof(stare) / sizeof(stare[0]);
int pas = 0;
unsigned long now = 0L;
unsigned long timeStamp = 0L;

void setup(){
	pinMode(releu,OUTPUT);
	digitalWrite(releu,LOW);
	pinMode(buton,INPUT_PULLUP);
}

void loop(){
	digitalWrite(releu,stare[pas]);
	now = millis();
	if(pas == 0 && digitalRead(buton) == LOW){
		pas = 1;
		timeStamp = now;
	}
	if(pas > 0 && now > timeStamp + durata[pas]){
		pas ++;
		pas %= nrPasi;
		timeStamp = now;
	}
}
Link spre comentariu

 

fara display momentan; ce display ai/vrei sa folosesti?

1602 clasic, sau cel cu intefata i2c?

#define buton 2
#define releu 3 //pin catre element actionare; releu, tiristor...
int stare[] = {0,1,0,1,0};	//stop puls pauza puls
int durata[] = {-1,100,100,100,1000}; //durate asociate ms
int nrPasi = sizeof(stare) / sizeof(stare[0]);
int pas = 0;
unsigned long now = 0L;
unsigned long timeStamp = 0L;

void setup(){
	pinMode(releu,OUTPUT);
	digitalWrite(releu,LOW);
	pinMode(buton,INPUT_PULLUP);
}

void loop(){
	digitalWrite(releu,stare[pas]);
	now = millis();
	if(pas == 0 && digitalRead(buton) == LOW){
		pas = 1;
		timeStamp = now;
	}
	if(pas > 0 && now > timeStamp + durata[pas]){
		pas ++;
		pas %= nrPasi;
		timeStamp = now;
	}
}

Care vrei tu :) .

Îl comand pe cel care îţi place ţie .

 

Mulţumesc mult !

Am un I2C 128x64 , un Screen Blue Display Module For Arduino LCD 1602 Backlight 5V With HOT 1602A și un I2C 128x32 . Momentan .

Link spre comentariu

#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
#include <EEPROM.h>
#define lcdAddr 0x3F
#define buton 2
#define releu 13 //pin catre element actionare; releu, tiristor...
#define menuButtons A0

#define left 844
#define right 672
#define up 336
#define down 503
#define save 404

LiquidCrystal_PCF8574 lcd(lcdAddr);  // set the LCD address to 0x27 for a 16 chars and 2 line display

#define coolDown 1000
int stare[] = {0, 1, 0, 1, 0};	//stop puls pauza puls
int durata[] = { -1, 100, 300, 200, coolDown}; //durate asociate ms
int nrPasi = sizeof(stare) / sizeof(stare[0]);
int pas = 0;
int saveCount = 0;
unsigned long now = 0L;
unsigned long timeStamp = 0L;
unsigned long lastLcdUpdate = 0L;
unsigned long btnPressedTime = 0L;
int pos = 1;
bool posChanged = false;
bool skipLcd = false;

bool near(int value, int target) {
  int tolerance = 10;
  return (abs(target - value) <= tolerance);
}

void setup() {
  pinMode(releu, OUTPUT);
  digitalWrite(releu, LOW);
  pinMode(buton, INPUT_PULLUP);
  for (int addr = 0; addr < nrPasi; addr++) {
    durata[addr] = EEPROM.read(addr * 2);
  }
  durata[4] = coolDown;
  lcd.begin(16, 2); // initialize the lcd
  lcd.setBacklight(255);
  lcd.clear();
  Serial.begin(9600);
}

void loop() {

  digitalWrite(releu, stare[pas]);
  skipLcd = false;

  now = millis();
  if (pas == 0 && digitalRead(buton) == LOW) {
    pas = 1;
    timeStamp = now;
  }
  if (pas > 0 && now > timeStamp + durata[pas]) {
    pas ++;
    pas %= nrPasi;
    timeStamp = now;
    skipLcd = true;
  }
  if (skipLcd == true) return;

  if (now > lastLcdUpdate + 200) {
    char buffer[16];
    lcd.noCursor();
    sprintf(buffer, "W1=%4d W2=%4d", durata[1], durata[3]);
    lcd.setCursor(0, 0);  //col line
    lcd.print(buffer);
    lcd.setCursor(0, 1);
    sprintf(buffer, "PAUZA=%4d", durata[2]);
    lcd.print(buffer);
    if (pos == 0) lcd.setCursor(0, 0);
    if (pos == 1) lcd.setCursor(0, 1);
    if (pos == 2) lcd.setCursor(8, 0);
    lcd.cursor();

    int readBtnVal = analogRead(A0);
    if (readBtnVal > 100) {
      btnPressedTime = now;
      Serial.println(readBtnVal);
      if (near(readBtnVal, save)) {
        saveCount++;
      }
      else {
        saveCount = 0;
      }
      if (saveCount > 20) {
        pas = 0;
        digitalWrite(releu, LOW);
        saveCount = 0;
        lcd.clear();
        sprintf(buffer, " SALVARE ");
        lcd.setCursor(0, 0);
        lcd.print(buffer);
        sprintf(buffer, " PARAMETRI ");
        lcd.setCursor(0, 1);
        lcd.print(buffer);
        for (int addr = 0; addr < nrPasi; addr++) {
          EEPROM.write(addr * 2, durata[addr]);
        }
        delay(2000);
      }
      if (near(readBtnVal, left)) {
        Serial.println("left");
        pos--;
        posChanged = true;
      }
      if (near(readBtnVal, right)) {
        Serial.println("right");
        pos++;
        posChanged = true;
      }

      if (pos < 0) pos = 2;
      pos %= 3;

      if (posChanged == true) {
        posChanged = false;
        sprintf(buffer, "Pos = %d", pos);
        Serial.println(buffer);
      }

      int value = durata[pos + 1];
      if (near(readBtnVal, up)) {
        Serial.println("up");
        value += 10;
      }
      if (near(readBtnVal, down)) {
        Serial.println("down");
        value -= 10;
      }
      value = constrain(value, 10, 1000);
      //      if (value > 1000) value = 1000;
      //      if (value < 10) value = 10;
      durata[pos + 1] = value;
    }
    lastLcdUpdate = now;
  }
}

lcd 1602 cu adaptor i2c... fire putine, asta am acum de teste.

tastatura cu 4 butoane la meniu, unul pt sudura ...

 

BP20wpg.png

din schema cu butoane montezi doar B1...B4, si lasi rezistenta de 1k catre A0

salvarea parametrilor se face tinand apasate simultan up si down cateva secunde

are codata hard 1s intre actionarile consecutive, deci daca tii apasat continuu butonul de sudura va face secvente din secunda in secunda, nu mai repede

am facut o greseala la EEPROM, functiile tb asa:

  for (int addr = 0; addr < nrPasi; addr++) {
    durata[addr] = EEPROM.read(addr * 2) | EEPROM.read(addr * 2 + 1) << 8;
  }
        for (int addr = 0; addr < nrPasi; addr++) {
          EEPROM.write(addr * 2, durata[addr]);
          EEPROM.write(addr * 2 + 1, durata[addr] >> 8);
        }
Link spre comentariu

Corect, era 1 noaptea, nu mai vedeam prea bine :)

Cand mai am ceva timp, fac si versiunea pt lcd simplu.


teoretic, daca adugam in partea de sus

#define lcd_d7 9
#define lcd_d6 8
#define lcd_d5 7
#define lcd_d4 6
#define lcd_en 5
#define lcd_rs 4
#include "Adafruit_LiquidCrystal.h"
Adafruit_LiquidCrystal lcd(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7); // RS, E, D4, D5, D6, D7

si comentam liniile pt i2c

//#include <LiquidCrystal_PCF8574.h>
//LiquidCrystal_PCF8574 lcd(lcdAddr);  // set the LCD address to 0x27 for a 16 chars and 2 line display

ar trebui sa functioneze cu 1602 simplu

Link spre comentariu

Corect, era 1 noaptea, nu mai vedeam prea bine :)

Cand mai am ceva timp, fac si versiunea pt lcd simplu.

teoretic, daca adugam in partea de sus

#define lcd_d7 9
#define lcd_d6 8
#define lcd_d5 7
#define lcd_d4 6
#define lcd_en 5
#define lcd_rs 4
#include "Adafruit_LiquidCrystal.h"
Adafruit_LiquidCrystal lcd(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7); // RS, E, D4, D5, D6, D7

si comentam liniile pt i2c

//#include <LiquidCrystal_PCF8574.h>
//LiquidCrystal_PCF8574 lcd(lcdAddr);  // set the LCD address to 0x27 for a 16 chars and 2 line display

ar trebui sa functioneze cu 1602 simplu

Oricum comand şi adaptor de I2C .

 

PS : vă admir pe cei care puteţi învăţa aşa ceva .


   are codata hard 1s intre actionarile consecutive, deci daca tii apasat continuu butonul de sudura va face secvente din secunda in secunda, nu mai repede

Nu se poate să facă o singură dată ?

Link spre comentariu
#include <EEPROM.h>

/*
  // versiunea cu display i2c
  #include <Wire.h>
  #include <LiquidCrystal_PCF8574.h>
  #define lcdAddr 0x3F
  LiquidCrystal_PCF8574 lcd(lcdAddr);  // set the LCD address to 0x27 for a 16 chars and 2 line display
*/

//versiunea cu display clasic
#define lcd_d7 9
#define lcd_d6 8
#define lcd_d5 7
#define lcd_d4 6
#define lcd_en 5
#define lcd_rs 4
#include "Adafruit_LiquidCrystal.h"
//meniul Sketch -> Include Library -> Manage libraries -> Adafruit_LiquidCrystal in campul search -> butonul install
Adafruit_LiquidCrystal lcd(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7); // RS, E, D4, D5, D6, D7

#define buton 2
#define releu 13 //pin catre element actionare; releu, tiristor...
#define menuButtons A0

#define left 844
#define right 672
#define up 336
#define down 503
#define save 404

#define coolDown 200  //asta poate fi setat cat de mic, este pentru limitarea actionarilor prea rapide

int stare[] = {0, 0, 1, 0, 1, 0};	//wait ready puls pauza puls cool
int durata[] = { -1, -1, 100, 300, 200, coolDown}; //durate asociate ms
char* hlp[] = {"WAIT", "RDY ", "WLD1", "PAUS", "WLD2", "COOL"};
int nrPasi = sizeof(stare) / sizeof(stare[0]);
int pas = 0;
int saveCount = 0;
unsigned long now = 0L;
unsigned long timeStamp = 0L;
unsigned long lastLcdUpdate = 0L;
unsigned long btnPressedTime = 0L;
int pos = 1;
bool posChanged = false;
bool skipLcd = false;

bool near(int value, int target) {
  int tolerance = 10;
  return (abs(target - value) <= tolerance);
}

void setup() {
  pinMode(releu, OUTPUT);
  digitalWrite(releu, LOW);
  pinMode(buton, INPUT_PULLUP);
  for (int addr = 0; addr < nrPasi; addr++) {
    durata[addr] = EEPROM.read(addr * 2) | EEPROM.read(addr * 2 + 1) << 8;
  }
  durata[5] = coolDown;

  lcd.begin(16, 2); // initialize the lcd
  lcd.setBacklight(255);
  lcd.clear();
  Serial.begin(9600);
}

void loop() {

  digitalWrite(releu, stare[pas]);
  skipLcd = false;

  now = millis();
  if (pas == 0 && digitalRead(buton) == HIGH) {
    pas = 1;
    //    nu facem nimic pana nu eliberam butonul, asta blocheaza actionarile succesive daca tinem butonul apasat
  }
  if (pas == 1 && digitalRead(buton) == LOW) {
    pas = 2;
    timeStamp = now;
    // am apasat butonul, trecem la pasul urmator
  }
  if (pas > 1 && now > timeStamp + durata[pas]) {
    pas ++;
    pas %= nrPasi;
    timeStamp = now;
    skipLcd = true;
    // daca durata pasului actual depaseste cat am setat noi, trecem la urmatorul pas
  }
  
  if (skipLcd == true) return;
  //skipLcd sare peste actualizarea lcd-ului atunci cand schimbam pasul, avem treburi mai importante de facut
  //vom actualiza lcd-ul la urmatorul ciclu loop, in cateva milisecunde

  if (now > lastLcdUpdate + 200) {
    char buffer[16];
    lcd.noCursor();
    sprintf(buffer, "W1=%4d W2=%4d", durata[2], durata[4]);
    lcd.setCursor(0, 0);  //col line
    lcd.print(buffer);
    lcd.setCursor(0, 1);
    sprintf(buffer, "PAUZA=%4d %s", durata[3], hlp[pas]);
    lcd.print(buffer);
    if (pos == 0) lcd.setCursor(0, 0);
    if (pos == 1) lcd.setCursor(0, 1);
    if (pos == 2) lcd.setCursor(8, 0);
    lcd.cursor();

    int readBtnVal = analogRead(A0);
    if (readBtnVal > 100) {
      btnPressedTime = now;
      Serial.println(readBtnVal);
      if (near(readBtnVal, save)) {
        saveCount++;
      }
      else {
        saveCount = 0;
      }
      if (saveCount > 20) {
        pas = 0;
        digitalWrite(releu, LOW);
        saveCount = 0;
        lcd.clear();
        lcd.noCursor();
        sprintf(buffer, " SALVARE ");
        lcd.setCursor(0, 0);
        lcd.print(buffer);
        sprintf(buffer, " PARAMETRI ");
        lcd.setCursor(0, 1);
        lcd.print(buffer);
        for (int addr = 0; addr < nrPasi; addr++) {
          EEPROM.write(addr * 2, durata[addr]);
          EEPROM.write(addr * 2 + 1, durata[addr] >> 8);
        }
        delay(2000);
      }
      if (near(readBtnVal, left)) {
        Serial.println("left");
        pos--;
        posChanged = true;
      }
      if (near(readBtnVal, right)) {
        Serial.println("right");
        pos++;
        posChanged = true;
      }

      if (pos < 0) pos = 2;
      pos %= 3;

      if (posChanged == true) {
        posChanged = false;
        sprintf(buffer, "Pos = %d", pos);
        Serial.println(buffer);
      }

      int value = durata[pos + 2];
      if (near(readBtnVal, up)) {
        Serial.println("up");
        value += 10;
      }
      if (near(readBtnVal, down)) {
        Serial.println("down");
        value -= 10;
      }
      value = constrain(value, 10, 1000);
      //astea sunt limitele valorilor setate, minim 10, maxim 1000
      durata[pos + 2] = value;
    }
    lastLcdUpdate = now;
  }
}

cf cerinte. am mai adaugat in dreapta jos pasul la care este

Editat de deejay2k1
Link spre comentariu
  • 3 săptămâni mai târziu...

Cu acceptul colegului @digix, va prezint proiectul digix.ro/elforum/SpotWelder/, un controller un singur puls cu 328p si enconder. Este un proiect interesant si util dat fiind ca are doar un encoder pentru setare timp si actionare (se poate pune in paralel cu intrerupatorul encoderului un intrerupator exterior). Am incercat sa-l fac cu puls dublu, merge, dar functia de contorizare nu mai functioneaza. Mentionez ca sunt tabula rasa programare ........... daca asta e. Cum pot ''reinvia'' functia?

Multumesc.

 

 

/*
  Spot welder timer

  The circuit:

 Use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver.

  The circuit:
 * LCD (1) VSS pin to ground
 * LCD (2) VDD pin to +5V
 * LCD (3) VO wiper of 10K resistor, ends to +5V and ground
 * LCD (4) RS pin to digital pin 12
 * LCD (5) R/W pin to ground
 * LCD (6) Enable pin to digital pin 11
 * LCD (11) D4 pin to digital pin 5
 * LCD (12) D5 pin to digital pin 6
 * LCD (13) D6 pin to digital pin 7
 * LCD (14) D7 pin to digital pin 8
 * LCD (15) A to +5V
 * LCD (16) K to ground
 
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 6, 7, 8);

int encoderPin1 = 2;
int encoderPin2 = 3;
int encoderSwitchPin = 4; //push button switch
int ssRelayPin=13;
int buzzerPin=9;
int overtempPin=10;

volatile int lastEncoded,weldNumber = 0;
volatile long encoderValue = 0;

long lastencoderValue = 0;

int lastMSB = 0;
int lastLSB = 0;

float weldTime = 0;


void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.setCursor(0,0);
  lcd.print("  Spot welder   ");
  lcd.setCursor(0,1);
  lcd.print("   by Digix     ");
  delay(2000);
  lcd.clear();

  Serial.begin (9600);
  pinMode(ssRelayPin,OUTPUT);
  pinMode(buzzerPin,OUTPUT);
  pinMode(overtempPin, INPUT);
  pinMode(encoderPin1, INPUT);
  pinMode(encoderPin2, INPUT);

  pinMode(encoderSwitchPin, INPUT);


  digitalWrite(encoderPin1, HIGH); //turn pullup resistor on
  digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

  digitalWrite(encoderSwitchPin, HIGH); //turn pullup resistor on
  digitalWrite(overtempPin, HIGH); //turn pullup resistor on
  digitalWrite(ssRelayPin, LOW); //turn off SSR


  //call updateEncoder() when any high/low changed seen
  //on interrupt 0 (pin 2), or interrupt 1 (pin 3)
  attachInterrupt(0, updateEncoder, CHANGE);
  attachInterrupt(1, updateEncoder, CHANGE);
}

void updateEncoder(){  

  if (digitalRead(ssRelayPin) == HIGH)
  {
    tone(buzzerPin,100,200);
    digitalWrite(ssRelayPin, LOW);
    weldNumber = weldNumber -- ;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    SUDURA      ");    
    lcd.setCursor(0,1);
    lcd.print("  intrerupta    ");  
  }
  int MSB = digitalRead(encoderPin1); //MSB = most significant bit
  int LSB = digitalRead(encoderPin2); //LSB = least significant bit

  int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number
  int sum  = (lastEncoded << 2) | encoded; //adding it to the previous encoded value


  if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderValue ++;
  if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderValue --;

  lastEncoded = encoded; //store this value for next time
}

void loop() {

  if (encoderValue >=  102 ) encoderValue=0;
  if (encoderValue <= -2 ) encoderValue=100;
  weldTime= abs(encoderValue/20.0) ;
  if (weldTime>5)
  {
     weldTime=0;
  }
  lcd.setCursor(2,0);
  lcd.print(weldTime);
  lcd.setCursor(8,0);
  lcd.print("secunde");
  lcd.setCursor(8,1);
  if (digitalRead(overtempPin)==HIGH)
  {
   lcd.print("CALD    ");
   if ( millis() % 3000 ==0)
     {
     tone(buzzerPin,2000,10);
     delay(200);
     tone(buzzerPin,2000,10);
     delay(200);
     tone(buzzerPin,2000,10);
     }
  }
  else
  {
   lcd.print("OK=");
   lcd.print(weldNumber);
  }
  Serial.println(weldTime);

  if(digitalRead(encoderSwitchPin))
  {
  }
  else
  {
    //button is being pushed
    lcd.setCursor(0,1);
    if (weldTime>0 & digitalRead(overtempPin)==LOW)
    {
    lcd.print(" ATENTIE SUDEZ !");
    tone(buzzerPin,2000,4);
    digitalWrite(ssRelayPin,HIGH);
delay (100)
digitalWrite(ssRelayPin,LOW);
delay (100)
digitalWrite(ssRelayPin,HIGH);
    weldNumber = weldNumber ++;
    delay(weldTime*1000);
    tone(buzzerPin,2000,4);
    digitalWrite(ssRelayPin,LOW);
    lcd.setCursor(0,1);
    lcd.print("  pauza racire  ");
    delay(2000);
    tone(buzzerPin,1000,25);
    delay(130);
    tone(buzzerPin,1000,25);
    }
    else
    {
      if (digitalRead(overtempPin)==HIGH)
      {
        tone(buzzerPin,100,200);
        lcd.print("        CALD   ");
      }
      else
      {
        tone(buzzerPin,100,200);
        lcd.print("selectati durata");
      }
    delay(1000);
    }
    lcd.clear();
  }
}
Link spre comentariu

Alătură-te conversației

Poți posta acum și să te înregistrezi mai târziu. Dacă ai un cont, autentifică-te acum pentru a posta cu contul tău.
Notă: Postarea ta va necesita aprobare moderator înainte de a fi vizibilă.

Vizitator
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Răspunde la acest subiect...

×   Alipit ca text avansat.   Restituie formatare

  Doar 75 emoji sunt permise.

×   Linkul tău a fost încorporat automat.   Afișează ca link în schimb

×   Conținutul tău precedent a fost resetat.   Curăță editor

×   Nu poți lipi imagini direct. Încarcă sau inserează imagini din URL.




×
×
  • Creează nouă...

Informații Importante

Am plasat cookie-uri pe dispozitivul tău pentru a îmbunătății navigarea pe acest site. Poți modifica setările cookie, altfel considerăm că ești de acord să continui.Termeni de Utilizare si Ghidări