# Compact Discrete-Time Chaotic Oscillator (180nm CMOS)
**eSim FOSSEE Research Migration Project**

**Author:** Akshat Sharma  
**Institution:** VIT Bhopal University  
**Reference Paper:** M. Priya, G. Swetha, R. Gupta and A. Pandey, "Compact chaotic oscillator using 1 80nm CMO S technology for its use in true random number generator," 2017 International Conference on Recent Innovations in Signal processing and Embedded Systems (RISE), Bhopal, India, 2017, pp. 366-370, doi: 10.1109/RISE.2017.8378183. keywords: {Chaotic communication;Oscillators;Generators;CMOS technology;Cryptography;Integrated circuits;CMOS;TRNG;Chaotic oscillator;V-shape;chaos map},

## Project Overview
This repository contains the complete eSim/KiCad schematic and Ngspice simulation files required to reproduce a high-frequency, discrete-time chaotic oscillator. The design utilizes a highly compact, three-transistor nonlinear core to generate an inverse tent-map (V-shape) characteristic, creating the mathematical stretching and folding necessary for sustained chaos.

The circuit features custom transistor sizing and a 1.05x gain compensation buffer to overcome physical loop losses and parasitic damping. To ensure strict open-source compliance and reproducibility, the design has been fully parameterized to use the generic 180nm CMOS BSIM3 models natively bundled with eSim.

## Directory Structure

### Root Directory (`new_final/`)
* `abstract_esim_akshat (1).pdf` : The comprehensive project report, containing the mathematical theory, block diagrams, and expected output plots.
* `README.md` : This documentation file.
* `ChaoticOscillator.proj` & `.projectExplorer` : eSim environment tracking files.
* `Images/` : Folder containing simulation output screenshots and schematic captures.
* `ChaoticOscillator2/` : **[MAIN WORKSPACE]** Contains all schematic and simulation files.

### Simulation Directory (`new_final/ChaoticOscillator2/`)
* `ChaoticOscillator2` (KiCad Schematic & Project) : The native eSim/KiCad 6 schematic files.
* `ChaoticOscillator2.cir` : The raw exported SPICE netlist.
* `ChaoticOscillator2.cir.out` : **(MAIN EXECUTION FILE)** The heavily augmented netlist containing the `.control` block, embedded library calls, multi-frequency transient analysis, and customized plotting commands.
* `NMOS-180nm.lib` & `PMOS-180nm.lib` : The native, open-source 180nm CMOS device models required for simulation.
* `VIN_vs_Time.raw` & `ChaoticOscillator2.raw` : The raw transient simulation data outputs.

## How to Run the Simulation

To verify the chaotic behavior, strange attractor, and discrete-time stepping, you can run the simulation using either the native eSim GUI or the Ngspice terminal. 

### Method 1: Using the eSim GUI (Primary Method)
1. Launch the **eSim** application on your system.
2. Click on **Open Project** and navigate to the extracted `new_final` directory. 
3. Select the `ChaoticOscillator` project to load the workspace.
4. Click on the **Simulation** button in the eSim left-hand toolbar.
5. The software will automatically read and execute the heavily augmented `ChaoticOscillator2.cir.out` file.
6. The distinct plot windows will render automatically.

### Method 2: Using the Ngspice Terminal (Manual Method)
If you prefer to run the simulation directly without opening the schematic editor:
1. Ensure `Ngspice` is installed on your system (ships natively with eSim).
2. Open your terminal or command prompt and navigate into the `ChaoticOscillator2` directory:
   ```bash
   cd new_final/ChaoticOscillator2
   ngspice ChaoticOscillator2.cir.out

## ⚠️ Important Disclaimer for Developers (Re-Exporting the Netlist)

The `ChaoticOscillator2.cir.out` file provided in this repository has been meticulously configured with advanced convergence options, relative library paths, and custom multi-frequency plotting commands to ensure seamless execution. 

If you open the KiCad schematic and click the **"KiCad to Ngspice"** button in the eSim GUI, eSim will overwrite this configured script with a raw, un-plotted netlist and strip the library linkages. 

**If you freshly convert the schematic to a netlist, you MUST manually add the following code blocks back into the newly generated `.cir.out` file to restore functionality and get the correct outputs:**

**1. Add the Libraries (At the very top of the file):**
Add these lines immediately below the initial `.title` line to import the native 180nm models:
```spice
.INCLUDE "NMOS-180nm.lib"
.INCLUDE "PMOS-180nm.lib"

2. Add the Convergence & Plotting Routine (At the very bottom of the file):
Delete any default .control block that eSim generated at the bottom, and replace it with this exact block to configure the transient analysis and generate the chaos plots:

Code snippet
.OPTIONS RELTOL=0.02 ABSTOL=1n VNTOL=1m ITL4=100 
.TRAN 0.05n 10u 

.control
run

echo "VIN vs Time (Fig 5 + Fig 6 equivalent) and Phase Space"

plot v("/VIN") xlimit 0 5u title "VIN vs Time - Full View (0 to 5us)"
plot v("/VIN") xlimit 2.0u 2.5u title "VIN vs Time - Zoomed (2.0 to 2.5us)"
plot v("/VOUT_MAP") vs v("/VIN") title "Phase Space: VOUT_MAP vs VIN"
plot v("/VIN") vs v("/N1") title "Strange Attractor: VIN vs N1"

write VIN_vs_Time.raw
.endc