Invisible Problem

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

Invisible Problem

Postby SLTom992 » Wed Aug 06, 2014 12:49 am

I backed up my working program a couple of days ago and ended up overwriting it with an older backup.

So I've spent the last couple of day redoing all of my code and finally it's working except for one function. This is an LED light blinking function. The LED's can be blinked at different rates to means different things and they can also be blinked very rapidly so that we conserve power.

The function operates the first LED properly. And external function sets the mode for each LED and that operates properly. The time counter counts down each counter correctly. But it only enters the "if" statements to turn the LEDs on or off for the initial "0" LED.

I am testing it by running it in Debug mode on an ICD3 and stopping it in various locations and observing the variables. It all appears to me to be properly programmed but it isn't working.

This has to be something staring me in the face but I can't see it.

Code: Select all

void blink_light() {

    char i, k;                         // Normal counter variable

        // mode indicates that LED is running, and whether it is
        // in the on mode or off mode (0 = not running, 1 = on 2 = off)

        // time is the amount of "on" or "off" time

        // "led_on" or "led_off" contain the reloads for time.
    for (i = 0; i < 5; i++) {
        k = 0x02;
        if (led_mode[i] > 0 && led_time[i] > 0) {       // if active count down
            led_time[i]--;
            if ((led_time[i] == 0) && (led_mode[i] > 0)) {      // if timeout, action
                if (led_mode[i] == LED_OFF) {
                    led_time[i] = led_on[i];               // insert next time
                    led_mode[i] = LED_ON;
                    LATB |= (k << i);                      // LED off
                }
                else {
                    led_time[i] = led_off[i];
                    led_mode[i] = LED_OFF;
                    LATB &= ~(k << i);
                }
            }
        }
    }
}
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: Invisible Problem

Postby ric » Wed Aug 06, 2014 1:32 am

What are the values defined for LED_OFF and LED_ON?
It would be best to show the definitions for your arrays also.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Invisible Problem

Postby drh » Wed Aug 06, 2014 2:46 pm

Are the pins driving the LEDS configured as outputs?
User avatar
drh
Verified identity
 
Posts: 61
Joined: Tue May 27, 2014 3:31 pm
Location: Hemet, Calif.
PIC experience: Professional 5+ years with MCHP products


Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 9 guests

cron