How to do PWM capture on xcore.ai board ?

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
uc69
Member
Posts: 13
Joined: Thu Jan 04, 2018 8:34 pm

How to do PWM capture on xcore.ai board ?

Post by uc69 »

Dear Community,

Is it possible to do accurate PWM capture with the xcore.ai evaluation board ?
Presently I'm doing it with timers on a STM32 H723ZG board but I would like to off-load this task to free the timers for other tasks. (& transmitting the measurements via SPI to the STM32 board)
The purpose is to measure the PWM output pulses of a standard 14-channel RC receiver. So 50 Hz frequency and pulses width from 1 ms to 2 ms.
Any code snippets/starting examples (different methods in XC with cons and pros ?) would be very welcome as I'm still a beginner in XC programming. I guess the multicore architecture can be useful for these accurate measurements ?
Thank you,


User avatar
fabriceo
XCore Addict
Posts: 186
Joined: Mon Jan 08, 2018 4:14 pm

Post by fabriceo »

Hi you may be interested by reviewing this old source code:
https://github.com/xcore/sw_logic_analyzer
on the xcore.ai, you have 10 timer per tile, thats quite a lot.
also each pin can drive an event when its value change so you could use this to mesure time elapsed since last change.

something like that:

Code: Select all

void measurePwm(chanend c, port p1){
    int val = 1;
    int pulse = 0;
    timer tt;
    while(1) {
        select {
            case  p1 when pinseq(val) :> void : {
                int time ; tt :> time;
                if (val) { pulse = time; val = 0; }
                else {
                    pulse = time - pulse;
                    c <: pulse;
                    val = 1; }
            break ;}
        }
    }
}
also instead of using multiple timer you might be interested in using the master timer and mesure time regarding this one.
just use this to read its absolute value (32bits)
asm volatile ("gettime %0":"=r"(myvar));