Difference between revisions of "NU32v2: Output Compare, PWM, and Analog Output"

From Mech
Jump to navigationJump to search
(New page: Code for PWM: <pre> OpenTimer2(T2_ON | T2_PS_1_4, 1000); // for 20kHz PWM: 80000000Hz / 4ps / 20000Hz = 1000 OpenOC1(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // PWM out...)
 
Line 1: Line 1:
Code for PWM:
Code for PWM:
<pre>
<pre>
OpenTimer2(T2_ON | T2_PS_1_4, 1000); // for 20kHz PWM: 80000000Hz / 4ps / 20000Hz = 1000
OpenTimer2(T2_ON | T2_PS_1_4, 1000); // for 20kHz PWM: 80000000Hz / 4ps / 20000Hz = 1000
OpenOC1(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // PWM output on Pin D1
OpenOC1(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // PWM output on Pin D1
SetDCOC1PWM(duty); // unsigned int duty from 0-1000
SetDCOC1PWM(duty); // unsigned int duty from 0-1000
</pre>
</pre>

Revision as of 00:55, 30 January 2011

Code for PWM:

OpenTimer2(T2_ON | T2_PS_1_4, 1000); // for 20kHz PWM: 80000000Hz / 4ps / 20000Hz = 1000
OpenOC1(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0); // PWM output on Pin D1
SetDCOC1PWM(duty); // unsigned int duty from 0-1000