Created
January 31, 2015 19:16
-
-
Save Aunsiels/7d97ee28f1e5e69f937c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Stm32.USB; use Stm32.USB; | |
with Stm32.Defines; use Stm32.Defines; | |
with Stm32.ADC; use Stm32.ADC; | |
with Interfaces; use Interfaces; | |
pragma Elaborate_All(Stm32.ADC); | |
package body TestADC is | |
--Specific parameters. | |
Params : constant ADC_Params := | |
(Resolution => Resolution_12b, | |
Scan_Conv_Mode => Disable, | |
Continuous_Conv_Mode => Enable, | |
External_Trig_Conv_Edge => None, | |
External_Trig_Conv => T1_CC1, | |
Data_Align => Right, | |
Nbr_Of_Conversion => 1); | |
--Common parameters. | |
Common_Params : constant ADC_Common_Params := | |
(Mode => Mode_Independent, | |
Prescaler => Div_8, | |
DMA_Access_Mode => Disabled, | |
Two_Sampling_Delay => Delay_5Cycles); | |
--The value where the read datas are written | |
Temp_Value : Unsigned_16 := 0; | |
type Datas is array(0..1) of Unsigned_8; | |
--I use this variable to separate Temp_Value in two parts in order to be able to | |
--send them thanks to character (8bits). | |
Temp_Value1 : Datas; | |
for Temp_Value1'Address use Temp_Value'Address; | |
--The channel of the TempSensor for my card. It may also be 18. Read the doc. | |
ADC_Channel_TempSensor : constant ADC_Channel_Number := 16; | |
protected body ADC_Interface is | |
procedure ADC_Interrupt_Handler is | |
begin | |
--I check if the conversion has completed | |
if ADC_GetFlagStatus(1,EOC) then | |
--Get the value of the conversion | |
Temp_Value := ADC_GetConversionValue(1); | |
--and send it by USB. | |
Send("" & Character'Val(Temp_Value1(1)) & Character'Val(Temp_Value1(0)) & " "); | |
--Clear the flags to be sure we do not read the same value. | |
ADC_ClearFlag(1,EOC); | |
end if; | |
end ADC_Interrupt_Handler; | |
end ADC_Interface; | |
begin | |
--Common parameters initialization | |
ADC_Init_Common(Common_Params); | |
--ADC initialization | |
ADC_Init(1,Params); | |
--Channel config | |
Regular_Channel_Config(1,ADC_Channel_TempSensor,1,Sample_Time_144Cycles); | |
--Temperature sensor | |
ADC_TempSensorVrefintCmd(Enable); | |
--Activation ADC | |
Configure_ADC(1,Enable); | |
--Activates Interrupt on ADC | |
ADC_ITConfig(1, IT_EOC, Enable); | |
--Activates the interrupt on NVIC | |
NVIC_Init(ADC_IRQn, 1); | |
--Start conversion | |
Start_Conv(1); | |
loop | |
null; | |
end loop; | |
end TestADC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with Stm32.NVIC; use Stm32.NVIC; | |
pragma Elaborate_All (Stm32.NVIC); | |
package TestADC is | |
protected type ADC_Interface is | |
procedure ADC_Interrupt_Handler; | |
--Link the function and the Handler. | |
pragma Attach_Handler(ADC_Interrupt_Handler, ADC_IRQn); | |
end ADC_Interface; | |
--Instanciates a ADC_Interface | |
ADC_Int : aliased ADC_Interface; | |
end TestADC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment