text
stringlengths 0
234
|
|---|
while DMA2D_Periph.BGPFCCR.START loop
|
-- Wait for CLUT loading...
|
null;
|
end loop;
|
end if;
|
Function Definition: procedure Demo_Timer_PWM is -- low-level demo of the PWM capabilities
|
Function Body: Period : constant := 1000;
|
Output_Channel : constant Timer_Channel := Channel_2;
|
-- The LED driven by this example is determined by the channel selected.
|
-- That is so because each channel of Timer_4 is connected to a specific
|
-- LED in the alternate function configuration on this board. We will
|
-- initialize all of the LEDs to be in the AF mode for Timer_4. The
|
-- particular channel selected is completely arbitrary, as long as the
|
-- selected GPIO port/pin for the LED matches the selected channel.
|
--
|
-- Channel_1 is connected to the green LED.
|
-- Channel_2 is connected to the orange LED.
|
-- Channel_3 is connected to the red LED.
|
-- Channel_4 is connected to the blue LED.
|
--------------------
|
-- Configure_LEDs --
|
--------------------
|
procedure Configure_LEDs;
|
procedure Configure_LEDs is
|
begin
|
Enable_Clock (GPIO_D);
|
Configure_IO
|
(All_LEDs,
|
(Mode_AF,
|
AF => GPIO_AF_TIM4_2,
|
AF_Speed => Speed_50MHz,
|
AF_Output_Type => Push_Pull,
|
Resistors => Floating));
|
end Configure_LEDs;
|
-- The SFP run-time library for these boards is intended for certified
|
-- environments and so does not contain the full set of facilities defined
|
-- by the Ada language. The elementary functions are not included, for
|
-- example. In contrast, the Ravenscar "full" run-times do have these
|
-- functions.
|
function Sine (Input : Long_Float) return Long_Float;
|
-- Therefore there are four choices: 1) use the "ravescar-full-stm32f4"
|
-- runtime library, 2) pull the sources for the language-defined elementary
|
-- function package into the board's run-time library and rebuild the
|
-- run-time, 3) pull the sources for those packages into the source
|
-- directory of your application and rebuild your application, or 4) roll
|
-- your own approximation to the functions required by your application.
|
-- In this demonstration we roll our own approximation to the sine function
|
-- so that it doesn't matter which runtime library is used.
|
function Sine (Input : Long_Float) return Long_Float is
|
Pi : constant Long_Float := 3.14159_26535_89793_23846;
|
X : constant Long_Float := Long_Float'Remainder (Input, Pi * 2.0);
|
B : constant Long_Float := 4.0 / Pi;
|
C : constant Long_Float := (-4.0) / (Pi * Pi);
|
Y : constant Long_Float := B * X + C * X * abs (X);
|
P : constant Long_Float := 0.225;
|
begin
|
return P * (Y * abs (Y) - Y) + Y;
|
end Sine;
|
-- We use the sine function to drive the power applied to the LED, thereby
|
-- making the LED increase and decrease in brightness. We attach the timer
|
-- to the LED and then control how much power is supplied by changing the
|
-- value of the timer's output compare register. The sine function drives
|
-- that value, thus the waxing/waning effect.
|
begin
|
Configure_LEDs;
|
Enable_Clock (Timer_4);
|
Reset (Timer_4);
|
Configure
|
(Timer_4,
|
Prescaler => 1,
|
Period => Period,
|
Clock_Divisor => Div1,
|
Counter_Mode => Up);
|
Configure_Channel_Output
|
(Timer_4,
|
Channel => Output_Channel,
|
Mode => PWM1,
|
State => Enable,
|
Pulse => 0,
|
Polarity => High);
|
Set_Autoreload_Preload (Timer_4, True);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.