This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to trigger ADC from a timer interrupt, while generating PWM with the same timer and while using BLE on nRF51822?

Hi. I am a newbie in Nordic chips, quite knowledgeable in Atmel AVR, though. I'm working with an nRF51822 on a board like this www.waveshare.com/.../BLE400. I use the Mbed environment.

What I'm trying to do is this:

Generate a PWM signal on a pin, with period approximately equal to 4ms (200 ~ 250Hz) and variable duty cycle (within some limits, without ever reaching 0). Simultaneously, I want to measure voltage in another pin, but I want the ADC to trigger during the positive part of the PWM, in each cycle. That is, I'm controlling a heater with PWM, and want to measure current as a feedback, but I need to sample it during the positive cycle, synchronized to PWM, otherwise I would have random errors in the measure.

I have done this without trouble in AVR, using a hardware timer with interrupts, but I have no idea how to do it in the nRF51822 (maybe PPI? also no idea how to code it in Mbed..). In addition, I need to maintain a BLE connection while doing simultaneously PWM and ADC.

Any advice you can give me, I'm grateful.

Greetings.

Parents
  • Hi,

    I suggest that you use the PWM library for nRF51, a GPIOTE channel, and PPI. Since the PWM library use a GPIOTE channel to control the PWM pin, you will need to connect the PWM pin to a different GPIO externally and use a second GPIOTE channel to register positive edges there. A GPIOTE event on a positive edge can then directly be used to trigger an ADC START task and make it do a conversion via PPI.

    However you might not want to sample the voltage on every edge? That sounds like quite a lot of work for the CPU while at the same time doing BLE. So what you could do then, is to use a TIMER/COUNTER and use the GPIOTE positive edge event to trigger a COUNT task in the counter. Then you can do measurements every time the counter reaches a certain count. This can all be done autonomously and you need only wake up when the ADC conversion is completed.

Reply Children
No Data
Related