beautypg.com

3 timer b code examples, 1 auto-reload mode, 2 clock output mode – Maxim Integrated MAX31782 User Manual

Page 114: 3 pwm output mode, 12 .3 timer b code examples -12, 3timerbcodeexamples, 1auto-reloadmode, 2clockoutputmode, 3pwmoutputmode

background image

MaximIntegrated 12-12

MAX31782 User’s Guide

Revision 0; 8/11

12.3TimerBCodeExamples

12.3.1Auto-ReloadMode

Creating a 10ms interrupt (10ms at 4MHz = 40,000 clock cycles):

TB0R = 40000;

//set the Reload Register

TB0V = 0x0000;

//clear the Value Register

TB0CN_bit.CPnRLB = 0;

//clear for auto reload

TB0CN_bit.ETB = 1;

//enable the interrupt

TB0CN_bit.TRB = 1;

//enable the Timer B operation

12.3.2ClockOutputMode

Creating a 100kHz clock on the TBA pin:

TB0CN_bit.CPnRLB = 0;

//clear for reload

TB0CN_bit.TBPS = 1;

//prescaler: divide sysclk/4 for 1MHz Timer B Clock

TB0R = 4;

//set for 100 kHz output frequency

TB0CN_bit.TBOE = 1;

//enable output on TBA pin

TB0CN_bit.TRB = 1;

//enable timer operation

12.3.3PWMOutputMode

Creating a 40% duty cycle 100kHz signal:

TB0CN_bit.TBPS = 0;

//Timer B input clk = sysclk

TB0R = 39;

//PWM period = 40 sysclks

TB0C = 16;

//duty cycle = 16/40

TB0CN_bit.TBCR = 1;

//set to reset mode

TB0CN_bit.TBCS = 0;

//set to reset mode

TB0CN_bit.TRB = 1;

//enable Timer B