Monday, July 9, 2018


#include<dht.h>
#include<LiquidCrystal.h>
dht DHT;
#define DHT11_PIN 7

const int rs = 12, en = 8, d4 = 5, d5 = 4, d6 = 13, d7 = 2;
int temp=0;
int temp1=0;
float potchange=0;
int sensorPin=A0;
int RoomTemp=0;
int temperature_read=0;
int set_temperature=0;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
           pinMode(10,OUTPUT);
           pinMode(9,OUTPUT);
           Serial.begin(9600);   

           // Recording Room Temperature in Initial Setup
           int chk = DHT.read11(DHT11_PIN);
           for(int i=0; i<=100; i++)
            {
              lcd.begin(16, 2);
              lcd.setCursor(2, 0);
              lcd.print("Initial Setup");
              lcd.setCursor(5, 1);
              lcd.print(i);
              RoomTemp=(int)DHT.temperature;
              lcd.setCursor(9, 1);
              lcd.print(RoomTemp);
 
              delay(100);
            }         
}
void loop()
{

      // Reading Potentiometer
      temp=analogRead(sensorPin);
      potchange=temp;
      temp1=15+(temp/1023.0)*41.0;
   
      set_temperature=temp1;
      temperature_read= DHT.temperature;
     
      // For Reading DHT11
      int chk = DHT.read11(DHT11_PIN);
     
      // Printing on LCD
      lcd.setCursor(0, 0);
      lcd.print("Set Temp: ");
      lcd.setCursor(10, 0);
      lcd.print(temp1);
      lcd.setCursor(13, 0);
      lcd.print("C");
      lcd.setCursor(0,1);
      lcd.print("Actual Temp:");
      lcd.print((int)DHT.temperature);
      lcd.setCursor(15,1);
      lcd.print("C");

     // Printing on Serial Monitor
      Serial.print("Set Temperature = ");
      Serial.println(temp1);
      Serial.print("Current Temperature = ");
      Serial.println(DHT.temperature);

     // Relay Polarity
     
     if(set_temperature>=RoomTemp)
      {
            digitalWrite(9,HIGH);
            digitalWrite(10,HIGH);
      }
       else if(set_temperature<RoomTemp)
      {
            digitalWrite(9,LOW);
            digitalWrite(10,LOW);
      }
     
      delay(2000);
}

Saturday, September 30, 2017

Process Statements in VHDL (Explicit Signal Assignments)

Signal assignments that we have seen so far were Implicit,that is they were executed any time. Whenever the signal on their right hand side changed the value of signal on the left hand side was updated.

We use a Process in VHDL to execute the statements in sequence.Along with the Explicit signal assignments it can also consist of the Simple signal assignment statements we have seen so far.

The Syntax of using a process is as follows :

Process (Sensitivity_List)

Constant declarations
Type declarations
Variable declarations

Begin
         Sequential Statement 1;
         Sequential Statement 2;
         .
         .
         .
         .
         Sequential Statement n;
End Process

Process is the keyword declaring the process

* Sensitivity_List is a list of inputs that a process would require

* All the local variables that are needed are declared between the Process and Begin statement

* The actual function of the process is written between the Begin and End Process statements

Previous : Selected signal assignment
Next: Sequential Statements

Signal Assignments in VHDL (Part 3)

$. Selected Signal Assignment

Syntax of Selected Signal Assignment is

with <select_sig_expression> select
<signal_name>  <= <expression_1> when <condition_1> ,
                  <expression_2> when <condition_2> ,
                  .
                  .
                  .
                  <expression_n> when others       ;


<signal_name>   is the name of the signal whose value is to be updated/assigned

* <=                          is the signal assignment operator

* with,select and when  are the keywords for selected signal assignment

* <select_sig_expression> is the signal/expression that is monitored for the change of condition

<condition_n>   is the condition

<expression_n> is the expression or value to be assigned to the signal on L.H.S,when its                                                 corresponding condition occurs

* when others  implies condition/s apart from the ones that are mentioned
   Thus the expression or value corresponding to 'when others' is assigned if none of the condition          mentioned are satisfied.



Example:

with sel select

y <= a when "00"
     b when "01"
     c when "10"
     d when others ;

a,b,c,d,sel are the input pins/signals
y  is the output pin/signal
All the signals are declared in the entity part of the program

Output signal y depends on the value of sel signal,
That is the Output signal y is the value of signal a when signal sel is 00, it is the value of signal b when signal sel is 01,it is the value of signal c when signal sel is 10 and it outputs the value of signal d when sel is neither equal to any of the values mentioned.

As signal sel changes, output signal y updates its value to the value of signal a,b,c or d.

Previous : Conditional Signal Assignment
Next: Explicit Process Statements

Thursday, June 29, 2017

Signal Assignments in VHDL (Part 2)



$. Conditional Signal Assignment

Condition Signal allows us to decide when a signal should get updated
Syntax of the Conditional Signal Assignment is

<signal_name>  <= <expression_1> when <condition_1> else
                  <expression_2> when <condition_2> else
                  .
                  .
                  .
                  <expression_n> when <condition_n> else
                  <expression> ;

* <signal_name>   is the name of the signal whose value is to be updated/assigned

* <=                          is the signal assignment operator

* when and else  are the keywords for conditional signal assignment

* <condition_n>   is the condition

