Tuesday, 29 July 2025

Testbench Code 2

 `timescale 1ns / 1ps


module traffic_light_tb();


reg clk;

reg reset;


wire red;

wire yellow;

wire green;


traffic_light_controller dut( .clk(clk), .reset(reset), .red(red), .yellow(yellow),

  .green(green) );


always #5 clk = ~clk; 


initial begin

  clk = 0;

  reset = 1;

  #10 reset = 0;


  #100 $finish;

end


always @(posedge clk) begin

  $display("RED=%b YELLOW=%b GREEN=%b", red, yellow, green);

end


endmodule. 

Design Code 2

 `timescale 1ns / 1ps


module traffic_light_controller(

  input clk, reset, 

  output reg red, yellow, green );


localparam RED = 3'b001; 

localparam YELLOW = 3'b010;

localparam GREEN = 3'b100;


reg [2:0] state; 


always @(posedge clk)

begin

  if (reset) 

    state <= RED;

  else

    case (state)

      RED: begin

        red <= 1'b1;

        yellow <= 1'b0;

        green <= 1'b0;

        state <= YELLOW;

      end


      YELLOW: begin

        red <= 1'b0;

        yellow <= 1'b1; 

        green <= 1'b0;

        state <= GREEN;

      end


      GREEN: begin

        red <= 1'b0;

        yellow <= 1'b0;

        green <= 1'b1;

        state <= RED;

      end

    endcase

end


endmodule. 

Testbench Code 1

 `timescale 1ns / 1ps


module vending_machine_tb;

    // Inputs

    reg clk, reset, cancel;

    reg [1:0] coin, sel;

    

    // Outputs

    wire PrA, PrB, PrC, change;


    // Instantiate the vending machine module

    vending_machine uut (

        .clk(clk),

        .reset(reset),

        .cancel(cancel),

        .coin(coin),

        .sel(sel),

        .PrA(PrA),

        .PrB(PrB),

        .PrC(PrC),

        .change(change)

    );


    // Clock Generation: 10ns period (50MHz clock)

    always #5 clk = ~clk; 


    // Test Procedure

    initial begin

        // Initialize Inputs

        clk = 0;

        reset = 1;

        cancel = 0;

        coin = 2'b00;

        sel = 2'b00;

        

        // Hold reset for 20 ns

        #20 reset = 0;


        // Test Case 1: Insert Rs. 5 and Buy Product A

        #10 coin = 2'b01;   // Insert Rs. 5

        #10 sel = 2'b00;    // Select Product A

        #10 coin = 2'b00;   // Stop inserting coins

        #20;


        // Test Case 2: Insert Rs. 10 and Buy Product B

        #10 coin = 2'b10;   // Insert Rs. 10

        #10 sel = 2'b01;    // Select Product B

        #20;


        // Test Case 3: Insert Rs. 5 twice (Total Rs. 10) and Buy Product A (Expect Rs. 5 change)

        #10 coin = 2'b01;   // Insert Rs. 5

        #10 coin = 2'b01;   // Insert Rs. 5 again (Total Rs. 10)

        #10 sel = 2'b00;    // Select Product A

        #20;


        // Test Case 4: Insert Rs. 20 and Buy Product C

        #10 coin = 2'b10;   // Insert Rs. 10

        #10 coin = 2'b10;   // Insert Rs. 10 again (Total Rs. 20)

        #10 sel = 2'b10;    // Select Product C

        #20;


        // Test Case 5: Insert Rs. 10 and Cancel Transaction

        #10 coin = 2'b10;   // Insert Rs. 10

        #10 cancel = 1;     // Press Cancel

        #10 cancel = 0;     // Release Cancel

        #20;


        // End Simulation

        #50 $finish;

    end


    // Monitor the signals

    initial begin

        $monitor("Time = %d, Coin = %b, Sel = %b, Cancel = %b, PrA = %b, PrB = %b, PrC = %b, Change = %b",

                  $time, coin, sel, cancel, PrA, PrB, PrC, change);

    end


endmodule


Design Code 1

 Design Code:

`timescale 1ns / 1ps


