CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

accelerometer-LED problem, perhaps obvious

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
elmoss



Joined: 23 Nov 2008
Posts: 3

View user's profile Send private message

accelerometer-LED problem, perhaps obvious
PostPosted: Fri Nov 28, 2008 12:01 am     Reply with quote

I'm attempting to read the pulse width from a digital accelerometer, and use the values to set the duty cycles of some LEDs for color blending. Timer0 is a state machine that on sequential calls adjusts the duty cycle values and cycles the LEDs on and off. The main function measures the pulse width (fixed period of 10ms) and doesn't yet use it to assign anything. The incoming values will eventually be used to set the acc values, but for now I set those directly for testing purposes. The problem is the LEDs do not respond to changes in the acc values. Is there an obvious mistake here? I'm somewhat a newbie, so it's possible the answer is pretty basic and obvious. Anybody have any ideas? Gratefully appreciated!


Code:

#include "C:\Program Files\PICC\Projects\tiltydigital.h"

#define Yin pin_c2
#define Xin pin_c3

unsigned int timerMode, Racc, Rduty, Bacc, Bduty, Gacc, Gduty, lightcounter, durationCounter, Yval, Xval;
void waitForRise(int channel);


#int_TIMER0
void  TIMER0_isr(void)
{
   if (timerMode == 0){//change Rduty
      if (Racc>Rduty)
         Rduty++;
      else
         Rduty--;
      timerMode = 1;     
   }
   
   else if (timerMode == 1){//change Bduty
      if (Bacc>Bduty)
         Bduty++;
      else
         Bduty--;
      timerMode = 2;   
   }
   
   else if (timerMode == 2){//change Gduty
      if (Gacc>Gduty)
         Gduty++;
      else
         Gduty--;
      timerMode = 3;   
   }
   
   else if (timerMode == 3){//control R output
      if (Rduty>lightcounter)
         output_high(pin_a0);
      else
         output_low(pin_a0);
      timerMode = 4;   
   }
   
   else if (timerMode == 4){//control G output
      if (Gduty>lightcounter)
         output_high(pin_a1);
      else
         output_low(pin_a1);
      timerMode = 5;   
   }
   
   else if (timerMode == 5){//control B output
      if (Gduty>lightcounter)
         output_high(pin_a2);
      else
         output_low(pin_a2);
      timerMode = 0;
      lightcounter++;
   } 
   
}



void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
//   setup_wdt(WDT_18MS|WDT_DIV_16);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_4MHZ);

   // TODO: USER CODE!!
   timerMode = 0;
   lightcounter = 0;
   
   while(1){
      Bacc = 5;
      Racc = 5;
      Gacc = 5;
     
      durationCounter = 0;
      waitForRise(1);
      while(input(Yin)){
         durationCounter++;
         delay_us(100);
      }
      Yval = durationCounter;
     
      durationCounter = 0;
      waitForRise(2);
      while(input(Xin)){
         durationCounter++;
         delay_us(100);
      }
      Xval = durationCounter;
     
     
   }
}//main

void waitForRise(int channel){
   if (channel == 1){
      while(input(Yin));
      while(!input(Yin));
   }
   
   else if (channel == 2){
      while(input(Xin));
      while(!input(Xin));
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 28, 2008 1:55 pm     Reply with quote

Post your:

1. PIC
2. #fuses statement.
3. #use delay() statement.
4. Compiler version.
elmoss



Joined: 23 Nov 2008
Posts: 3

View user's profile Send private message

PostPosted: Fri Nov 28, 2008 2:02 pm     Reply with quote

my mistake! here's the info:

1. PIC: 16f684
2.
Code:
#include <16F684.h>
#device adc=8

#FUSES WDT                      //Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled

#use delay(clock=4000000)

4. Compiler version: 4.038
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 28, 2008 2:54 pm     Reply with quote

Quote:
#FUSES WDT

The Watchdog timer is enabled, but you're not restarting it in your code,
so the PIC will keep resetting. Change it to NOWDT.


If that doesn't fix the problem, then strip down your program so it only
uses one LED (such as the Red LED).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group