2010-10-03 02:41 AM
how to count the 12 bit ADC count
2011-05-17 05:09 AM
Unfortunately ''count'' is not a very helpful term. When the ADC converts an input analog channel, it returns an unsigned integer value. For zero or negative input volts, it returns a value of zero. For 3.3 or higher volts, it returns a value of 4095. (Don't go too negative or too high to avoid damaging the ADC). In between zero and 3.3 volts, the ADC returns a corresponding ratioed value.
No ''counting'' is required, just a simple read. Look at the examples in the Library for further information on how to convert and read a channel. If I have misunderstood your question, please restate. Cheers, Hal2011-05-17 05:09 AM
and sending it to Hyperterminal (or any other application) is a matter of using the USART - again, see examples provided with the library...
2011-05-17 05:09 AM
Thanx for replying ...
actualy in my application my data (Analog temperature value ) i want read this so i am confg here RCC_Configuration(); SYSTICKS_Configuration(); GPIO_Config(); TIM2_Configuration(); NVIC_Configuration(); USART_Configuration(DBG_USART,115200); ADC_Config(); for read this channel.... u16 readADC1(u8 channel) { ADC_RegularChannelConfig(ADC1, channel, 1, ADC_SampleTime_55Cycles5); // Start the conversion ADC_SoftwareStartConvCmd(ADC1, ENABLE); // Wait until conversion completion while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); // Get the conversion value return ADC_GetConversionValue(ADC1); } but i didnt see the count value in hyperterminal so plz tel me what is the thing is wrong thanx2011-05-17 05:09 AM
''i didnt see the count value in hyperterminal''
Nothing in the code you've shown writes anything to the USART! Remember: to the STM32, Hyperterminal is irrelevant! All the STM32 knows is that it transmits bytes through the USART - where those bytes go from there is entirely immaterial to the STM32. See:[DEAD LINK /public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/ARM CortexM3 STM32/Hyperterminal is not the only terminal program!!&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E]https://my.st.com/public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fARM%20CortexM3%20STM32%2fHyperterminal%20is%20not%20the%20only%20terminal%20program%21%21&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E2011-05-17 05:09 AM
thanx andrew in main ()
while(1) { //u16 readADC1(u8 channel); ADC_val=ADC_GetConversionValue(ADC1); WriteSerial(DBG_USART,''count ''); Second_Delay(3); WriteSerial(DBG_USART,ADC_val); WriteSerial(DBG_USART,''\r\n'');2011-05-17 05:09 AM
How have you verified that your WriteSerial() routine actually works?
eg, have you tried it with a simple ''Hello, world'' program? Remember that serial comms is very, very slow relative the CPU execution - how do you ensure that the USART is ready before you call WriteSerial() again...?2011-05-17 05:09 AM
Sorry - stupid forum playing up again!
2011-05-17 05:09 AM
Dear Andrew….Thanx for reply…
Actually I want to disply the ADC count on USART
and this my code
int main(void)
{
u16 ADC_val;
RCC_Configuration();
SYSTICKS_Configuration();
GPIO_Config();
Delay_Ms(500);
TIM2_Configuration();
NVIC_Configuration();
USART_Configuration(DBG_USART,115200);
Delay_Ms(500);
WriteSerial(DBG_USART,'' hello \r\n'');
Delay_Ms(500);
ADC_Config();
u16 readADC1(u8 channel);
while(1)
{
//u16 readADC1(u8 channel);
ADC_val=ADC1ConvertedValue;
//strcat(ADC_val,'':'');
//sprif(ADC_val,ADC_val);
WriteSerial(DBG_USART,''SJA '');
Second_Delay(3);
WriteSerial(DBG_USART,ADC_val);
WriteSerial(DBG_USART,''\r\n'');
//WriteSerial(DBG_USART,''ADC_val'');
}
}
And ADC config
void ADC_Config(void)
{ADC_InitTypeDef ADC_InitStructure;ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel5configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_55Cycles5);
/* Enable ADC1 DMA */
//ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while (1)
{
}
}
u16 readADC1(u8 channel)
{
ADC_RegularChannelConfig(ADC1, 5, 1, ADC_SampleTime_55Cycles5);
// Start the conversion
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
// Wait until conversion completion
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
// Get the conversion value
//return ADC_GetConversionValue(ADC1);
ADC1ConvertedValue = ADC_GetConversionValue(ADC1);
}
// -------------- The ADC IRQ handler
--------------
/*
void ADC1_2_IRQHandler(void)
{
// Clear ADC1 EOC pending interrupt bit
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
// Get converted value of Channelxx converted by ADC1
ADC1ConvertedValue = ADC_GetConversionValue(ADC1);
cADC1_BUF1[cnt++]=ADC1ConvertedValue;
WriteSerial(DBG_USART,cADC1_BUF1);
if(cnt==128)
{
cnt=0;
}*/
How have you verified that your WriteSerial() routine actually works?
In hyper
only hello is displayed nt ADC_valY it is not displayed? Iam confusing plz help me.:-).
2011-05-17 05:09 AM
You still haven't showed the code of your WriteSerial() function!
And you still haven't said how you know that it actually works at all! But this doesn't look right:Here, you are passing a string to it:
WriteSerial( DBG_USART, '' hello \r\n'' );
But here, you are passing a u16 integer value:
WriteSerial( DBG_USART, ADC_val );
That can't be right, surely??!