0% found this document useful (0 votes)
13 views7 pages

EDDITED

Uploaded by

vivek.2023ree07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views7 pages

EDDITED

Uploaded by

vivek.2023ree07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

FINAL QUIZ

VIVEK KUMAR YADAV Email Id: [email protected]

Ans (i) Converting 𝐺(𝑠) to Discrete Domain Using Bilinear Transformation:


Given:
𝐺(𝑠) = 𝐾𝑝 + 𝐾𝑖 (1)
𝑠

Using the bilinear transformation:


𝑇𝑠 1−𝑧−1 (2)
𝑠= ∗
2 1+𝑧−1

where 𝑇𝑠 is the sampling period. Substituting 𝑠, 𝐺(𝑠) in discrete form becomes:


𝐺(𝑧) = 𝐾 + 𝐾 ∗ 𝑇𝑠 ∗ 1−𝑧−1 (3)
𝑝 𝑖 −1 2 1+𝑧

We can implement this as difference equations in code.


y[n]=Kp⋅e[n]+Ki⋅Ts⋅(e[n]+e[n−1])/2 (4)
Code:
#include “F28x_Project.h”
#define Ts 0.0001 // Sampling time (100 µs for 10 kHz ISR)
float Kp = 3.7, Ki = 12580.0;
float e_current = 0.0, e_previous = 0.0; // Error terms
float y_current = 0.0; // PI controller output
void update_PI_controller(float error)
{
e_previous = e_current; // Update previous error
e_current = error; // Update current error
// Discrete PI controller equation
y_current = Kp * e_current + (Ki * Ts / 2) * (e_current + e_previous);
}
Ans (ii)

The logic block maps the digital ADC input to a scaled value for further calculations and
applies the DAC-ADC back-to-back transformation:

1. Scale p (ADC digital value) to x in the range [−10,10] based on the given resolution.
2. Map x back to p for DAC output.

For 12-bit ADC:

𝑥=( 𝑝
∗ 20) − 10 (5)
4095

Code:
#include “F28x_Project.h”
#define ADC_MAX 4095 // Maximum ADC value (12-bit ADC)
#define X_MAX 10.0 // Maximum x value
#define X_MIN -10.0 // Minimum x value
#define DAC_MAX 4095 // Maximum DAC value
float map_adc_to_x(uint16_t adc_value)
{
// Map ADC value to x in the range [-10, 10]
return ((float)adc_value / ADC_MAX) * (X_MAX - X_MIN) + X_MIN;
}
uint16_t map_x_to_dac(float x)
{
// Map x back to DAC range [0, 4095]
return (uint16_t)(((x - X_MIN) / (X_MAX - X_MIN)) * DAC_MAX);
}
// Example usage in the ISR or main loop
interrupt void epwm_isr(void)
{
uint16_t adc_value = AdcaResultRegs.ADCRESULT0; // Read ADC value
float x = map_adc_to_x(adc_value); // Map ADC to x
// Logic block implementation
// Perform any intermediate computation or scaling (optional)
uint16_t dac_value = map_x_to_dac(x); // Map x to DAC value
DacaRegs.DACVALS.all = dac_value; // Write to DAC
// Clear interrupt flag
EPwm1Regs.ETCLR.bit.INT = 1;
}
Ans (iii)

The ePWM ISR will:

 Implement the closed-loop system.


 Perform ADC-to-DAC transformations.
 Use the bilinear difference equations to calculate output.

Code:

#include “F28x_Project.h”

#define Ts 0.0001 // Sampling time (100 µs for 10 kHz ISR)

#define ADC_MAX 4095

#define X_MAX 10.0

#define X_MIN -10.0

float Kp = 3.7, Ki = 12580.0, C = 28.0;

float x = 0.0, y = 0.0, z = 0.0, error = 0.0;

float integral = 0.0;

interrupt void epwm_isr(void)

// Read ADC Value

uint16_t adc_value = AdcaResultRegs.ADCRESULT0; // Assuming channel A0

x = ((float)adc_value / ADC_MAX) * (X_MAX - X_MIN) + X_MIN;


// Closed-loop PI control

error = C - x; // Error calculation

integral += Ki * Ts * error; // Integral term

