19.4.2.4 Triangle Wave Mode

Triangle Wave mode generates an output voltage that rises and falls with a triangle wave pattern. The Triangle Wave mode is enabled by the bit, TWME (SLPxCON[26]), and requires SLOPEN to be set to ‘1’. The high and low points of the waveform are specified via DACDAT and DACLOW. The rise and fall times and the frequency of the triangle wave are controlled via the SLPxDAT register. The very first clock cycle of the slope process selects a scaled SLPxDAT value, instead of the specified value, to provide prompt DAC response to the DAC trajectory. For all subsequent clock cycles of the slope process, the slope generator uses the specified SLPxDAT data value for incrementing/decrementing the DAC data value. The Fast DAC mode is exclusive to the Triangle Wave mode and is used to provide a fast response. The slope changes the direction automatically after reaching either the DACDAT or DACLOW value. The Triangle Wave mode is useful in digital audio applications, where an analog input signal is sampled via an analog comparator using a triangle wave reference signal (Figure 19-5).

Figure 19-5. Triangle Wave Mode

A configuration example to set the Triangle Wave mode is shown in Triangle Wave Mode Configuration(1).

Triangle Wave Mode Configuration(1)

/* Triangle Wave Mode Settings */
DAC1DATbits.DACLOW = 0x100; 	 	 	 /* Lower data value */
DAC1DATbits.DACDAT = 0xF00; 	 	 	 /* Upper data value */
SLP1DATbits.SLPDAT = 0x1;     			 /* Slope rate, counts per step */
SLP1CONbits.TWME = 1;        	 		 /* Enable Triangle Mode */
SLP1CONbits.SLOPEN = 1;      	 		 /* Enable Slope Mode */
Note:
  1. The maximum value of DACDAT must be set at 0xF32 – SLPxDAT and the minimum value of DACLOW must be set at 0xCD + SLPxDAT.