1
\$\begingroup\$

I am working with PIC24EP256GP204. The CPU frequency is 64 MHz. I am generating two PWM pulses for TCD1304AP CCD sensor and two PWM pulses for WM8253 ADC AFE.

My problem lies with PWM pulses for ADC as i have to use ISRs to fetch data.

I need to sync Vsmp (it determines sampling point and frequency) and Master clock of ADC so that i can read the 16-Bit output of ADC (which is available in 4-Bit multiplexed format). I am generating square wave of frequency 3 MHz for Master clock of ADC and square wave of 500 KHz for Vsmp. I have verified the wave-forms with a digital oscilloscope.

But for syncing and reading the output of ADC AFE, i need to run some code in ISR of Vsmp and Master clock of ADC. If i just clear the interrupt flags in respective ISRs, then everything works perfectly. However, even a few lines of code in C programming language makes the PIC24EP hang. I couldn't post my whole code base as it is huge. I have posted ISRs code. Please have a look:

volatile bool vsmp_failing_edge = false; // VSMP ISR void __attribute__((__interrupt__, no_auto_psv)) _OC3Interrupt(void) { vsmp_failing_edge = true; IFS1bits.OC3IF = 0; } // ADC ISR void __attribute__((__interrupt__, no_auto_psv)) _OC4Interrupt(void) { /* Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); */ if (vsmp_failing_edge) { // oc_disable(OC_CHANNEL_4); vsmp_failing_edge = false; } IFS1bits.OC4IF = 0; } 

The ISR _OC4 is assigned to Master clock of ADC which is running at 3 MHz and ISR _OC3 is assigned to Vsmp which is running at 500 KHz. The output of ADC is available at few other pins in 4-Bit multiplexed format.

ISR _OC3 is executed at falling edge of Vsmp pin. In the interrupt, i am setting some flag. After 16.5 Master clock cycles, i have to read 4 external pins at falling edge of master clock pulses. I have to read at four consecutive falling edges of master clock to get complete data.

Please comment on my approach or suggest better approaches for the sensor and ADC.

I also thought of using Pin change interrupt at Master Clock pulse output pin and some timer interrupt to fetch the data. However, i haven't implemented that approach because i am not sure if PIC24EP can handle the waveform generation and sync at the frequency i want it to.


EDIT:

If you look at code of _O4 ISR, you can find 60 Nop() instructions along with IFS1bits.OC4IF = 0; line will make PIC hang. I have added Nop() instructions to verify the number of instruction cycles required to make it hang.

The Nop() instructions are commented out. Without them, only the if condition and IFS1bits.OC4IF = 0; line will make PIC hang. So, you can conclude that Nop() instructions are equivalent to just if part of the ISR in terms of execution time.

\$\endgroup\$
2
  • \$\begingroup\$ How many instructions are in the 'few lines in C' Is it represented by the NOP()s? (and if so, how many do you need to make it hang?). \$\endgroup\$ Commented Mar 22, 2017 at 10:33
  • \$\begingroup\$ I have edited my question. Please have a look at EDIT section \$\endgroup\$ Commented Mar 22, 2017 at 10:43

1 Answer 1

0
\$\begingroup\$

I have tried every other possibility. Looks like there is large overhead in ISR of PIC microcontroller. I can't generate signals any faster than 1 MHz with the controller I have. Only solution is to write in assembly (which is not an good idea) or to switch controller (for now, i have dropped the idea of generating pulses by this method).

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.