Matlab-Simulink device driver Blockset for Microchip dsPIC / PIC24 / PIC32 Microcontrollers.

Block/Output Compare HW

From http://www.kerhuel.eu/wiki - Simulink device driver Blockset for dsPIC / PIC24 / PIC32 Microcontrollers --[[User:LubinKerhuel|LubinKerhuel]] 12:40, 3 September 2009 (UTC)

Jump to: navigation, search
Block Output Compare

Output driver for PWM output data.

Contents

Outline

Output Compare Dialog

The Output Compare Hardware (OC_HW) block generates PWM impulse on the Output Compare peripheral. This driver does not use any software, in comparison with PWM Output Compare block that use software interrupt. The two improvements (compared to PWM Output Compare block) are:

Drawbacks (compared to PWM Output Compare block) are:

Three modes available allow defining PWM (block input) as:

The two first modes are robust and will never cause glitch whatever is the period or duty cycles of the PWM signal (even very fast). The third mode Time Set and Reset may cause glitch (for more details, ask on the forum).

Synchronisation with the ADC: The ADC can synchronize with the Timer 3. The sampling time starts at the end of the period. When the third mode (Time Set and Reset) is selected, it is possible to set within the timer period the rising and falling instant. This makes possible sampling at any instant of the PWM period. Input block value must be scaled using the following :

Up or Down or Periode = Equation

With

for example, if the max value is set to 20ms (MaxChannel = Equation) on channel 1

Equation

is the input value coding for 1ms.

Clarifying note regarding OCkmax: OCkmax is relevant to the internal chip frequency (typically depending on quartz and PLL used). the dsPIC blockset evaluate this variable in the MATLAB workspace. Type "who" at matlab prompt to list all variable. Get the variable value typing its name "OC1max" (case sensitive). There are two OC blocks : The OC hardware block creates one variable OCmax. The OC block creates multiple variables OC(x)max with x, corresponding to each channel (1, 2 3 or 4)

Dialog Box Parameters

Timer

Select either Timer 2 or Timer 3. The selected timer will be reserved for the Output Compare Hardware block.

Output Channels

Specify Output Compare channel(s) (OC) used starting from 1. This modifies the number of input of the block. Specify multiple channels in vector form: [1 2] for OC1 and OC2.

Channels Input Type

Select for each channel which input you want to define:

Note that the Period is common to all channels!

Periode as block input

Add Period input to the block. Otherwise, the period will be the max period set by Period Max.

Period Max

Define max time in seconds of the longest value that could be generated by each channel. Event is either Up, Down, or Period max time for one channel. It should be set to the lowest value possible in order to get the highest resolution.

ValMax / Channel Variable Name

This Variable evaluated in the workspace allows setting correct scaling for input data. The ValMax is the max value that corresponds to the duration defined in Max/Channels.

Result Byte Resolution

This is the log2 of the ValMax Variables for each channels. i.e. it is resolution of the channel. It is updated when you push the update diagram button (top right of the simulink menu).

Timer

This is the timer assigned to each channel. It is set automatically. The timer prescaler are defined in the Master block. It is updated when you push the update diagram button (top right of the simulink menu).

Sample Time

-1 mean inherited

Status

Information if error encountered.

Related block & Examples

Related block:

Examples:



Name (required):

Website:

Comment:

Personal tools
Namespaces
Variants
Actions
Blockset
Examples
Blocks (Root level)
Digital I/O
Peripheral I/O
Serial PORT
Numerical BUS
others
Lubin Kerhuel
Toolbox