You are on page 1of 3

SHIFT REGISTER PULSE WIDTH MODULATION SERVICE

This service keeps track of each shift register output and its PWM signal
MODULE VARIABLES
MyPriority
SRStrings
CurrPulseWidth
DelayTime

ES_Framework priority
Array of our shift register strings
Array of the pulse widths on every output we're running
Minimum delay time between shift register updates

Init_SRPWMService
Parameters:
priority number
Returns:
success/failure
Local Variables: Pseudo-code:
Initialize the shift register hardware
Initialize short timer and start if off counting
Return success
Post_SRPWMService
Parameters:
Returns:
Local Variables: Pseudo-code:
ES_PostToService
Return success/failure
Run_SRPWMService
Parameters:
Returns:
Local Variables:

ThisEvent
ReturnEvent
ReturnEvent
PW_ctr
val
PW_idx
NewPW

Event we are handling


ES_NO_EVENT if no errors
ES_Event to return (ES_NO_EVENT if no errors)
Time counter to keep track of current value of each pin
8-bit value to write to shift registers
Index of output pin we want to change
New pulse width we want to impose on the output PW_idx

Pseudo-code:
Switch ThisEvent
ThisEvent is an ES_SHORT_TIMEOUT...
FOR EACH of our shift register strings
FOR EACH of the shift registers in this shift register string
FOR EACH of the outputs in this shift register
Check CurrPulseWidth at this output at this tick (PW_ctr)
Set val at this output LOW or HIGH accordingly
END FOR
Write to shift register
Reset value to be written next time
END FOR
Post to current shift register string
END FOR
Increment PW_ctr modulo MAX_PULSE_WIDTH

Start ES_SHORT_TIMER over again with DelayTime


ThisEvent is a CHANGE_PULSEWIDTH
Extract PW_idx and NewPW from ThisEvent.EventParam
Make sure PW_idx and NewPW are valid
IF PW_idx is not valid
Do nothing
END IF
IF NewPW width is greater than maximum allowed pulse width
Set the new pulse with to the max
END IF
Set the output at PW_idx to have pulse width NewPW in CurrPulseWidth
END Switch
SR_SetPWM
Parameters:

PulseWidth
OutputPin
-

New pulse width we want to set on OutputPin


Index of OutputPin we want to change

Returns:
Local Variables:
Pseudo-code:
Set the current pulse width of OutputPin to PulseWidth

SRPWM_HWInit
Parameters:
Returns:
Local Variables: Pseudo-code:
Initialize the shift register hardware
SRPWM_GetPW
Parameters:
PW_idx
Index of output pin we want to poll for its pulse width
Returns:
uint8_t
The value of the current pulse width at PW_idx
Local Variables: Pseudo-code:
IF PW_idx is not valid
Do nothing
Return 0
END IF
Return the current pulse width at PW_idx
Encode_Idx_PW
Parameters:

PW
PW_idx
uint16_t
-

Returns:
Local Variables:
Pseudo-code:
Shift PW_idx left 8 bits
Logical OR PW and PW_idx
Return the result

Pulse width to encode into an event parameter


Output pin index to encode into an event parameter
Encoded event parameter

ExtractIdx_PW
Parameters:
Param
An event parameter to decode
Returns:
uint8_t
Output pin index extracted from Param
Local Variables: ReturnVal
Holds the decoded value
Pseudo-code:
Return the 8 most significant bits of Param
ExtractIdx_PW
Parameters:
Param
An event parameter to decode
Returns:
uint8_t
Pulse width value extracted from Param
Local Variables: ReturnVal
Holds the decoded value
Pseudo-code:
Return the 8 least significant bits of Param

You might also like