Page 1 of 1

Triggered ADC on MOD54415

Posted: Mon Jun 24, 2013 9:59 am
by xt5160
I have some mcPWMs generating read and clock pulses on mcPWM[A2] and mcPWM[A3] respectively for a linescan camera. The camera has an analog signal (verified working by scope) going to ADC0. New pixel data is generated by the clock rising edge. I'm trying to trigger the ADC using mcPWM3VAL[4] whem analog is certain to be stable. I can see the pulse on [B3] so I know it's working. No matter what I do, I can't seem to get anyting out of the ADC.

I'm setting the ADC to parallel triggered (I've tried sequential, too)

sim2.adc.cr1 = 0x1005; // SMODE Triggered Parallel

Section 29.51, says that a conversion is started "Upon an intial start or enabled sync pulse" but I can't seem to find what "enables" a sync pulse, and what exactly constitutes a sync pulse. Triggers? Physical?

The mcPWM is loaded

sim1.mcpwm.sm[3].cr1 = 0x0424; // FULL, fClk/4, LDMOD
sim1.mcpwm.sm[3].cr2 = 0x2000; // A0 & B0 independent
sim1.mcpwm.sm[3].init = 0; // start counter value (reload)
sim1.mcpwm.sm[3].val[1] = 239; // end counter value
sim1.mcpwm.sm[3].val[2] = 60; // PWM A ON counter value
sim1.mcpwm.sm[3].val[3] = 180; // PWM A OFF counter value
sim1.mcpwm.sm[3].val[4] = 120; // PWM B ON counter value
sim1.mcpwm.sm[3].val[5] = 180; // PWM B OFF counter value
sim1.mcpwm.sm[3].ocr = 0;
sim1.mcpwm.sm[3].otcr = 0x0010; // Generate Trigger OUT_TRIG0 on VAL[4]
sim1.mcpwm.sm[3].dismap=0xFFF0;

I'm selecting a trigger for the ADC (ref 10.13.11)
sim1.ccm.adctsr = 0x001C; // TRIG0 Channel 3
I must admit I'm a bit confused by the manaual, as it implies the default (Reset) values will use PWM_A Channel 0 for both ADCs.

I've tried both TRIG0 and 1. Same (non) results. Ditto with PWM_A, PWM_X.
What am I missing here?

Re: Triggered ADC on MOD54415

Posted: Tue Jun 25, 2013 5:53 am
by khoney
I haven't used the MOD54415, but I'm using the Nano, and I got tripped up by a voltage supply that I didn't think I needed. The Netburner datasheet made it sound like it could be generated internally, but that turned out to not be the case, so first make sure your analog supply and reference voltages are good if you haven't already.

Re: Triggered ADC on MOD54415

Posted: Tue Jun 25, 2013 12:52 pm
by xt5160
I ran into that problem, too. Unlike the MOD5213 dev kit, The MOD54415 needs both analog common and reference pins connected. Before I started this project, I made sure the SimpleAD example was working, and the ADC returned good values. It took me a while to find the problem because the DEV70 board has the A0 to A7 inputs tied to the DIP switches and pulldowns; I was getting bizarre results until I found that little "gotcha". For anyone reading this, be aware your analog source is going to be driving a 1K load.
Section 29.5.5 states that "Scanning is initiated when the START0 bit is set or, if the SYNC0 bit is set, when the SYNC0 input is asserted", but I have not been able to find the elusive "SYNC0 input". I'm somewhat certain it's not physical (there's only a single Port G1 labeled PWM_SYNC, and that's an input to the mcPWM). I've been under the impression that it's the TRIGn signal from the mcPWM because section 29.1.1 states the ADC "• Can be synchronized to the PWM via the PWM_SYNC0/1 input signal". AN4485 seems to confirm this, but does not make it clear whether both ADC sections have to be used when all 6 PWM events are triggers (especially since there is no way for TRIG0 and TRIG1 to both be selected on the same ADC). However, section 10.3.11 (the ADC Trigger Select Register) seems to expand on this by allowing almost any PWM event to trigger the ADC. I do explicitly set the ADCTSR for the trigger I'm using, but I've tried the other events also, with no luck.

Re: Triggered ADC on MOD54415

Posted: Wed Jun 26, 2013 8:24 am
by khoney
There's no code shown to start the scan (setting bit 13 of CR1), so I assume you're just not showing that in your code sample? Have you tried to get things working in loop mode first?

Re: Triggered ADC on MOD54415

Posted: Wed Jun 26, 2013 11:48 am
by mbrown
khoney: you don't need to set the start bit to start the scan. That's supposed to be the beauty of this setting. You don't need to tell the ADC to start sampling, it works automatically when the pwm is triggered.

I have had some success with this. The settings xt5160 may have been looking for are as follows:

sim2.adc.cr1 = 0x1001; // SMODE Once Parallel, SYNC0 set
sim1.ccm.adctsr = 0x0019; // PWMB Channel 3

Although sim1.ccm.adctsr = 0x001C; should also work with the PWM settings he's working with.

If you've started using the base code for SimpleAtoD, the way the ADDone function works is that it checks the EOSI1 bit in the ADC_SR or that the scan has been completed. The triggering scan mode in the ADC_CR1 has a somewhat misleading name. It isn't to set the adc to run when triggered by an external signal. It is meant to trigger an end sampling when "a disabled sample is encountered". What a disabled sample is is not very clear from the manual to me as of yet, but if all you want to do is read all the pins once, the once sequential or once parallel modes are what you want. In these modes, the end of scan interrupt bit should be triggered properly and the functions from the SimpleAtoD example would all work correctly.