ServiceDesk

 View Only

Problem with PWM chan2 on BCM2835 Chip

  • 1.  Problem with PWM chan2 on BCM2835 Chip

    Posted Apr 25, 2023 09:25 AM

    Hi. I have problem with BCM2835 processor on Raspberry Pi 2B single board computer. Namely which is PWM chan2.

    I use PWM chan1 in serialise mode. Data is sent via PWM FIFO. While channel 1 works smoothly, channel 2 does not work. I need help. Short code for PWM channel1:

    if(channel & PWM0)

    {

            for(pos = 0; pos <= (length) && BIT_IS_CLR(PWM_STA_FIFO_FULL, *pwm_statep); pos++) //fill empty FIFO till full

                    {

                   

                            *pwm_fifop = data[pos];

                    }

    *(pwm + PWM_CTL) |= PWM0_ENABLE ; //enable PWM0

            for(; pos <= (length ); pos++) //move next data to FIFO

            {

                    while(BIT_IS_SET(PWM_STA_FIFO_FULL, *pwm_statep)) //Wait for free place in FIFO

                    {

                                    delayMicroseconds(20);

                    }

                    *pwm_fifop = data[pos];

            }

            if BIT_IS_SET(PWM_STA_GAP0, *pwm_statep) //Check for GAP in STA

            {

                    gapCounter++;

            }

            if BIT_IS_SET(PWM_STA_BERR, *pwm_statep)// Check for BUS Error in STA

            {

                    berrCounter++;

            }

            while( BIT_IS_SET(PWM_STA_FIFO_EMPT, *pwm_statep)) // wait for channel works to the end

                    {

                            delayMicroseconds(380);

                                                           

                    }

                   

                 *(pwm + PWM_CTL) &= ~ PWM0_ENABLE; //desable PWM0

    Short code for PWM channel1:

    else if(channel & PWM1)

             {

                           

                                   

            for(pos = 0; pos <= (length) && BIT_IS_CLR(PWM_STA_FIFO_FULL, *pwm_statep); pos++)//check if FIFO not full

                   

                    {

                   

                            *pwm_fifop = data[pos]; //fill FIFO with data

                    }

     

            *(pwm + PWM_CTL) |= PWM1_MS_MODE|PWM1_USEFIFO | PWM1_SERIAL|PWM1_ENABLE ;

                                   

                    for(; pos <= (length ); pos++) //move next data to FIFO

            {

                    while(BIT_IS_SET(PWM_STA_FIFO_FULL, *pwm_statep)) //Wait for free place in FIFO

                    {

                                    delayMicroseconds(20);  //here endless loop waits for bit PWM_STA_FIFO_FULL go low

                    }

                    *pwm_fifop = data[pos]; //fill free place with next Data

            }

                    if BIT_IS_SET(PWM_STA_GAP1, *pwm_statep)

                    {

                            gapCounter++;

                    }

                    if BIT_IS_SET(PWM_STA_BERR, *pwm_statep)

                    {

                            berrCounter++;

                    }

                    while(BIT_IS_SET (PWM_STA_FIFO_EMPT, *pwm_statep)) // wait for fifo empty

                    {

                            delayMicroseconds(380);                                                        

                    }

                   

    *(pwm + PWM_CTL) &= ~ PWM1_ENABLE; //disable PWM chanel2

     

            }

           

            delayMicroseconds(10);

            *pwm_statep = 0x1FFF;

           

            return pos;

    }