0

I'm working on a C Project for University where I need to measure a Laser with a TCD1304 CCD-Sensor. Therefore I am using Zephyr as OS on an STM32-H7(A3ZI-Q). Since the TCD1304 has to receive different PWM signals to drive it, I am trying to generate PWMS with Zephyr. So far I have already reached the point where I can generate two PWMs using Timer1 and Timer4. It should be mentioned that one frequency is 2MHz and the other one is 500kHz, which are multiples of each other.

The different frequencies can be adjusted well, but I can always detect a drift of the two signals to each other. I have to fix this drift by synchronizing the PWMs of the two timers. Otherwise it won't be possible to drive the TCD1304.

Here I provide an overview of the used code:

prj.conf

CONFIG_PWM=y
CONFIG_SYS_CLOCK_TICKS_PER_SEC=100

main.c


#define FM_PERIOD 2000000U
#define SH_PERIOD 500000U

void main(){
    /* Initialize and start PWM Signals */
    const struct device *fM_device = device_get_binding("FM");
    const struct device *SH_device = device_get_binding("SH");

    if (!fM_device | !SH_device){
        printk("TCM1304 - PWM initialize failed.");
        return;
    }
    pwm_set(fM_device, 1, FM_PERIOD, 0.5*FM_PERIOD, 0);
    pwm_set(SH_device, 4, SH_PERIOD, 0.5*SH_PERIOD, 0);
}

nucleo_h7a3zi_q.overlay

...
&timers1 {
    st,prescaler = <10>;
    status = "okay";
    
    pwm1: pwm {
        status = "okay";
        label = "FM";
        pinctrl-names = "default";
        pinctrl-0 = <&tim1_ch1_pe9>;
    };
};

&timers4 {
    st,prescaler = <100>;
    status = "okay";

    pwm3: pwm {
        status = "okay";
        label = "SH";
        pinctrl-names = "default";
        pinctrl-0 = <&tim4_ch4_pd15>;
    };
};
...

When generating the two signals by the same timer with different frequencies, I noticed that some periods are cut off at the 2MHz signal. From this I conclude that different frequencies cannot be created by the same timer?

I assume that this is a common problem for which there must be a solution. Maybe by assigning the same input clocks to the Timers in the overlay-file (clocks=<XX>-Option) or by using any kind of master-slave principle within Zephyr (Github-Issue). It seams that my issue is closely related to this Issue, but within Zephyr.

Is there a solution that avoids interrupts in the best possible way to reduce CPU load? I would be very glad to get some help.

Omegon
  • 11
  • 2

0 Answers0