Labs/Lab6/Watkins_William_Lab6_Part2.c
// <editor-fold defaultstate="collapsed" desc="updateDAC()">
/******************************************************************************
 * updateDAC function
 *
 * Updates the output of the DAC from CCP1 handler.  Was in mainline, but 
 * the timing would not work.
 ******************************************************************************/

updateDAC function

Updates the output of the DAC from CCP1 handler.  Was in mainline, but
the timing would not work.
updateDAC function Updates the output of the DAC from CCP1 handler . Was in mainline but the timing would not work .
void updateDAC() {
    DACTempSend = 0;    
    LATEbits.LATE0 = 0; 
    DACTempSend = DACData | currentBin; 
    SSP1BUF = DACTempSend>>8;   
    while(SSP1STATbits.BF == 0){}   
    trashSPI = SSP1BUF; 
    SSP1BUF = DACTempSend & 0xFF;   
    while(SSP1STATbits.BF == 0){}
    trashSPI = SSP1BUF;
    LATEbits.LATE0 = 1; 
    if(upDown == 0)
    {
        if(currentBin == 4092)
        {
            upDown = 1;
            currentBin -= 4;
            LATAbits.LA4 = 1; 
        }
        else
        {
            currentBin += 4;
        }
    }
    else
    {
        if(currentBin == 0)
        {
            upDown = 0;
            currentBin += 4;
            LATAbits.LA4 = 0;   
        }
        else
        {
            currentBin -= 4;
        }
    }
}
void updateDAC ( ) { DACTempSend = 0 ; LATEbits . LATE0 = 0 ; DACTempSend = DACData | currentBin ; SSP1BUF = DACTempSend >> 8 ; while ( SSP1STATbits . BF == 0 ) { } trashSPI = SSP1BUF ; SSP1BUF = DACTempSend & 0xFF ; while ( SSP1STATbits . BF == 0 ) { } trashSPI = SSP1BUF ; LATEbits . LATE0 = 1 ; if ( upDown == 0 ) { if ( currentBin == 4092 ) { upDown = 1 ; currentBin -= 4 ; LATAbits . LA4 = 1 ; } else { currentBin += 4 ; } } else { if ( currentBin == 0 ) { upDown = 0 ; currentBin += 4 ; LATAbits . LA4 = 0 ; } else { currentBin -= 4 ; } } }
<editor-fold defaultstate="collapsed" desc="updateDAC()">
 updateDAC function
<editor - fold defaultstate = " collapsed " desc = " updateDAC () " > updateDAC function
// Update the DAC output value! // Make sure variable is empty // Drive CS low // Combine command and data bits // Load first byte into SSP1BUF // Wait until the buffer is full to read // Read trash data // Load last 8 bits into SSP1BUF // Drive CS high to set DAC output // Simple up or down checker to change the current bin appropriately // Using +=4 because the delay with 1024 bins was more precise/accurate // than using 4096 // Illustration purposes only // Again, illustration purposes only