Skip to main content
SConf
Associate
October 24, 2018
Question

Why ADC watchdog is not triggering.

  • October 24, 2018
  • 1 reply
  • 898 views

The code is as follows....

RCC_AHBPeriphClockCmd (RCC_AHBPeriph_DMA1, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

static RCC_ClocksTypeDef clocks;

RCC_GetClocksFreq(&clocks);

// Analog inputs - GPIO

GPIO_InitTypeDef GPIO_InitStructure = {0};

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

GPIO_Init(GPIOC, &GPIO_InitStructure);

DMA_DeInit(DMA1_Channel1);

DMA_InitTypeDef DMA_InitStructure;

DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;

DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&g_analogInput1RawData[0];

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

DMA_InitStructure.DMA_BufferSize = 3;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel1, &DMA_InitStructure);

DMA_Cmd(DMA1_Channel1, ENABLE);

// TODO for test only DMA_ITConfig(DMA1_Channel1, DMA_IT_TC | DMA_IT_TE, ENABLE);

NVIC_InitTypeDef NVIC_InitStructure;

// ADC Interrupt

NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

// DMA Interrupt

NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

ADC_DeInit(ADC1);

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 = 3;

ADC_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_55Cycles5);

ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_55Cycles5);

ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_55Cycles5);

ADC_Cmd(ADC1, ENABLE);

ADC_DMACmd(ADC1, ENABLE);

ADC_ITConfig(ADC1, ADC_IT_AWD , ENABLE);

ADC_ResetCalibration(ADC1);

while (ADC_GetResetCalibrationStatus(ADC1));

ADC_StartCalibration(ADC1);

while (ADC_GetCalibrationStatus(ADC1));

uint16_t lowThreshold = 3700;

uint16_t highThreshold = 3500;

ADC_AnalogWatchdogThresholdsConfig(ADC1, highThreshold, lowThreshold);

ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);

ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_0);

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

The registers seem to be set correctly....

0690X000006CFSmQAO.jpg

The analog voltage read in is 3794. Since the high threshold is 3700 shouldn't the analog watchdog have been triggered?

    This topic has been closed for replies.

    1 reply

    SConf
    SConfAuthor
    Associate
    October 24, 2018

    ​Correction...

    uint16_t lowThreshold = 3300;

    uint16_t highThreshold = 3500;

    Actual still 3794.

    I was changing thresholds to and the previous was incorrect. No matter what the threshold I don't get the interrupt.