KL27Z: Driving I/O pin and ADC trigger with a timer

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

KL27Z: Driving I/O pin and ADC trigger with a timer

1,257 次查看
robertpoor
Senior Contributor I

Currently I'm doing the following loop in firmware.  I'd like to offload the processor and do this directly in the hardware:

1. Drive GPIOx1 high and drive GPIOx2 low

2. Initiate a read on the ADC and wait for the conversion to complete

3. Add result of ADC to a running total

4. Drive GPIOx1 low and drive GPIOx2 high

5. Initiate a read on the ADC and wait for the conversion to complete

6. Subtract result of ADC from a running total

To move this into hardware, my thoughts are as follows, but I'm looking for guidance and/or gotchas:

  • For the GPIO pins (steps 1 and 4) use a pair of TPM channels in PWM mode with 50% duty cycle, initialized so they run out of phase from one another
  • Set up the ADC to trigger on a PWM transition (is that possible?).  Alternatively, initialize LPTMR to have the same period as the PWMs and use that to trigger the ADC.
  • Configure the ADC to write its output using DMA transfer.
  • Set up some mechanism (not sure what's best) to stop the ADC after N samples have been written
  • In the foreground, wait for the N samples to be written, then do the add / subtract operation (steps 3 and 6) in firmware.

Some questions:

  • Is this a feasible approach?
  • Is there a better / simpler / more idiomatic way to accomplish the same results?
  • Is there a mechanism to notify the firmware that N samples have been written (either via polling or interrupt)?
  • I have a spare analog inverter in my system.
标签 (1)
0 项奖励
回复
1 回复

1,061 次查看
mjbcswitzerland
Specialist V

Hi Robert
 
See appendix A/section E of http://www.utasker.com/docs/uTasker/uTaskerADC.pdf
This shows how a TPM module can be used to trigger inputs A and B of ADC modules. If you set up DMA transfer to a buffer on each output conversion (reference in chapter 3 of the same document) and a defined length you can automate the operation to stop after a certain number of samples with an interrupt - the samples can then be summed and negated in SW after it has completed (or while a following sequence of samples is taking place).

Since you have 6 PWM channels on TPM0 in the KL27 you can use two for the ADC triggering (controlled points in the cycle) and two for the output square waves that you require (which are fully synchronised). See chapter 5 of http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF whereby you can control anti-phased outputs using ELSA (low true pulses)/ELSB (high true pulses) settings

Regards

Mark

 
uTasker developer and supporter (+5'000 hours experience on +60 Kinetis derivatives in +80 product developments)
Kinetis: http://www.utasker.com/kinetis.html


Kinetis KL25, KL26, KL27, KL28, KL82, KL43, KL46
- http://http://www.utasker.com/kinetis/FRDM-KL25Z.html
- http://www.utasker.com/kinetis/TWR-KL25Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL26Z.html
- http://www.utasker.com/kinetis/TEENSY_LC.html
- http://www.utasker.com/kinetis/FRDM-KL27Z.html
- http://www.utasker.com/kinetis/Capuccino-KL27.html
- http://www.utasker.com/kinetis/FRDM-KL28Z.html
- http://www.utasker.com/kinetis/FRDM-KL82Z.html
- http://www.utasker.com/kinetis/FRDM-KL43Z.html
- http://www.utasker.com/kinetis/TWR-KL43Z48M.html
- http://www.utasker.com/kinetis/FRDM-KL46Z.html
- http://www.utasker.com/kinetis/TWR-KL46Z48M.html

0 项奖励
回复