Go Down

Topic: Convert char (arrays of chars) to int (Read 779 times) previous topic - next topic

sreekanthmp

Good progress.

Try it. Write the code and see what happens.

However, if you detach the interrupt your seconds will not increment and the time for the hour meter will not be correct. If the machine is not running then perhaps it doesn't matter. You can also turn off the square wave it you don't want to count.


I need to detach the interrupt for only for a 2mscnd, meter will send the warning signal when engine oil pressure below the standard value.For doing this function i have used millis(), hence i should to detach the  interrupt for 2-3 mscnd.
It will not be happened  in engine off condition.


# how i can turnoff square wave?

cattledog

Quote
For doing this function i have used millis(), hence i should to detach the  interrupt for 2-3 mscnd.
This doesn't make sense to me. What is the conflict between a millis() timer, and the tick of your hour meter every second based on the rtc interrupt?

What are you seeing with the two things running together. Please post some code, or a simplified example, which demonstrates a problem when the two run together.

Quote
# how i can turnoff square wave?
You figured out how to turn it on, so I think you should be able to figure out how to turn it off.

sreekanthmp

This doesn't make sense to me. What is the conflict between a millis() timer, and the tick of your hour meter every second based on the rtc interrupt?
 be able to figure out how to turn it off.
I came to know that millis(), delay () , are not work while interrupt execution.So that i detach the interrupt on that function which i have using millis () for sending oil pressure warning signal.Is it correct?


cattledog

Quote
I came to know that millis(), delay () , are not work while interrupt execution.So that i detach the interrupt on that function which i have using millis () for sending oil pressure warning signal.
Quote
.Is it correct?
No. millis() will not advance inside an ISR, because other interrupts are disabled while the isr executes and millis() depends on interrupts. The millis() interrupt will be placed in a queue to execute when the isr finishes, so millis() advance will only be affected if the isr is poorly crafted. Your incrementing of the clock is fine, but remove the Serial printing from inside the ISR.

Serial printing, i2c communications, and other processes which rely on interrupts also do not belong inside an ISR. The out put to the monitor is actually taking place after the ISR finishes.

ISR's need to be fast and not call functions which use interrupts. For details, see https://gammon.com.au/interrupts


sreekanthmp

What are you seeing with the two things running together. Please post some code, or a simplified example, which demonstrates a problem when the two run together.


Here is my code:-

Code: [Select]







#include <EEPROM.h>
#include <Wire.h>
#include <Adafruit_GFX.h>////////////////oled
#include <Adafruit_SSD1306.h>////////////oled

#include <OneWire.h>/////////////////////Temp sensor
#include <DallasTemperature.h>///////////Temp sensor
#define ONE_WIRE_BUS A0//////////////////Temp sensor
OneWire oneWire(ONE_WIRE_BUS);//////////Temp sensor
DallasTemperature sensors(&oneWire);////Temp sensor
#define ONE_WIRE_BUS A0////////////////Temp sensor

#define OLED_Address 0x3C///////////////oled
Adafruit_SSD1306 oled(1);///////////////oled
//#include "Wire.h"
#define WIDTH     128//////////////////oled
#define HEIGHT     64/////////////////oled
#define NUM_PAGE    8/////////////////oled

#include "RTClib.h"///////////////////// rtc
RTC_DS3231 rtc;////////////////////////// rtc
#define deviceAddress 0b1101000   //0x68

#define NUMFLAKES 10/////////////////oled
#define XPOS 0///////////////////////oled
#define YPOS 1///////////////////////oled
#define DELTAY 2///////////////////oled
#define LOGO16_GLCD_HEIGHT 16///////oled
#define LOGO16_GLCD_WIDTH  16//////oled


const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;
const uint8_t EngineCommand = 8;
float temp;
unsigned long time_now = 0;
unsigned long currentMillis;
unsigned long EngoilPresdelay = 0; //millis();
unsigned long Engoildelay = 15000;

int EventState = 0;
int addr_secnd = 0;
int addr_Minute = 1;
int addr_hrs1 = 2;
int addr_hrs2 = 3;
int addr_hrs3 = 4;
int addr_hrs4 = 5;
int addr_hrs5 = 6;

int secnd = 0;
int Minute = 0;
int hrs1 = 0;
int hrs2 = 0;
int hrs3 = 0;
int hrs4 = 0;
int hrs5 = 0;
int value_secnd;
int value_Minute;
int value_hrs1;
int value_hrs2;
int value_hrs3;
int value_hrs4;
int value_hrs5;
int x6;
int x7;
int x8;




