Waveform generation issue with Client project to control NeoPixels

I generate a waveform to control NeoPixels with success into a simple peripheral project like "Blinky". When I try to do the same into Blinky Client project I got some random delay even by commenting stack initialization.

GOOD SIGNAL:

WRONG SIGNAL:

int main(void)
{
    neopixel_strip_t m_strip;
    volatile uint8_t dig_pin_num = NRF_GPIO_PIN_MAP(0,21);
    volatile uint8_t leds_per_strip = 12;
    volatile uint8_t error;
    volatile uint8_t led_to_enable = 0;
    volatile uint8_t red = 28;
    volatile uint8_t green = 0;
    volatile uint8_t blue = 28;

    NRF_P0->PIN_CNF[21] =  ((uint32_t)GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos)
                         | ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
                         | ((uint32_t)GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
                         | ((uint32_t)GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
                         | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos);

    neopixel_init(&m_strip, dig_pin_num, leds_per_strip);
    neopixel_show(&m_strip);

	// Enter main loop.
    while(1)
    {

    }
}

//These defines are timed specific to a series of if statements and will need to be changed
//to compensate for different writing algorithms than the one in neopixel.c
#define NEOPIXEL_SEND_ONE	NRF_P0->OUTSET = (uint32_t)(GPIO_OUTSET_PIN21_High << GPIO_OUTSET_PIN21_Pos); \
		__ASM ( \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
			); \
		NRF_P0->OUTCLR = (uint32_t)(GPIO_OUTCLR_PIN21_High << GPIO_OUTCLR_PIN21_Pos); \
                __ASM (  \
				" NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
			);
#define NEOPIXEL_SEND_ZERO NRF_P0->OUTSET = (uint32_t)(1UL << GPIO_OUTSET_PIN21_Pos); \
		__ASM (  \
				" NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
                                " NOP\n\t"  \
			);  \
		NRF_P0->OUTCLR = (uint32_t)(1UL << GPIO_OUTCLR_PIN21_Pos);  \
		__ASM ( \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
				" NOP\n\t" \
                " NOP\n\t" \
				" NOP\n\t" \
			);

void neopixel_show(neopixel_strip_t *strip)
{
	const uint8_t PIN =  strip->pin_num;
        NRF_P0->OUTCLR = (uint32_t)(1UL << GPIO_OUTCLR_PIN21_Pos);
        //NRF_P0->OUTSET = (uint32_t)(1UL << GPIO_OUTSET_PIN23_Pos);
//	NRF_GPIO->OUTSET = (1UL << PIN);
	nrf_delay_us(50);
			for (int i = 0; i < strip->num_leds; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					if ((strip->leds[i].grb[j] & 128) > 0){
                                          NEOPIXEL_SEND_ONE
                                        }
					else{
                                          NEOPIXEL_SEND_ZERO
                                        }
					
					if ((strip->leds[i].grb[j] & 64) > 0)	{NEOPIXEL_SEND_ONE}
					else	{NEOPIXEL_SEND_ZERO}
					
					if ((strip->leds[i].grb[j] & 32) > 0)	{NEOPIXEL_SEND_ONE}
					else	{NEOPIXEL_SEND_ZERO}
					
					if ((strip->leds[i].grb[j] & 16) > 0)	{NEOPIXEL_SEND_ONE}
					else	{NEOPIXEL_SEND_ZERO}
					
					if ((strip->leds[i].grb[j] & 8) > 0)	{NEOPIXEL_SEND_ONE}
					else	{NEOPIXEL_SEND_ZERO}
					
					if ((strip->leds[i].grb[j] & 4) > 0)	{NEOPIXEL_SEND_ONE}
					else	{NEOPIXEL_SEND_ZERO}
					
					if ((strip->leds[i].grb[j] & 2) > 0)	{NEOPIXEL_SEND_ONE}
					else	{NEOPIXEL_SEND_ZERO}
					
					if ((strip->leds[i].grb[j] & 1) > 0)	{NEOPIXEL_SEND_ONE}
					else	{NEOPIXEL_SEND_ZERO}
				}
			}
}

Do you know where this instability comes from ?

Parents Reply Children
No Data
Related