ET4047: Electrical Engineering | Assignment

Added on - 18 Sep 2019

  • 4

    pages

  • 1457

    words

  • 47

    views

  • 0

    downloads

Showing pages 2 of 4
ET4047 Autumn 2016 Project 2 (Lab Weeks 8-12)(Version 1.0, first released version)This project is worth15%of the total module assessment.Description:Write a single ATMega328P program that changes the direction and speed of a DC motorusing PWM, based on date read over the serial port. The program will:Read a character using the serial port. Depending on the character that has been read, theprogram will change the motor speed or direction, or report requested data (suitablyformatted) over the serial port.Read the ADC0 inputDetect the period of a periodic input signal applied to PortB bit 0 (the Input Capture pin)Report the time taken by the high and low parts of the input signal applied to PortB bit 0.Operation of the program:The program controls the speed of a DC motor using the Arduino Motor Shield, usingPWM and the Timer/Counter 2 output OC2B, where a zero PWM value stops rotation anda PWM value of 100% corresponds to the maximum motor speed. The Direction iscontrolled by the state of PORTB Bit 4, where 1 means Forward and 0 means Reverse.The program can also start or stop the motor using a Brake signal on PORTB Bit 1, where1 means Halt or stop motor rotation and 0 means Go or start the motor rotation.TheOC2Bsignal from the ATMega328P is shared with PORTD Bit 3. The PWM output onOC2B is controlled by the data value written to the OCR2B register.TheADC0input is driven by the motor control IC on the motor shield and is a function ofthe motor current. The ADC should be initialised so that it runs in Free Running Mode.The Timer/Counter2 output OC2B is used as the PWM output, but Timer/Counter2interrupts are not enabled.The Timer/Counter1 input,ICP1, is connected to a 555 Timer, which produces a periodicsignal in a frequency range from approximately 2 kHz to 13 kHz, where the frequency iscontrolled by a potentiometer on a shield.The program responds to the following single character commands received over theserial port:'F' or 'f': Set Direction of motor spin to Forward.'R' or 'r': Set Direction of motor spin to Reverse.‘H’ or ‘h’: Halt motor irrespective of the motor speed previously selected – ie Turn on Brake‘G’ or ‘g’: Start the motor (depends on the motor speed previously selected) – ie Turn offBrake‘0’ to ‘9’: Set the motor speed using the OC2RB register, to value from 0 to 90% of fullspeed. You must convert the char value to an integer, and set the PWM based on thisET4047 Autumn 2016 Project 2. Page1
value.‘T’ or ‘t’: Report the period of the 555 Timer in microseconds.‘L’ or ‘t’: Report the time taken by the low pulse of the 555 Timer signal in microseconds‘J’ or ‘j’: Report the time taken by the high pulse of the 555 Timer signal in microseconds'C' or 'c': Continuously report the Timer input period in microseconds.‘E’ or ‘e’: Stop continuous reporting of Timer input.‘A’ or ‘a’: Report the ADC0 conversion result. This is the ADC value.‘V’ or ‘v’: Report the ADC0 conversion result in mV. You must convert the ADC value to mV'M' or 'm': Report motor direction to user.‘S’ or ‘s’: Report the current value of the OCR2B register to the user.All other characters are ignored.Note:The data reported to the user is in ASCII format, and should be formatted with sometext to show what is being displayed. (e.g. “Timer period = 103us”, or “Voltage = 1234mV”).Code Structure:Initialisation Section:Initialise Bit 3 of PORTD to output (needed as PWM output)Initialise Bits 4 and 1 of PORTB to outputs (motor direction and brake bits)Initialise Timer/Counter 1 for input capture and rollover.Initialise Timer/Counter 2 for PWM – Note Timer 2 interrupts are not used.Initialise USART Serial PortInitialise ADC// Use a separate initialisation function for each initialisation task.Enable global interruptswhile(1){Poll Serial port or use scanf to check for new character and Parse inputPoll New Input Capture data flag to see if new ICP data has been captured.If yes{If the continuous timer value display is selected, report new timer value totheuser on the USARTClear the New Input Capture data flag}}//================================================================ET4047 Autumn 2016 Project 2. Page2