y = Kp * error + integral; // PI controller output

// Scale y to DAC range

if (y > X_MAX) y = X_MAX; // Saturation limits

if (y < X_MIN) y = X_MIN;

uint16_t dac_value = (uint16_t)(((y - X_MIN) / (X_MAX - X_MIN)) * ADC_MAX);

// Write to DAC

DacaRegs.DACVALS.all = dac_value;

// Clear interrupt flag

EPwm1Regs.ETCLR.bit.INT = 1;

Ans (iv)

Set p for x=5and Observe Output y

To set p for x=5, reverse the mapping formula:

𝑝= 𝑥−𝑋𝑚𝑖𝑛 ∗ 𝐴𝐷𝐶_𝑀𝐴𝑋 (6)


𝑋𝑚𝑎𝑥−𝑋𝑚𝑖𝑛

Code:

#include “F28x_Project.h”

#define X_MIN -10.0

#define X_MAX 10.0

#define ADC_MAX 4095

float x = 5.0; // Desired value of x

float y = 0.0; // Output of the PI controller


void set_p_and_measure_y() {

// Calculate p for x = 5

uint16_t p = (uint16_t)(((x - X_MIN) / (X_MAX - X_MIN)) * ADC_MAX);

// Set DAC output to p

DacaRegs.DACVALS.all = p;

// Read y (example logic; replace with actual output measurement)

y = map_adc_to_x(AdcaResultRegs.ADCRESULT0); // Convert ADC back to x

Ans (v)

Change C(s) to 24 in Expression Window

Modify C(s) in real-time (using watch variables) and observe the impact on y. Comment on
whether the system stabilises or oscillates.

Ans (vi)

Decrease C(s) in Steps and Plot

 Use a timer interrupt to decrement C(s) from 28 to 0.15.


 Monitor z, stop when z=0.85, then increment C(s) in steps.
 Log C(s) and z values and plot the graph.

Code:

#include “F28x_Project.h”

#define TIMER_PERIOD 1000000 // Timer period for 1 Hz (assuming 100 MHz clock)

#define Z_TARGET 0.85 // Target value for z

#define C_START 28.0 // Initial C(s) value

#define C_STEP 0.5 // Step size for increment/decrement

float C = C_START; // Current value of C(s)

float z = 0.0; // Current value of z (to be monitored)


// Timer ISR to adjust C(s)

interrupt void cpu_timer0_isr(void) {

// Adjust C(s) value

if (z < Z_TARGET) {

C -= C_STEP; // Decrease C(s)

if (C < 0.15) C = 0.15; // Ensure minimum limit

} else

C += C_STEP; // Increase C(s)

if (C > 28.0) C = 28.0; // Ensure maximum limit

// Update z (example computation, replace with actual logic)

z = compute_z(C); // Replace with real-time logic to compute z based on C

// Clear timer interrupt flag

CpuTimer0Regs.TCR.bit.TIF = 1;

// Function to initialize the timer

void init_timer(void) {

// Configure CPU Timer 0 for 1 Hz interrupt

ConfigCpuTimer(&CpuTimer0, 100, TIMER_PERIOD);

CpuTimer0Regs.TCR.all = 0x4001; // Start Timer 0

IER |= M_INT1; // Enable CPU INT1

PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // Enable Timer0 interrupt

}
// Placeholder function to compute z based on C(s)

float compute_z(float C) {

// Add actual computation for z based on C

return (C / 28.0); // Example: Normalize C to calculate z

Ans (vii)

Change p for x Range [5,8] and [5,−8]

 Set p such that x changes within the specified ranges.


 Observe the corresponding y values for these x ranges.
 Comment on the relationship between x and y, e.g., proportionality, stability, etc.

Code:

void change_p_and_observe_y(float new_x) {

// Update x

x = new_x;

// Calculate new p based on x

uint16_t p = (uint16_t)(((x - X_MIN) / (X_MAX - X_MIN)) * ADC_MAX);

// Set new DAC output

DacaRegs.DACVALS.all = p;

// Measure y

y = map_adc_to_x(AdcaResultRegs.ADCRESULT0); // Example: Read ADC result and


map back to x

You might also like