* <expression_n> is the expression or value to be assigned to the signal on L.H.S,when its                                                 corresponding condition occurs

* The last expression or value is assigned if none of the condition is satisfied.


Example:

y <= a when s='0' else
     b ;

a,b,s are the input pins/signals
y  is the output pin/signal
All the signals are declared in the entity part of the program

Output signal y is the value of signal a when signal s is 0
As soon as signal s becomes 1, output signal y updates its value to the value of signal b.
Signal a and b can have same or different values,depending on the signal s,y is either equal to a or b.

Previous : Simple Signal Assignment
Next: Selected Signal Assignment

Monday, June 26, 2017

Signal Assignments in VHDL (Part 1)




As Discussed in the previous post,there are three different types of Signal Assignments-
1. Simple Signal Assignment
2. Conditional Signal Assignment
3. Selected Signal Assignment

Syntax's of each type of signal assignments are given as --

$. Simple Signal Assignment



<signal_name> <= <expression> ;

<signal_name>  is the name of signal to which a value or an expression is to be assigned

<=                          is the signal assignment operator
                                     Note that it is an <= and not just an equal to sign =

<expression>     is the expression or a value
                                  As soon as some value in an expression changes an implicit process is
                                  called and the new value is assigned to the signal

Example:

<= a xor b 

a,b are the input pins/signals
c is the output pin/signal
a,b and c are declared in entity part of the program

Signal c is the logical xor of signal a and signal b

If either or both of input signals a or b change their value, signal c changes accordingly.


Previous : Fundamentals of writing an architecture in VHDL
Next : Conditional Signal Assignment 


Saturday, June 24, 2017

Fundamentals of writing an Architecture in VHDL




The basic aim of an Architecture is to obtain an output signal/s when input signal/s are applied.
It generates an output signal on the output pin (a pin which can write to) based on the input signals applied on the input pin (a pin which can be read from). The input and output pin/ports are declared in the entity part of the program.
Thus the code written inside Architecture specifies the logical relation between input and output.

An Architecture is modeled with the use of -
* Signals,variables,user defined types and operators
* Signal assignment statements
* Processes

$. Signal Assignment Statements (Implicit Process)

Signal assignment implies a process(function) that is executed in parallel when anything on the right hand side of the assignment changes.

Three types of Signal Assignment Statements are -
* Simple Signal Assignment
* Conditional Signal Assignment (When else statements)
* Selected Signal Assignment (With select statements)



$. Process

A process in VHDL architecture is a set of statements that are executed sequentially and not in parallel.
A process can be declared explicitly and the sequential statements that can be used inside a process are -
* Simple Signal Assignment
* If-Then Statements
* Case Statements
* Looping Statements
* Wait Statements


Previous: Getting started with VHDL
Next : Signal Assignments in VHDL (Part 1)

Friday, June 23, 2017

Getting Started with VHDL





A VHDL program consists of 4 Main Design Units

1.Entity
-It is how the system is viewed externally

2.Architecture
-It is a description of functionality (Schematic)

3.Configuration
-It assosciates Entity and Architecture

4.Package
-It is used to store a Reusable code(Library)



$. ENTITY DECLARATION SYNTAX :
 

Entity <name_of_entity> is

Generic Declarations
Port Declarations

end <name_of_entity>;


*  <name_of_entity> is any alphanumeric name given to the entity

*  Generic Declarations are used to pass information into a model

*  Port Declarations are used to describe the input,output pins



$. Port Declaration Syntax:
 

Port(
port_name1:<mode> <type> ;
port_name2:<mode> <type> ;
.
.
.
port_nameN:<mode> <type> 
);



* port_name is a name given to the port/pin

* <mode> is used to specify the direction of data flow through that pin,
                   modes are-
in         -for input
                  input signals can only be read from
out          -for output
           output signals can only be written to
inout     -bidirectional
buffer -output with internal feedback
          physically it is an output pin but can also be read

* <type> is used to specify the data type of the port
            Some of the commonly used types are-
  STD_LOGIC - Declares a Standard Logic Bit which can have values
                     0 (logic low)
                     1 (logic high)
              x (Unknown)
                     z (Tristate)
                     - (Don't Care)

  STD_LOGIC_VECTOR(m downto 0) - Declares a Standard Logic Vector of m+1 bits                    where port_name(m) signifies the MSB and port_name(0) signifies the LSB.

Note that Every port declaration ends with a semi-colon except the last one


$. ARCHITECTURE :
 
Architecture describes the internal logic of our model,the outside world can only see the port connections and the parameters passed to it.
Note: An architecture must be associated to an Entity
  Entity can have multiple architecture.


Syntax of Architecture:



Architecture <identifier> of <name_of_entity> is

Declaration of variables that aren't ports or generics

Begin
.
.
.
Body of Architecture 
.
.
.
End Architecture <identifier> ;

* <identifier> is the name given to the architecture
* Variables that aren't ports or generics are declared before Begin
   these variables are generally Temporary Signals or Constants for interconnections.
* Body of Architecture is the description of functionality and timing of the model.
    It consists of executable statements


Next : Fundamentals of  writing an architecture in VHDL

#include<dht.h> #include<LiquidCrystal.h> dht DHT; #define DHT11_PIN 7 const int rs = 12, en = 8, d4 = 5, d5 = 4, d6 = 13...