Programming in Assembly with MSP430 G2553 Design a Pulse Width Modulation (PWM)
ID: 3779742 • Letter: P
Question
Programming in Assembly with MSP430 G2553
Design a Pulse Width Modulation (PWM) sequence for the green LED.
The program should be able to gradually increase the intensity of the green LED over about 30 seconds smoothly without obvious flickering.
Modify the sample code (Taken from project skeleton):
StartPWMTimer:
mov.w &samplingPr, &TA0CCR0 ; Update PWM sampling period
mov.w &lowerDC, &TA0CCR1 ; Set lower threshold of PWM duty cycle.
; TA0CCR1 cannot start with 0!
bis.b #alarmLED, &P1DIR ; Configure P1.6 to be used as TA0CCR1 output
bis.b #alarmLED, &P1SEL
bic.b #alarmLED, &P1SEL2
bic.b #alarmLED, &P1OUT
mov.w #OUTMOD_7, &TA0CCTL1 ; Use reset/set mode to generate PWM
mov.w #MC_1 + TASSEL_2 + TACLR, &TA0CTL ; Config Timer Clock to SMCLK.
; Start Timer in up mode to count up to CCR0
ret
StopPWMTimer:
bic.b #alarmLED, &P1SEL ; disconnect debug LED from timerA0 CCR0
mov.w #MC_0 + TACLR, &TA0CTL ; clear timerA0 config for PWM
clr.w &TA0CCTL0
clr.w &TA0CCR0
clr.w &TA0CCR1
ret
;-------------------------(Not given code for ISR)-------------------------------------------------------------------
; TA0CCR0 ISR
DownCntISR:
; Downcount to alarm time routine starts here
; -------------------------------------------
reti
Explanation / Answer
import ch05.queues.*;
import ch03.stacks.*;
import support.BSTNode;
public category BinarySearchTree>
implements BSTInterface
relevance the basis of this BST
boolean found; // utilized by take away
// for traversals
protected LinkedUnbndQueue inOrderQueue; // queue of information
protected LinkedUnbndQueue preOrderQueue; // queue of information
protected LinkedUnbndQueue postOrderQueue; // queue of information
public BinarySearchTree()
// Creates Associate in Nursing empty BST object.
public mathematician isEmpty()
// Returns true if this BST is empty; otherwise, returns false.
private int recSize(BSTNode tree)
// Returns the quantity of components in tree.
public int size()
// Returns the quantity of components during this BST.
public int size2()
// Returns the quantity of components during this BST.
}
return count;
}
private mathematician recContains(T part, BSTNode tree)
// Returns true if tree contains a part e such
// e.compareTo(element) == zero; otherwise, returns false.
{
if (tree == null)
return false; // part isn't found
else if (element.compareTo(tree.getInfo()) < 0)
return recContains(element, tree.getLeft()); // Search left subtree
else if (element.compareTo(tree.getInfo()) > 0)
return recContains(element, tree.getRight()); // Search right subtree
else
return true; // part is found
}
public mathematician contains (T element)
// Returns true if this BST contains a part e such
// e.compareTo(element) == zero; otherwise, returns false.
private T recGet(T part, BSTNode tree)
// Returns a part e from tree such e.compareTo(element) == zero;
// if no such part exists, returns null.
{
if (tree == null)
return null; // part isn't found
else if (element.compareTo(tree.getInfo()) < 0)
return recGet(element, tree.getLeft()); // get from left subtree
else
if (element.compareTo(tree.getInfo()) > 0)
return recGet(element, tree.getRight()); // get from right subtree
else
return tree.getInfo(); // part is found
}
public T get(T element)
// Returns a part e from this BST such e.compareTo(element) == 0;
// if no such part exists, returns null.
private BSTNode recAdd(T part, BSTNode tree)
// Adds part to tree; tree retains its BST property.
public void add (T element)
// Adds part to the current BST. The tree retains its BST property.
private T getPredecessor(BSTNode tree)
// Returns the knowledge command within the right node in tree
private BSTNode removeNode(BSTNode tree)
// Removes the knowledge at the node documented by tree.
// The user's information within the node documented by tree is not any
// longer within the tree. If tree could be a leaf node or has solely
// a non-null kid pointer, the node pointed to by tree is
// removed; otherwise, the user's information is replaced by its
// logical forerunner and therefore the predecessor's node is removed.
}
private BSTNode recRemove(T part, BSTNode tree)
// Removes a part e from tree such e.compareTo(element) == 0
// and returns true; if no such part exists, returns false.
return tree;
}
public mathematician take away (T element)
// Removes a part e from this BST such e.compareTo(element) == 0
// and returns true; if no such part exists, returns false.
private void inOrder(BSTNode tree)
// Initializes inOrderQueue with tree components in inOrder order.
}
private void preOrder(BSTNode tree)
// Initializes preOrderQueue with tree components in preOrder order.
}
private void postOrder(BSTNode tree)
// Initializes postOrderQueue with tree components in postOrder order.
}
public int reset(int orderType)
// Initializes current position for Associate in Nursing iteration through this BST
// in orderType order. Returns current variety of nodes within the BST.
else
if (orderType == PREORDER)
if (orderType == POSTORDER)
return numNodes;
}
public T getNext (int orderType)
// Preconditions: The BST isn't empty
// The BST has been reset for orderType
// The BST has not been changed since the foremost recent reset
// the tip of orderType iteration has not been reached
//
// Returns the part at the present position on this BST for orderType
// and advances the worth of the present position supported the orderType.
come back null;
}
}
BSTInterface:
//----------------------------------------------------------------------------
// BSTInterface.java by Dale/Joyce/Weems Chapter eight
//
// Interface for a category that implements a binary search tree (BST).
//
// The trees square measure boundless and permit duplicate components, however don't enable null
// components. As a general precondition, null components don't seem to be passed as
// arguments to any of the strategies.
//
// The tree supports iteration through its components in INORDER, PREORDER,
// and POSTORDER.
//----------------------------------------------------------------------------
package ch08.trees;
public interface BSTInterface>
accustomed specify traversal order
static final int INORDER = 1;
static final int PREORDER = 2;
static final int POSTORDER = 3;
boolean isEmpty();
// Returns true if this BST is empty; otherwise, returns false.
int size();
// Returns the quantity of components during this BST.
boolean contains (T element);
// Returns true if this BST contains a part e such
// e.compareTo(element) == 0; otherwise, returns false.
boolean take away (T element);
// Removes a part e from this BST such e.compareTo(element) == 0
// and returns true; if no such part exists, returns false.
T get(T element);
// Returns a part e from this BST such e.compareTo(element) == 0;
// if no such part exists, returns null.
void add (T element);
// Adds part to the current BST. The tree retains its BST property.
int reset(int orderType);
// Initializes current position for Associate in Nursing iteration through this BST
// in orderType order. Returns current variety of nodes within the BST.
T getNext (int orderType);
// Preconditions: The BST isn't empty
// The BST has been reset for orderType
// The BST has not been changed since the foremost recent reset
// the tip of orderType iteration has not been reached
//
// Returns the part at the present position on this BST for orderType
// and advances the worth of the present position supported the orderType.
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.