Giter Site home page Giter Site logo

nrf52-timer-gpiote-ppi-hands-on's Introduction

Timer, GPIOTE, PPI Hands On


Scope: The point of this hands-on is to learn how to use the PPI, Timer and GPIOTE peripherals. These peripherals will be used to implement a multi channel PWM feature that doesn't rely on a dedicated PWM module or software bitbanging, just the flexibility of the task/event system and the PPI module.

The picture below shows how the CC registers of a timer can be used to control several separate PWM channels through the PPI controller, as will be done in this example:

Task 1: Add an additional PWM channel

  1. Implement a method for initializing PWM channel 1, for a total of 2 individual PWM channels, and call it pwm1_init(uint32_t pinselect)

    Hint: You can copy pwm0_init(..) and use it as a starting point.

    Hint2: Remember to duplicate and change the PWM0_GPIOTE_CH, PWM0_PPI_CH_A, PWM0_PPI_CH_B and PWM0_TIMER_CC_NUM defines. Otherwise PWM channel 1 will conflict with PWM channel 0.

  2. Using the FORK feature of the PPI try to modify the pwm1_init(..) function you implemented in step 1 to reduce the number of PPI channels used (in total it should be sufficient to use 3 PPI channels for 2 PWM outputs).

    Hint: The FORK feature is useful when the same event needs to trigger several tasks.

  3. Implement a method for setting the duty cycle on PWM channel 1, and call it pwm1_set_duty_cycle(uint32_t value)

    Hint: You can copy pwm0_set_duty_cycle(..) and use it as a starting point

  4. Call the init function implemented in STEP 1, and configure the additional PWM channel on LED_2.

  5. Update the duty cycle of PWM channel 1, and add an offset to the counter to make the LED's blink out of phase.

    Optional: Add generic PWM functions for a total of 4 PWM channels

  6. Make a generic init function that takes both the PWM channel number and the pinselect as arguments, to avoid having to implement one function for each channel. The function should support up to 4 PWM channels total.

    Hint: Don't start on the optional steps until all the required steps are complete.

  7. Make a generic set duty cycle function to support a total of 4 PWM channels.

  8. Find a better workaround for a duty cycle of 0% or 100%, so that it is possible to set the PWM output either constantly high or low. Implement the workaround in pwmN_set_duty_cycle(uint32_t N, uint32_t value)

  9. Call the generic init function implemented in STEP 6, and configure 2 more PWM channels on LED_3 and LED_4.

  10. Update the duty cycle of PWM channel 2 and 3, using the generic functions implemented earlier.

nrf52-timer-gpiote-ppi-hands-on's People

Contributors

too1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.