Here is some sample code to use the ECAP module as a timer:

#include <stdint.h>
#include <string.h>
#include <pru_cfg.h>
#include <pru_ecap.h>

#define PRU0_ARM_INTERRUPT 19  // Interrupt used to signal to host we have 
halted

volatile register uint32_t __R30;  // Output pins
volatile register uint32_t __R31;  // Input pins

/* Mapping Constant table register to variable */
volatile pruCfg CT_CFG __attribute__((cregister("CFG", near), peripheral));  // 
PRU configuration from constants table
volatile pruEcap ECAP __attribute__((cregister("ECAP", near), peripheral));  // 
ECAP module from constants table

#define ROUT __R30
#define RIN __R31

int main(void) {

    // Enable OCP master ports - this enables pinmux pins to R30 & R31 & host 
ram access
    CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;

    // Enable ECAP port for simple PWM (We need a timer tick)
    ECAP.ECCTL2 = 0x0200; // PWM mode,continuous mode
    ECAP.CAP1 = 0x060000; // Period = 1/1000th second
    ECAP.CAP2 = 0x000000; // Duty cycle
    ECAP.TSCTR  = 0;      // Reset the counter (it may be past the period)
    ECAP.CTRPHS = 0;
    ECAP.ECEINT = 0x0040; // Counter reset interrupt enable
    ECAP.ECCTL1 = 0x0000; // do not reset on capture
    ECAP.ECCTL2 |= 0x10;  // Start the timer

    while (1) {
               // Do work in the loop

                while ((ECAP.ECFLG & 0x40) == 0); // Wait for timer to reset
                ECAP.ECCLR = 0xff; // Clear the condition
    }
}

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to