How to use ADC_SAR_Seq to get range interrupts on individual channels

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Doorknob
Level 4
Level 4
First solution authored 50 replies posted 25 replies posted

I am using a ADC_SAR_Seq component and  using the internal range detection two of the channels. However I want to distinguish in an interrupt which channel  is being tripped by my range setting.  Is this possible to do, and if so how would I do it?

Thanks

0 Likes
1 Solution

Will this work?

CY_ISR(ADC_ISR_Handler)
{
uint32 intr_status;
uint32 range_status;

/* Read interrupt status registers */
intr_status = ADC_SAR_INTR_MASKED_REG;
/* Check for End of Scan interrupt */
if ((intr_status & ADC_EOS_MASK) != 0u)
{
/* Read range detect status */
range_status = ADC_SAR_RANGE_INTR_MASKED_REG;
/* If range limit detected in Foward or Reverse on Motor-One stop it */
if((range_status & (uint32)(1ul << ADC_Ch0_IS1)) != 0u || (range_status & (uint32)(2ul << ADC_Ch1_IS2)) != 0u )
{
Motor1_En_Write(Disable);
}
/* If range limit detected in Foward or Reverse on Motor-Two stop it */
if((range_status & (uint32)(3ul << ADC_Ch2_IS3)) != 0u || (range_status & (uint32)(4ul << ADC_Ch3_IS4)) != 0u )
{
Motor2_En_Write(Disable);
}
/* Clear range detect status */
ADC_SAR_RANGE_INTR_REG = range_status;

/* Clear range detect status */
ADC_SAR_RANGE_INTR_REG = ADC_Range_Trip;
/* Set Data Ready Flag for reading ADC values */
dataReady = 1u;
}
/* Clear handled interrupt */
ADC_SAR_INTR_REG = intr_status;

View solution in original post

0 Likes
3 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

You can check SAR_RANGE_INTR register in Registers TRM . You can check this register in ISR to see which channel triggered the interrupt by checking the status of the corresponding bit.

Best Regards,
Vasanth

0 Likes
Doorknob
Level 4
Level 4
First solution authored 50 replies posted 25 replies posted

Vasanth,

thank you for the reply, but i am not familiar with this task.  Could I impose on you and ask for a code example?

Thanks

 

0 Likes

Will this work?

CY_ISR(ADC_ISR_Handler)
{
uint32 intr_status;
uint32 range_status;

/* Read interrupt status registers */
intr_status = ADC_SAR_INTR_MASKED_REG;
/* Check for End of Scan interrupt */
if ((intr_status & ADC_EOS_MASK) != 0u)
{
/* Read range detect status */
range_status = ADC_SAR_RANGE_INTR_MASKED_REG;
/* If range limit detected in Foward or Reverse on Motor-One stop it */
if((range_status & (uint32)(1ul << ADC_Ch0_IS1)) != 0u || (range_status & (uint32)(2ul << ADC_Ch1_IS2)) != 0u )
{
Motor1_En_Write(Disable);
}
/* If range limit detected in Foward or Reverse on Motor-Two stop it */
if((range_status & (uint32)(3ul << ADC_Ch2_IS3)) != 0u || (range_status & (uint32)(4ul << ADC_Ch3_IS4)) != 0u )
{
Motor2_En_Write(Disable);
}
/* Clear range detect status */
ADC_SAR_RANGE_INTR_REG = range_status;

/* Clear range detect status */
ADC_SAR_RANGE_INTR_REG = ADC_Range_Trip;
/* Set Data Ready Flag for reading ADC values */
dataReady = 1u;
}
/* Clear handled interrupt */
ADC_SAR_INTR_REG = intr_status;

0 Likes