Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. with Stm32.USB; use Stm32.USB;
  2. with Stm32.Defines; use Stm32.Defines;
  3. with Stm32.ADC; use Stm32.ADC;
  4. with Interfaces; use Interfaces;
  5.  
  6. procedure TestADC is
  7. --Specific parameters.
  8. Params : constant ADC_Params :=
  9. (Resolution => Resolution_12b,
  10. Scan_Conv_Mode => Disable,
  11. Continuous_Conv_Mode => Enable,
  12. External_Trig_Conv_Edge => None,
  13. External_Trig_Conv => T1_CC1,
  14. Data_Align => Right,
  15. Nbr_Of_Conversion => 1);
  16. --Common parameters.
  17. Common_Params : constant ADC_Common_Params :=
  18. (Mode => Mode_Independent,
  19. Prescaler => Div_8,
  20. DMA_Access_Mode => Disabled,
  21. Two_Sampling_Delay => Delay_5Cycles);
  22. --The value where the read datas are written
  23. Temp_Value : Unsigned_16 := 0;
  24. type Datas is array(0..1) of Unsigned_8;
  25. --I use this variable to separate Temp_Value in two parts in order to be able to
  26. --send them thanks to character (8bits).
  27. Temp_Value1 : Datas;
  28. for Temp_Value1'Address use Temp_Value'Address;
  29. --The channel of the TempSensor for my card. It may also be 18. Read the doc.
  30. ADC_Channel_TempSensor : constant ADC_Channel_Number := 16;
  31. begin
  32. --Common parameters initialization
  33. ADC_Init_Common(Common_Params);
  34. --ADC initialization
  35. ADC_Init(1,Params);
  36. --Channel config
  37. Regular_Channel_Config(1,ADC_Channel_TempSensor,1,Sample_Time_144Cycles);
  38. --Temperature sensor
  39. ADC_TempSensorVrefintCmd(Enable);
  40. --Activation ADC
  41. Configure_ADC(1,Enable);
  42. --Start conversion
  43. Start_Conv(1);
  44. loop
  45. --I check if the conversion has completed.
  46. if ADC_GetFlagStatus(1,EOC) then
  47. --Get the value of the conversion
  48. Temp_Value := ADC_GetConversionValue(1);
  49. --and send it by USB.
  50. Send("" & Character'Val(Temp_Value1(1)) & Character'Val(Temp_Value1(0)) & " ");
  51. --Clear the flags to be sure we do not read the same value.
  52. ADC_ClearFlag(1,EOC);
  53. end if;
  54. end loop;
  55. end TestADC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement