Inampudi Sugun TejAniket Lad
Published

Peltier Cooler

Mini-cooler powered by the Peltier module, designed for temperature setpoint control.

BeginnerShowcase (no instructions)251
Peltier Cooler

Things used in this project

Hardware components

Temperature Sensor
Temperature Sensor
×1
MSP430 Microcontroller
Texas Instruments MSP430 Microcontroller
×1
Darlington High Power Transistor
Darlington High Power Transistor
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Through Hole Resistor, 680 ohm
Through Hole Resistor, 680 ohm
×1
Capacitor 100 nF
Capacitor 100 nF
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1

Software apps and online services

Code Composer Studio
Texas Instruments Code Composer Studio
MATLAB
MATLAB

Story

Read more

Schematics

Final Schematic

Sensor Circuit

Peltier and Relay Circuit

Code

Peltier Cooler Project Code

C#
Compile on MSP430 Board with Code Composer Studio
/******************************************************************************
ME461 Computer Control of Mechanical Systems
Fall 2019 

Final Project
Peltier Cooler with Temperature Control

Written by-
Aniket Ajay Lad
Sugun Tej Inampudi
*******************************************************************************/

#include "msp430x22x2.h"
#include "UART.h"

char newprint = 0;
unsigned int timecnt = 0;
unsigned int fastcnt = 0;


long int value = 0;
int millivolt = 0;
int Temp=0;
long int Temp1 = 0;
int sampleIter = 0;
long int duty = 0;
int lastdecisionTemp = 0;
int peltierOn = 0;
int doorservoLow = 3000;	// Servo duty to close the door
int doorservoHigh = 4800;	// Servo duty to open the door
int Tset = 100;				// Set point temperature x10 (deg C)
int dT = 5;					// Allowable change from set point x10 (deg C)

// Create your global variables here:







void main(void) {
	
	WDTCTL = WDTPW + WDTHOLD; // Stop WDT
	
	if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF) while(1);
	                                             
	DCOCTL  = CALDCO_16MHZ; // Set uC to run at approximately 16 Mhz
	BCSCTL1 = CALBC1_16MHZ; 
		
	//P1IN 		    Port 1 register used to read Port 1 pins setup as Inputs
	P1SEL &= ~0xFF; // Set all Port 1 pins to Port I/O function
	P1REN &= ~0xFF; // Disable internal resistor for all Port 1 pins
	P1DIR |= 0x03;   // Set Port 1 Pin 0 (P1.0) as an output.  Leaves Port1 pin 1 through 7 unchanged
	P1OUT &= ~0xFF; // Initially set all Port 1 pins set as Outputs to zero
	P1OUT |= 0x02; // Initially set all Port 1 pins set as Outputs to zero

	// Pin 4.1 for controlling door servo with PWM
	P4SEL |= 0x02;
	P4REN &= ~0xFF;
	P4DIR |= 0x06;

	// P2IN Configuration for controlling switches
	P2SEL &= ~0xF0;
	P2DIR &= ~0xF0;
	P2REN |= 0xF0;
	P2OUT |= 0xC0;
	P2OUT &= ~0x30;

	// Timer A Config
	TACCTL0 = CCIE;              // Enable Timer A interrupt
	TACCR0  = 16000;             // period = 1ms   
	TACTL   = TASSEL_2 + MC_1;   // source SMCLK, up mode
	

	// Timer B config
	TBCCTL0 = 0;
	TBCCTL1 |= OUTMOD_7;
	TBCCTL2 = OUTMOD_7 | CLLD_1;
	TBCTL |= ID_3 + TBSSEL_2 + MC_1;
	TBCCR0 = 40000;
	TBCCR1 = doorservoLow;
	TBCCR2 = (duty * TBCCR0)/100; // Setting TBCCR2

	// Setting up ADC channel to read temperature sensor data
	ADC10CTL1 = ADC10DIV_2 + INCH_7;
	ADC10AE0 = 0xF0;
	ADC10AE1 = 0;
	ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10IE + ADC10ON;


	Init_UART(115200, 1);	// Initialize UART for 9600 baud serial communication

	_BIS_SR(GIE); 	    // Enable global interrupt

	while(1) {

		if(newmsg) {
			//my_scanf(rxbuff,&var1,&var2,&var3,&var4);
			newmsg = 0;
		}

		if (newprint)  { 
			P1OUT ^= 0x1; // Blink LED
 			UART_printf("C %d Ts %d\n\r",Temp,Tset); //  %d int, %ld long, %c char, %x hex form, %.3f float 3 decimal place, %s null terminated character array
			// UART_send(1,(float)timecnt);
			
			timecnt++;  // Just incrementing this integer for default print out.
			newprint = 0;
		}

	}
}


// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
    ADC10CTL0 |= ADC10SC + ENC;

  
}



// ADC 10 ISR - Called when a sequence of conversions (A7-A0) have completed
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) {
    fastcnt++; // Keep track of time for main while loop.
    value = ADC10MEM;
    millivolt = (3300*value)/1023;
    Temp1 += ((long int)(millivolt))-500;
    sampleIter += 1;

    if (fastcnt == 500) {

        Temp = Temp1/sampleIter;
        Temp1 = 0;
        sampleIter = 0;
        fastcnt = 0;
        newprint = 1;  // flag main while loop that .5 seconds have gone by.


        lastdecisionTemp = Temp;


        if(lastdecisionTemp > Tset + dT){
            peltierOn = 1;
        }else if(lastdecisionTemp <= Tset + dT && lastdecisionTemp >= Tset - dT && peltierOn == 1){
            peltierOn = 1;
        }else if(lastdecisionTemp <= Tset + dT && lastdecisionTemp >= Tset - dT && peltierOn == 0){
            peltierOn = 0;
        }else if(lastdecisionTemp < Tset - dT){
            peltierOn = 0;
        }

        decisionTemp = 0;
//        peltierOn = 0;

    }

    //    Big fan control
    if((P2IFG & 0x10)==0x10){
        P4OUT ^= 0x04;
        P2IFG &= ~0xF0;
    }

	//    Relay for small fan + Peltier
    if((P2IFG & 0x40)==0x40){
        P1OUT ^= 0x02;
        P2IFG &= ~0xF0;
    }

	// 	  Control of small fan and peltier
    if(peltierOn == 0){
        P1OUT &= ~0x02;
    }else if(peltierOn == 1){
        P1OUT |= 0x02;
    }else{
        P1OUT &= ~0x02;
    }


    // Door servo control
    if((P2IFG & 0x80)==0x80){
        if(TBCCR1 == doorservoLow){
            TBCCR1 = doorservoHigh;
        }else if(TBCCR1 == doorservoHigh){
            TBCCR1 = doorservoLow;
        }else{
            TBCCR1 = doorservoLow;
        }
        P2IFG &= ~0xF0;
    }


}



// USCI Transmit ISR - Called when TXBUF is empty (ready to accept another character)
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void) {
  
	if((IFG2&UCA0TXIFG) && (IE2&UCA0TXIE)) { // USCI_A0 requested TX interrupt
		if(printf_flag) {
			if (currentindex == txcount) {
				senddone = 1;
				printf_flag = 0;
				IFG2 &= ~UCA0TXIFG;
			} else {
			UCA0TXBUF = printbuff[currentindex];
			currentindex++;
			}
		} else if(UART_flag) {
			if(!donesending) {
				UCA0TXBUF = txbuff[txindex];
				if(txbuff[txindex] == 255) {
					donesending = 1;
					txindex = 0;
				} else {
					txindex++;
				}
			}
		}
	    
		IFG2 &= ~UCA0TXIFG;
	}

	if((IFG2&UCB0TXIFG) && (IE2&UCB0TXIE)) { // USCI_B0 requested TX interrupt (UCB0TXBUF is empty)
		
		IFG2 &= ~UCB0TXIFG;   // clear IFG
	}
}


// USCI Receive ISR - Called when shift register has been transferred to RXBUF
// Indicates completion of TX/RX operation
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void) {
  
	if((IFG2&UCA0RXIFG) && (IE2&UCA0RXIE)) { // USCI_A0 requested RX interrupt (UCA0RXBUF is full)
		// Changing set point temperature from Teraterm
	    if (UCA0RXBUF == 'w') {
	        Tset = Tset - 10;
	    }
	    if (UCA0RXBUF == 'e') {
	        Tset = Tset + 10;
	    }


		IFG2 &= ~UCA0RXIFG;
	}
	
	if((IFG2&UCB0RXIFG) && (IE2&UCB0RXIE)) { // USCI_B0 requested RX interrupt (UCB0RXBUF is full)

		IFG2 &= ~UCB0RXIFG; // clear IFG
	}
  
}

Credits

Inampudi Sugun Tej

Inampudi Sugun Tej

1 project • 0 followers
Aniket Lad

Aniket Lad

1 project • 0 followers

Comments

Add projectSign up / Login