module vending_machine(

    input clk, reset, cancel,

    input [1:0] coin, sel,

    output reg PrA, PrB, PrC, change

);


    // State encoding using parameter 

    parameter S0 = 3'b000, S5 = 3'b001, S10 = 3'b010, S15 = 3'b011, S20 = 3'b100;


    reg [2:0] current_state, next_state;


    // Sequential logic for state transition

    always @(posedge clk or posedge reset) begin

        if (reset)

            current_state <= S0; // Reset to initial state

        else

            current_state <= next_state;

    end


    // Next State Logic (Combinational)

    always @(*) begin

        case (current_state)

            S0: begin

                if (coin == 2'b01) next_state = S5;

                else if (coin == 2'b10) next_state = S10;

                else next_state = S0;

            end


            S5: begin

                if (coin == 2'b01) next_state = S10;

                else if (coin == 2'b10) next_state = S15;

                else if (cancel) next_state = S0;

                else next_state = S5;

            end


            S10: begin

                if (coin == 2'b01) next_state = S15;

                else if (coin == 2'b10) next_state = S20;

                else if (cancel) next_state = S0;

                else next_state = S10;

            end


            S15: begin

                if (coin == 2'b01) next_state = S20;

                else if (cancel) next_state = S0;

                else next_state = S15;

            end


            S20: begin

                if (cancel) next_state = S0;

                else next_state = S20;

            end


            default: next_state = S0; // Default state

        endcase

    end


    // Output Logic

    always @(posedge clk or posedge reset) begin

        if (reset) begin

            PrA <= 0;

            PrB <= 0;

            PrC <= 0;

            change <= 0;

        end 

        else begin

            // Default values (avoid latches)

            PrA <= 0;

            PrB <= 0;

            PrC <= 0;

            change <= 0;


            case (current_state)

                S5: begin

                    if (sel == 2'b00) begin

                        PrA <= 1;  // Product A (Rs. 5)

                        change <= 0; // No change needed

                    end

                end

                

                S10: begin

                    if (sel == 2'b00) begin

                        PrA <= 1;  // Product A (Rs. 5)

                        change <= 1; // Rs. 5 change

                    end

                    else if (sel == 2'b01) begin

                        PrB <= 1; // Product B (Rs. 10)

                        change <= 0; // No change needed

                    end

                end

                

                S15: begin

                    if (sel == 2'b01) begin

                        PrB <= 1;  // Product B (Rs. 10)

                        change <= 1; // Rs. 5 change

                    end

                end

                

                S20: begin

                    if (sel == 2'b00) begin

                        PrA <= 1;

                        change <= 1; // Rs. 15 change

                    end

                    else if (sel == 2'b01) begin

                        PrB <= 1;

                        change <= 1; // Rs. 10 change

                    end

                    else if (sel == 2'b10) begin

                        PrC <= 1; // Product C (Rs. 20)

                        change <= 0; // No change needed

                    end

                end

            endcase

            

            // Handle cancellation (return money)

            if (cancel) 

                change <= 1;

        end

    end

endmodule


Sunday, 13 July 2025

IOT LAB EXP 4.2 PROGRAM

 #include <ESP8266WiFi.h>

 #include "Adafruit_MQTT.h"
 #include "Adafruit_MQTT_Client.h"
 #define WLAN_SSID "ECE_STAFF_ROOM"
  #define WLAN_PASS "specnet@23"
 #define AIO_SERVER "io.adafruit.com"
 #define AIO_SERVERPORT 1883
 #define AIO_USERNAME "ChanduPrasanth"
 #define AIO_KEY "aio_WIaH72ooBeG8RlOfFJxF3a1DRGXV"
 // Create an ESP8266 WiFiClient class to connect to the MQTT server.
 WiFiClient client;
 // Setup the MQTT client class by passing in the WiFi client and
 // MQTT server and login details.
 Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
 // Setup a feed called iot-lab-exp04-attendance for publishing.
 Adafruit_MQTT_Publish attendanceFeed = Adafruit_MQTT_Publish(&mqtt,
 "ChanduPrasanth/feeds/iot attendance");
 void connectMQTT() {
 Serial.print("Connecting to Adafruit IO...");
 while (mqtt.connected() == false) {
 if (mqtt.connect()) {
 Serial.println("Connected to Adafruit IO !");
 } else {
 Serial.println("Failed to connect to Adafruit IO, retrying in 5s...");
 delay(5000);
 }
 }
 }
 void setup() {
 Serial.begin(115200);
 delay(10);
 Serial.println("Adafruit MQTT demo");
 // Connect to WiFi access point.
 Serial.println(); Serial.println();
 Serial.print("Connecting to ");
 Serial.println(WLAN_SSID);
 WiFi.begin(WLAN_SSID, WLAN_PASS);
 while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(".");
 }
 Serial.println();
 Serial.println("WiFi connected");
 Serial.print("IP address: "); Serial.println(WiFi.localIP());
 connectMQTT();
 }
 
 void loop() {
 // Now we can publish stuff!
 Serial.print("Sending Attendance ");
 Serial.print("...");
 if (mqtt.connected()){
 // Replace your 10-Digit roll number here
 if (! attendanceFeed.publish("22261A0400")) {
 Serial.println("Failed");
 } else {
 Serial.println("OK!");
 }
 }
 delay(5000);
 }

IOT LAB EXP 4.1 PROGRAM

 #include <ESP8266WiFi.h>
 #include <ESP8266HTTPClient.h>
 const char* ssid = "ECE_STAFF_ROOM";
 const char* password = "specnet@23";
 String server = "http://api.thingspeak.com/update";
 String apiKey = "65AZ09LAJJKJQ0D3";
 WiFiClient client;
 #include <DHT.h>
 #define DHTPIN 4
 #define DHTTYPE DHT11
 DHT dht(DHTPIN,DHTTYPE);
 float h;
 float t;
  void setup() {
 Serial.begin(115200);
 WiFi.begin(ssid, password);
 Serial.print("Connecting.");
 while(WiFi.status() != WL_CONNECTED){
 delay(1000);
 Serial.print(".");
 }
 Serial.println(": Connected to WiFi!");
 dht.begin();
 }
 void loop() {
 h = dht.readHumidity();
 t = dht.readTemperature();
 HTTPClient http;
 // Place your 10-digit roll number in the string below
 String url = server + "?api_key=" + apiKey + "&field1=22261A0400" +
 "&field2="+String(h) + "&field3="+ String(t);
 http.begin(client,url);
 int httpCode = http.GET();
 if(httpCode > 0){
 Serial.println("Data Sent Successfully");
 }else{
 Serial.println("Error sending data");
 }
 http.end();
 delay(5000);

 } 

Sunday, 6 July 2025

IOT LAB EXP3 PROGRAM


 #include <ESP8266WiFi.h>

 #include <ThingSpeak.h>
 #include <DHT.h>
 #define DHTPIN 4
 #define DHTTYPE DHT11
 const char* ssid = "PLACEMENTDRIVE";
 // Replace with your Wi-Fi SSID
 const char* password = "specplacements"; // Replace with your Wi-Fi password
 unsigned long ch_id = 2995467; // Replace with your ThingSpeak Channel ID
 const char* apiKey = "EW2AWHPQ8QW31G1V"; // Replace with your ThingSpeak API Key
 DHT dht(DHTPIN, DHTTYPE);
 WiFiClient client;

 
 void setup() {
 Serial.begin(9600);
 dht.begin();
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(".");
 }
 Serial.println("WiFi connected");
 ThingSpeak.begin(client);
 }
 void loop() {
 
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 if (isnan(h) || isnan(t)) {
 Serial.println("Failed to read from DHT sensor!");
 return;
 }
 int httpCode = ThingSpeak.writeField(ch_id, 1, "Chandu:"+String(h)+","+String(t), apiKey);
 
 if(httpCode == 200){
 Serial.println("Channel write successful.");
 }else{
 Serial.println("Problem writing to channel. HTTP error code " + String(httpCode) );
 }
 delay(20000); // Wait 20 seconds before next reading
 }

Install NodeMCU Board Support Package

  1. Open the Arduino IDE.

 2. Go to File Preferences.

 3. In the Additional Boards Manager URLs eld, add the following URL for NodeMCU support:

 https://arduino.esp8266.com/stable/package_esp8266com_index.json 

 4. Click OK. 5. Go to Tools Board Boards Manager. 

 6. Search for esp8266 and install the package

IOT Architectures and Protocols Laboratory

CLIK HERE :   IOT LAB HANDOUTS

Sunday, 7 November 2021

Reasoning Study Material/Notes pdf

COMING SOON

Quantitative Aptitude Study Material/Notes

COMING SOON--------------------------------

Technical Seminar Topics for ECE- RADAR BULLETS

RADAR BULLETS

VERILOG STUDY NOTES

COMING SOON

Digital Electronics/STLD/DLD STUDY MATERIAL/NOTES- COMBINATIONAL CIRCUITS

COMBINATIOANL CIRCUITS --------------------coming soon--------------------------

Digital Signal Processing- IIR Filters Study Material Download

Download IIR FILTERS STUDY MATERIAL/NOTES HERE:

Digital Signal Processing -FIR FILTERS STUDY MATERIAL

FIR FILTERS NOTES DOWNLOAD HERE

Digital Signal Processing Study Material/Notes

Multirate Signal Processing