text
stringlengths
0
234
-- increases and decreases. The value is more or less arbitrary, but
-- note that the effect of compiler optimization is observable.
begin
loop
Value := Percentage (50.0 * (1.0 + Sine (Arg)));
Power_Control.Set_Duty_Cycle (Value);
Arg := Arg + Increment;
end loop;
Function Definition: procedure Demo_DAC_Basic is
Function Body: Output_Channel : constant DAC_Channel := Channel_1; -- arbitrary
procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel);
-- Once the channel is enabled, the corresponding GPIO pin is automatically
-- connected to the analog converter output. However, in order to avoid
-- parasitic consumption, the PA4 pin (Channel_1) or PA5 pin (Channel_2)
-- should first be configured to analog mode. See the note in the RM, page
-- 431.
procedure Print (Value : UInt32);
-- Prints the image of the arg at a fixed location
procedure Await_Button;
-- Wait for the user to press and then release the blue user button
-----------
-- Print --
-----------
procedure Print (Value : UInt32) is
Value_Image : constant String := Value'Img;
begin
LCD_Std_Out.Put (170, 52, Value_Image (2 .. Value_Image'Last) & " ");
end Print;
------------------
-- Await_Button --
------------------
procedure Await_Button is
begin
Await_Pressed : loop
exit Await_Pressed when Set (User_Button_Point);
end loop Await_Pressed;
Await_Released : loop
exit Await_Released when not Set (User_Button_Point);
end loop Await_Released;
end Await_Button;
------------------------
-- Configure_DAC_GPIO --
------------------------
procedure Configure_DAC_GPIO (Output_Channel : DAC_Channel) is
Output : constant GPIO_Point := (if Output_Channel = Channel_1
then DAC_Channel_1_IO
else DAC_Channel_2_IO);
begin
Enable_Clock (Output);
Configure_IO (Output, (Mode => Mode_Analog, Resistors => Floating));
end Configure_DAC_GPIO;
begin
Initialize_LEDs;
All_LEDs_Off;
LCD_Std_Out.Clear_Screen;
Configure_User_Button_GPIO;
Configure_DAC_GPIO (Output_Channel);
Enable_Clock (DAC_1);
Reset (DAC_1);
Select_Trigger (DAC_1, Output_Channel, Software_Trigger);
Enable_Trigger (DAC_1, Output_Channel);
Enable (DAC_1, Output_Channel);
declare
Value : UInt32 := 0;
Percent : UInt32;
Resolution : constant DAC_Resolution := DAC_Resolution_12_Bits;
-- Arbitrary, change as desired. Counts will automatically adjust.
Max_Counts : constant UInt32 := (if Resolution = DAC_Resolution_12_Bits
then Max_12bit_Resolution
else Max_8bit_Resolution);
begin
Put (0, 0, "VRef+ is 2.95V"); -- measured
Put (0, 25, "Button advances");
Put (0, 52, "Current %:");
loop
for K in UInt32 range 0 .. 10 loop
Percent := K * 10;