Author Topic: Interrupt the ADC  (Read 1663 times)

0 Members and 1 Guest are viewing this topic.

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Interrupt the ADC
« on: June 11, 2018, 06:02:59 pm »
If an ADC is in progress when an interrupt (Timer1) occurs, will the conversion be interrupted? This is for a PIC 16F1827.

If so, to where does the interrupt return? Into the middle of the ADC?
You can release yourself but the only way to go is down!
RJD
 

Offline BocaDev

  • Contributor
  • Posts: 42
  • Country: us
Re: Interrupt the ADC
« Reply #1 on: June 11, 2018, 06:28:17 pm »
Interrupt the ADC
Interesting, I was wondering that myself except for the 8051 devices (I know, I know, are 8051 devices still around?)
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: Interrupt the ADC
« Reply #2 on: June 11, 2018, 06:33:57 pm »
No. The conversion is done by the ADC module. Interrupt only affects the CPU.

After the interrupt, the CPU will return to where it was before the interrupt has happened. If CPU was waiting for ADC, it'll continue waiting for ADC after the interrupt. Most likely the conversion will finish while CPU executes the interrupt.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Interrupt the ADC
« Reply #3 on: June 11, 2018, 06:35:30 pm »
The ADC of all 8 bit PIC families is a hardware module.   You set it up by configuring various bits in a couple of registers and enable it with the ADON control flag.  Then to perform a conversion you select an input channel to convert, wait briefly for the input to stabilise after switching input channels (or if converting a single channel, you can initialise it with that channel selected and skip further channel selection and the brief wait), then trigger the conversion by setting the Go_/Done control flag.  The conversion happens autonomously, and its completion and the presence of an updated result in the ADRESH:ADRESL register pair is signalled by it clearing the Go_/Done control flag and setting the ADIF interrupt flag.   

Except under certain special circumstances involving the FRC conversion clock and SLEEP mode, it doesn't matter what code the CPU core is running while the ADC is converting.   This includes going off to service your Timer 1 interrupt.  As an ADC conversion takes at most a few uS, the odds are the conversion will complete while the Timer 1 ISR is running, but the usual ADC code that loops polling the Go_/Done flag wont even notice - it will just see conversion complete and carry on to fetch the result.

By using a CCP module in compare: special event mode, the ADC module can run almost entirely autonomously, performing an ADC conversion at a predetermined time without further CPU core intervention.   However you do then need an ADC ISR to handle fetching the result and setting the channel and time for the next conversion.
« Last Edit: June 11, 2018, 06:39:02 pm by Ian.M »
 

Offline 0xFFF0

  • Regular Contributor
  • *
  • Posts: 87
  • Country: de
Re: Interrupt the ADC
« Reply #4 on: June 11, 2018, 08:33:56 pm »
Is there an automatic conversion loop mode? Or do I always have to trigger the GO again and again?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Interrupt the ADC
« Reply #5 on: June 11, 2018, 08:59:30 pm »
8 bit PIC CCP compare: special event mode resets the 16 bit timer that CCP module is using, so, assuming you initially started the timer from zero, it will continue to start ADC conversions at repeats of the same interval without further intervention.  However there is no DMA hardware to get the result in ADRESH:ADRESL  into an array in RAM so you need an ADC ISR with code to copy the result to RAM.
 

Offline 0xFFF0

  • Regular Contributor
  • *
  • Posts: 87
  • Country: de
Re: Interrupt the ADC
« Reply #6 on: June 11, 2018, 09:52:24 pm »
No expierience with that. Does it work with a timer interrupt too? A timer triggers, let's say every 50us, a GO. ADC-isr writes ADRESL into RAM.

 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Interrupt the ADC
« Reply #7 on: June 11, 2018, 11:34:59 pm »
You can do it that way, with two ISRs, but the ISR overhead is fairly high relative to the conversion time, so it makes more sense to use a CCP module to trigger the ADC and reset the timer.   Alternatively, especially if you are programming in C so have more entry/exit overhead in the ISR, it can be preferable to do a normal software driven complete ADC conversion in the timer ISR.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf