Alternating Pulse Generator Issue

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am trying to create alternating pulses on two pins of a CY8C29466 and display a count of the pulses on an LCD character display. The attached code works to some extent, but basically the pulses stop alternating between the two pins after 10 cycles. I am using a counter to generate an interrupt and throw a flag that I am checking for in the main loop. Once the interrupt flag is detected, a second flag is toggled that should alternate what pin the pulse appears on. Relevant code:

if (countFlag == TRUE)

        {

            Pin_C_Data_ADDR ^= Pin_C_MASK;

            if (turnA == 0x0)

            {

                Pin_A_Data_ADDR |= Pin_A_MASK;

                for (i = 0; i < 5000; i++);

                Pin_A_Data_ADDR &= ~Pin_A_MASK;

                turnA = 0x1;

            }

            else if (turnA == 0x1)

            {

                Pin_B_Data_ADDR |= Pin_B_MASK;

                for (j = 0; j < 5000; j++);

                Pin_B_Data_ADDR &= ~Pin_B_MASK;

                turnA = 0x0;

                count++;

                LCDUpdate = TRUE;

            }

            countFlag = FALSE;

        }

I do not understand why this isn't working after 10 cycles. Any ideas?

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The line

itoa(&countA, count, 10);

destroys your data. countA is not defined as a character array as it should be. So all data will be overwritten with the resulting string of the conversion.

Bob

View solution in original post

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The line

itoa(&countA, count, 10);

destroys your data. countA is not defined as a character array as it should be. So all data will be overwritten with the resulting string of the conversion.

Bob

0 Likes