long lastTime = 1;
long seconds = EEPROM.read(addr_secnd);
long minutes = EEPROM.read(addr_Minute);
long hours = EEPROM.read(addr_hrs2);

void setup()
{
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
  rtc.begin();
  sensors.begin();
  Serial.begin(9600);
  Wire.begin();
  DateTime now = rtc.now();
  if (! rtc.begin())
  {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (rtc.lostPower())
  {
    Serial.println("RTC lost power, lets set the time!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  pinMode(ledPin, OUTPUT);
  pinMode(EngineCommand, INPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, FALLING);
  setSQW(0x00);
}

String time()
{
  String dataString = "";
  DateTime now = rtc.now();
  dataString += String(now.year(), DEC);
  dataString += String('.');
  dataString += String(now.month(), DEC);
  dataString += String('.');
  dataString += String(now.day(), DEC);

  dataString += String("    ");
  dataString += String(now.hour(), DEC);
  dataString += String(':');
  dataString += String(now.minute(), DEC);
  dataString += String(':');
  dataString += String(now.second(), DEC);
  return dataString;
}

void loop() {
  display();
    Serial.print(hours);
    Serial.print(":");
    Serial.print(minutes);
    Serial.print(":");
    Serial.println(seconds);
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  float sensorValue = analogRead(A1);////////////used pot.meter as pressure sensor
  if ( temp >= 24 && temp < 25  )
  {
    oled.setTextSize(1);
    oled.setTextColor(BLACK, WHITE);
    oled.setCursor(64, 24);
    oled.print(" TEMP-HIGH  ");
    oled.display();

  }

  else if ( temp >= 26   )
  {
    oled.setTextSize(1);
    oled.setTextColor(BLACK, WHITE);
    oled.setCursor(64, 24);
    oled.print("  ENG.OFF  ");
    oled.display();

  }
  if ( (sensorValue / 10) <= 2.00)
  {
    detachInterrupt(digitalPinToInterrupt(interruptPin));
    currentMillis = millis();
    if ( currentMillis - EngoilPresdelay >= Engoildelay )//////waiting 15 secnd to engine start
    {
      oled.setTextSize(1);
      oled.setTextColor(BLACK, WHITE);
      oled.setCursor(68, 11);
      oled.print(" PRES-LOW ");
      oled.display();


    }
    attachInterrupt(digitalPinToInterrupt(interruptPin), blink, FALLING);
  }




  digitalWrite(ledPin, HIGH);

  if (digitalRead(EngineCommand) == HIGH)
  {

    if (EventState < 1)
    {
      EEPROM.update(addr_secnd, seconds);
      EEPROM.update(addr_Minute, minutes);
      EEPROM.update(addr_hrs2, hours);
      Serial.print(EEPROM.read(addr_hrs2));
      Serial.print(EEPROM.read(addr_Minute));
      Serial.println(EEPROM.read(addr_secnd));
      EventState++;
    }
  }

}

void display()
{

  //unsigned long startTime = millis();
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  float sensorValue = analogRead(A1);
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE, BLACK);
  oled.setCursor(0, 0);
  oled.print(time());
  oled.drawLine(0, 10, 127, 10, WHITE);
  oled.drawLine(0, 11, 127, 11, WHITE);

  oled.setCursor(0, 14);
  oled.print((hours));//,":",(minutes));
  oled.print(":");
  oled.print((minutes));//,":",(minutes));
  oled.print(":");
  oled.print((seconds));//,":",(minutes));
  oled.setCursor(0, 24);
  oled.print((temp));
  oled.setCursor(0, 13);
  oled.print("E.O.P:");
  oled.print((sensorValue) / 10);

  oled.display();
  //Serial.print("Function Time = ");
  // Serial.println(millis() - startTime);
}
void blink() {
  if (digitalRead(EngineCommand) == LOW)
  {

    EventState = 0;
    
    if (lastTime > 0)
    {
      seconds++;

      //lastTime = millis();
    }
    if (seconds > 59)
    {

      minutes++;
      seconds = 0;

    }
    if (minutes > 59)
    {

      hours++;
      minutes = 0;
    }
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }

}
void setSQW(uint8_t value) {
  Wire.beginTransmission(deviceAddress); //device address and STSRT command are queued
  Wire.write(0x0E); //Control Register Address is queued
  Wire.write(0x00); //Data for Control Register is queued
  Wire.endTransmission(); //queued information are transferred under ACK; STOP
}





when engin oil pressure goes to below the 2g/cm2 give  the warning signal. In this area i have detach the interrupt. Initially i need  15msecnd delay  on before the warning signal shows.This for avoiding the unwanted pressure low signal, before the engine start .For this purpose i have used millis().

Go Up