Ask a question to Desklib · AI bot

Ask NowBETA

ET4047: Electrical Engineering | Assignment

Added on -2019-09-18

| ET4047
| 4 pages
| 1457 words
| 1080 views

Trusted by 2+ million users,
1000+ happy students everyday

ET4047 Autumn 2016 Project 2 (Lab Weeks 8-12)(Version 1.0, first released version)This project is worth 15% of the total module assessment.Description:Write a single ATMega328P program that changes the direction and speed of a DC motor using 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 (suitably formatted) 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, using PWM and the Timer/Counter 2 output OC2B, where a zero PWM value stops rotation and a PWM value of 100% corresponds to the maximum motor speed. The Direction is controlled 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, where 1 means Halt or stop motor rotation and 0 means Go or start the motor rotation.The OC2B signal from the ATMega328P is shared with PORTD Bit 3. The PWM output on OC2B is controlled by the data value written to the OCR2B register. The ADC0 input is driven by the motor control IC on the motor shield and is a function of the 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/Counter2 interrupts are not enabled.The Timer/Counter1 input, ICP1, is connected to a 555 Timer, which produces a periodic signal in a frequency range from approximately 2 kHz to 13 kHz, where the frequency is controlled by a potentiometer on a shield.The program responds to the following single character commands received over the serial 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 off Brake‘0’ to ‘9’: Set the motor speed using the OC2RB register, to value from 0 to 90% of full speed. You must convert the char value to an integer, and set the PWM based on this ET4047 Autumn 2016 Project 2. Page 1
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 tothe user on the USARTClear the New Input Capture data flag}}//================================================================ET4047 Autumn 2016 Project 2. Page 2

Found this document preview useful?

You are reading a preview
Upload your documents to download
or
Become a Desklib member to get accesss

Students who viewed this