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 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 Jump to search
(New page: thumb|rght|Block Output Compare Output driver for PWM output data =Outline= [[Image:Block_OutputCompare_DialogBox_HW.png|thumb|right|450px|Output Co...)
 
Line 1: Line 1:
 
[[Image:Block_Output_Compare_HW.png|thumb|rght|Block Output Compare]]
 
[[Image:Block_Output_Compare_HW.png|thumb|rght|Block Output Compare]]
Output driver for PWM output data
+
Output driver for PWM output data.
  
 
=Outline=
 
=Outline=
Line 6: Line 6:
 
[[Image:Block_OutputCompare_DialogBox_HW.png|thumb|right|450px|Output Compare Dialog]]
 
[[Image:Block_OutputCompare_DialogBox_HW.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 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:
  
*Time Up and Time Down
+
*Allow generation of very fast PWM signal
*Time Up ane Periode
+
*Possibility to set accurately the ADC sampling time at any instant of the PWM period.
*Time Down and Periode
 
  
 +
Drawbacks (compared to PWM Output Compare block) are:
 +
 +
*All PWM channels have the same Period (however, mode and duty cycle can be different)
 +
*The peripheral will not be able to share the timer it uses with others peripheral
 +
 +
Three modes available allow defining PWM (block input) as:
 +
 +
*Time Up and Period
 +
*Time Down and Period
 +
*Time Set and Reset
 +
 +
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 :
 
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 Periode = <tex>T_{set} * \frac{OCmax}{MaxChannel}</tex>
  
 
With  
 
With  
*MaxChannel = The literal value (in second) you defined as the max time in the dialob box
+
*MaxChannel = The literal value (in second) you defined as the max time in the dialog box
*OCkmax = a constant automatically evaluated in the matlab workspace (replace k by the channel number)
+
*OCmax = a constant automatically evaluated in the matlab workspace  
 
*Tset = the required time in second (inferior to MaxChannel)
 
*Tset = the required time in second (inferior to MaxChannel)
  
Line 27: Line 40:
 
is the input value coding for 1ms.
 
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.
+
=Dialog Box Parameters=
  
 +
==Timer==
  
=Dialog Box Parameters=
+
Select either Timer 2 or Timer 3. The selected timer will be reserved for the Output Compare Hardware block.
 
 
==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==
 
==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.
+
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==
 
==Channels Input Type==
Select for each channel which input you want to define :
+
Select for each channel which input you want to define:
*3 : is to set both High and low pulse duration
+
*5 : set UP duty cycle and Period
*5 : is to set both High pulse duration and periode
+
*10 : set Down duty cycle and Period
*10 : is to set both Down pulse duration and periode
+
*16 : set rise and fall time instant within the period (useful when using ADC)
*The first value of the vector reffere to the first channel defined in the vector "Input Channel'.
+
 
 +
Note that the Period is common to all channels!
 +
 
 +
==Periode as block input==
  
==Max/Channels==
+
Add Period input to the block. Otherwise, the period will be the max period set by Period Max.
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.
+
==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==
 
==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.
+
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==
 
==Result Byte Resolution==
Line 61: Line 76:
  
 
==Status==
 
==Status==
Information if error encountred.
+
Information if error encountered.

Revision as of 16:37, 1 March 2009

Block Output Compare

Output driver for PWM output data.

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:

  • Allow generation of very fast PWM signal
  • Possibility to set accurately the ADC sampling time at any instant of the PWM period.

Drawbacks (compared to PWM Output Compare block) are:

  • All PWM channels have the same Period (however, mode and duty cycle can be different)
  • The peripheral will not be able to share the timer it uses with others peripheral

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

  • Time Up and Period
  • Time Down and Period
  • Time Set and Reset

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 = <tex>T_{set} * \frac{OCmax}{MaxChannel}</tex>

With

  • MaxChannel = The literal value (in second) you defined as the max time in the dialog box
  • OCmax = a constant automatically evaluated in the matlab workspace
  • 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

<tex>1*10^{-3}*\frac{OC1max}{20*10^{-3}}</tex>

is the input value coding for 1ms.

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:

  • 5 : set UP duty cycle and Period
  • 10 : set Down duty cycle and Period
  • 16 : set rise and fall time instant within the period (useful when using ADC)

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.