Blockset described on this wiki is deprecated since 2012.

For Model Based Design (MBD), use the free MPLAB Device Blocks for Simulink, tool from Microchip.
Updated Rapid Control Prototyping (RCP) custom projects are published at: https://lubin.kerhuel.eu.

DsPIC Block/Output Compare

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 Jump to search
Block Output Compare

Output driver for PWM output data

Outline

Output Compare Dialog

The Output Compare (OC) block generates PWM impulse on the Output Compare peripheral. There is two entry for each channel. They can be configured to be :

  • Time Up and Period
  • Time Down and Period
  • Time Up and Time Down

Input block value must be scaled using the following :

Up or Down or Period = [math]T_{set} * \frac{OCkmax}{MaxChannel}[/math]

With

  • MaxChannel = The literal value (in second) you defined as the max time in the dialob box
  • OCkmax = a constant automatically evaluated in the matlab workspace (replace k by the channel number)
  • Tset = the required time in second (inferior to MaxChannel)

for example, if the max value is set to 20ms (MaxChannel = [math]20*10^{-3}[/math]) on channel 1

[math]1*10^{-3}*\frac{OC1max}{20*10^{-3}}[/math]

is the input value coding for 1ms.

A timer is automatically assigned and configured for each channel to provide the best resolution possible. The timer configuration is choosen to comply with the max pulse duration the channel will be able to generate.

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

Interrupt Priority

Interrupt is set on each rising and/or falling edge. The interrupt priority do not affect the accuracy of the PWM generated because PWM output pin are directly driven by the hardware. High interrupt priority is necessary for very short impulse generation that have fast consecutive event.

Output Channels

Specify Output Compare channel(s) (OC) used starting from 1. This modify 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 :

  • 3 : is to set both High and low pulse duration
  • 5 : is to set both High pulse duration and periode
  • 10 : is to set both Down pulse duration and periode
  • The first value of the vector reffere to the first channel defined in the vector "Input Channel'.

Max/Channels

Define max time in secondes 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 to set correct scalling for input data. The ValMax is the max value that correspond 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 encountred.

Related block & Examples

Related block:

Examples:


<comments \>