This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PPM decode with HET timer

Other Parts Discussed in Thread: HALCOGEN

Hi,

I'm trying to decode a PPM signal with a TMS570LC43x and the use of an HET timer. So far I've been able to trigger an edge interrupt, but something goes wrong with measuring time between two interrupts. The PPM signal has 8 channels, so there should be 9 interrupts. Below the interrupt handler and calculation of the duration between the interrupts.

void   edgeNotification(hetBASE_t * hetREG,uint32 edge){

	ppm_values[spike] = hetGetTimestamp(hetRAM1);
	++spike;

	if(spike == 9){
		spike = 0;
		hetResetTimestamp(hetRAM1);
		calculate_ppm();
	}
}

void calculate_ppm(){
	uint32 t0 = ppm_values[0] - ppm_values[1];
	uint32 t1 = ppm_values[1] - ppm_values[2];
	uint32 t2 = ppm_values[2] - ppm_values[3];
	uint32 t3 = ppm_values[3] - ppm_values[4];
	uint32 t4 = ppm_values[4] - ppm_values[5];
	uint32 t5 = ppm_values[5] - ppm_values[6];
	uint32 t6 = ppm_values[6] - ppm_values[7];
	uint32 t7 = ppm_values[7] - ppm_values[8];
}

In my main I've called hetInit();. In HalcoGen the frequency of HET1 is set to 1MHz, so each tick should be 1 uS (?). The values of t1-t7 are all somewhere around 4294742144. The time between each spike should be 1500 uS... Am I missing something? What goes wrong here?

Thanks, Jesse

  • HI Jesse,
    What are the 9 different values in ppm_values? Do they make sense to you? Are they in an ascending order?

    When you said 4294742144, can you clarify? Is this one single value or are they multiple values?

    I'd would have expected ppm_values[0] to contain the smallest timestamp value while ppm_values[8] to have the largest value. Is there a reason to subtract as in ppm_values[0] - ppm_values[1] instead of ppm_values[1] - ppm_values[0] to get t0 and likewise for others?
  • Thanks for the replay Charles,

    Indeed, it should be ppm_values[1] - ppm_values[0], end of the day I guess. The actual values of the spikes are ascending, and the times between them are about the same. Here are a few examples of the ppm_values:

    37504
    225792
    224128
    225664
    225408
    224384
    225792
    224512


    32896
    1635712
    225664
    224640
    224640
    225408
    225536
    224128

    86144
    224000
    225536
    225024
    225280
    1635072
    224000
    224512

    The PPM signal consists 9 spikes and then a rest period before the next 9. I think my reading of out of sync with the actual signal (my 1th spike reading isn't actually the first spike). That would explain the larger value of >1600000. But still the values of ~220000 don't make sense, the real time between the spikes is around 1500uS, and with a HET frequency of 1MHz, each tick should be 1uS right? So I would expect values around 1500...

    Any ideas?

    Jesse

  • Well, figuered some things out. Re-wrote the interrupt function, this way the reading starts at the right time/spike:

    void   edgeNotification(hetBASE_t * hetREG,uint32 edge){
    
    	uint32 this_tick = hetGetTimestamp(hetRAM1);
    	uint32 diff = this_tick - last_tick;
    
    	if(diff > 1600000){
    		spike = 0;
    		this_tick = hetGetTimestamp(hetRAM1);
    	}
    
    	ppm_values[spike] = this_tick;
    	++spike;
    	last_tick = this_tick;
    
    	if(spike >= 9){
    		calculate_ppm();
    	}
    }
    
    
    void calculate_ppm(){
    	int i;
    	for (i = 0; i < 8; ++i) {
    		ppm_times[i] = ppm_values[i+1] - ppm_values[i];
    	}
    
    	if(ppm_times[4] < 180000){
    		gioSetBit(gioPORTB, 6, 1);
    	}else if (ppm_times[4] > 260000) {
    		gioSetBit(gioPORTB, 6, 0);
    	}
    }


    ppm_times[4] is from the 4th channel and connected to a switch on the RC controller. Because it is a switch I was able to figure out what the min and max values are: 160000 - 280000 (with 220000 in the middle).

    The only thing that is left is the frequency of the HET timer. I've changed the HET frequency back to 110MHz, but still the results are all ~220000? Shouldn't there be more pulses/ticks compared to 1MHz, in the same period of time?

  • HI Jesse,

     Are you using HalCoGen? Can you please show me how you configure the Loop Time for the HET? Please show me how you configure the timebase like the below screenshot. Below screenshot is only a default setup by the HalCoGen.

  • The only thing changed is the HR Clock:


  • Hi Jesse,

      Please refer to the timing diagram in the screenshot. There is the VCLK2, HRCLK, LRCLK. With your current setting you have configuring the HRCLK with 1.172MHz and the LRCLK loop time is only 0.853uS, not 1uS. Also with your setting you only have 1 HRCLK in 1 LRCLK. This is a very boundary setup and I'm not 100% sure you will get correct measurement.

    What I will suggest is below. Configure the HR Clock to 75MHz and the Loop Time to 1000 ns. With this setting you can get 1.706uS of timebase for the loop time. You can't get 1uS because the VCLK2 is 75MHz and the prescaler does not divide down to 1MHz for you. You can come close to 1.706uS which should still be OK for you if your PPM pulse is in the range of 1500uS. Whatever timesamp value you capture using the hetGetTimestamp() you will multiply that by 1.706uS to get the absolute delay.  

  • Alright, I will try those settings.

    Thanks for the support Charles!
  • Hi Jesse,
    I also want to remind you that the timestamp value you read out using hetGetTimestamp() will contain two fields, a loop resolution counter value and a high resolution counter value. The high resolution counter occupies the lower 7 bits of the timestamp. If you only care for the loop resolution then you will just do a right shift of 7 bits.

    Let's use your earlier example where you show in below. Let's pick the 225792 value you get. If you divide this value by 128 you get 1764 loop clocks. Since each loop clock is 0.853uS as in your original setup you will get 1764*0.853 which is about 1504uS. This is close to what you were expecting.

    37504
    225792
    224128
    225664
    225408
    224384
    225792
    224512
  • Hi Jesse,

    do you was able to read the PPM stream? Is the stream coming from a RC Receiver?

    Another Question: Any idea on how to read the Futaba S.Bus stream? There are many infos for the STM32F MCUs including source code etc, but I'm looking for a solution on the Hercules MCU.

    Regards,

    -Jarno