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.

Difference between revisions of "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
m (LubinKerhuel moved page Block/Output Compare to DsPIC Block/Output Compare: Block is a special page, creates many issues)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Image:Block_Output_Compare.png|thumb|rght|Block Output Compare]]
+
[[Image:Block_Output_Compare.png|thumb|rght|Block Output Compare]]
 
Output driver for PWM output data
 
Output driver for PWM output data
  
 
=Outline=
 
=Outline=
 +
 +
[[Image:Block_OutputCompare_DialogBox.png|thumb|right|450px|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 :
 
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
 
*Time Up and Time Down
*Time Up ane Periode
 
*Time Down and Periode
 
  
 
Input block value must be scaled using the following :
 
Input block value must be scaled using the following :
  
Up or Down or Periode = <tex>T_{set} * \frac{OCkmax}{MaxChannel}</tex>
+
Up or Down or Period = <math>T_{set} * \frac{OCkmax}{MaxChannel}</math>
  
 
With  
 
With  
Line 18: Line 21:
 
*Tset = the required time in second (inferior to MaxChannel)
 
*Tset = the required time in second (inferior to MaxChannel)
  
for example, if the max value is set to 20ms (MaxChannel = <tex>20*10^{-3}</tex>) on channel 1  
+
for example, if the max value is set to 20ms (MaxChannel = <math>20*10^{-3}</math>) on channel 1  
  
<tex>1*10^{-3}*\frac{OC1max}{20*10^{-3}}</tex>
+
<math>1*10^{-3}*\frac{OC1max}{20*10^{-3}}</math>
  
 
is the input value coding for 1ms.
 
is the input value coding for 1ms.
Line 26: Line 29:
 
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.
 
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=
 
=Dialog Box Parameters=
[[Image:Block_OutputCompare_DialogBox.png|thumb|right|450px|Output Compare Dialog]]
+
 
 
==Interrupt Priority==
 
==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.
 
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.
Line 43: Line 52:
  
 
==Max/Channels==
 
==Max/Channels==
Define max time in secondes of the longuest value that could be generated by each channel. Event is either Up, Down, or Periode max time for one channel. It should be set to the lowest value possible in order to get the highest resolution.
+
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==
 
==ValMax / Channel Variable Name==
Line 59: Line 68:
 
==Status==
 
==Status==
 
Information if error encountred.
 
Information if error encountred.
 +
 +
=Related block & Examples=
 +
Related block:
 +
* [[Block/Output_Compare_HW| Output Compare Hardware]]
 +
 +
Examples:
 +
* [[Hyper_Sampling]]
 +
* forum : http://www.kerhuel.eu/forum/viewtopic.php?f=1&t=242
 +
* forum : http://www.kerhuel.eu/forum/viewtopic.php?f=1&t=312
 +
 +
----
 +
<comments \>

Latest revision as of 18:30, 3 May 2015

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 \>