Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / container for Objects like c++ vector? on: November 07, 2010, 12:38:11 pm
Hey All,

In the avr version of c++, is there a way to have a list container to store Objects?  Say I have and RGBLed library for controlling RGB leds declared like this:

RGBLed led1(redPin,greenPin,bluePin);

I want to have a list of these.  In regular c++ I would use a vector declared like this:

vector<RGBLed> leds;

..then I could iterate though them and select certain elements in the list, etc.

Can I do something like this with avr c++ or Arduino library?
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: timer 2 and millis() on: November 07, 2010, 12:08:48 pm
Thanks, that makes sense.  I took out that line but delay() still doesn't work correctly.  A delay(100) in my main code takes about 4 seconds. What happens if my ISR takes longer to execute than the time between overflows?
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: timer 2 and millis() on: November 07, 2010, 11:08:16 am
OK.  I've posted the ISR and related code above.  The problem seems to be with the post_frames() function in ISR.  Maybe it takes too long for the speed of the ISR?
This is a hacked version of an RGB matrix display.  I'm not sure how to calculate how much time the ISR needs to execute but I suspect this is the problem.  If I comment out post_frames() from ISR then delay() and millis() are OK.

Thanks!
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: timer 2 and millis() on: November 06, 2010, 10:17:19 pm
Yes, I have an ISR that I didn't include.  At the moment it does nothing because I'm stuck trying to figure out the millis() issue.
5  Forum 2005-2010 (read only) / Syntax & Programs / timer 2 and millis() on: November 06, 2010, 08:51:36 pm
Hi All,

I'm confused about the relationship between timer 2 and millis() in Arduino-0021.  I am trying to use timer 2 for an overflow interrupt but as soon as I enable the timer, the millis() function stops working.  I thought that millis() just used timer0... at least this is what it looks like from reading wiring.c
I am using an Atmega 328p.
The code is below.  Any advice is greatly appreciated.


Code:
/* First disable the timer overflow interrupt while we're configuring */
      TIMSK2 &= ~(1<<TOIE2);

      /* Configure timer2 in normal mode (pure counting, no PWM etc.) */
      TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
      TCCR2B &= ~(1<<WGM22);

      /* Select clock source: internal I/O clock */
      ASSR &= ~(1<<AS2);
      
      /* Disable Compare Match A interrupt enable (only want overflow) */
      TIMSK2 &= ~(1<<OCIE2A);

      /* Now configure the prescaler to none */
      TCCR2B |=  (1<<CS20); // Set bit
      TCCR2B &= ~(1<<CS21); // Clear bit
      TCCR2B &= ~(1<<CS22); // Clear bit

      /* Finally load end enable the timer */
      TIMSK2 |= (1<<TOIE2);

ISR(TIMER2_OVF_vect) {
      /* Reload the timer */
      TCNT2 = 255;
      digitalWrite(8, toggle == 0 ? HIGH : LOW); //test output
      toggle = ~toggle; //test output
      timer_clicks = (timer_clicks + 1) & 0x1F; //circular to 32
      post_frames();
}


void post_frames(void)
{
      for(char row = 0 ; row < 8; row++)shift_out_line(row);      //Send all 8 rows of colors to the Matrix
}

void shift_out_line(volatile uint8_t row_num)
{
      cbi(PORTC, LATCH);      //Disable the shift registers

      //Send Red Values
      for(uint8_t LED = row_num*8 ; LED < (row_num*8)+8 ; LED++) //Step through bits
      {
            cbi(PORTC, CLK);      //Lower the shift register clock so we can configure the data

            //Compare the current color value to timer_clicks to Pulse Width Modulate the LED to create the designated brightness
            if(timer_clicks < red_frame[LED])
                  sbi(PORTC, DATA);
            else
                  cbi(PORTC, DATA);

            sbi(PORTC, CLK);      //Raise the shift register clock to lock in the data
      }
      //Send Blue Values
      for(uint8_t LED = row_num*8 ; LED < (row_num*8)+8 ; LED++) //Step through bits
      {
            cbi(PORTC, CLK);      //Lower the shift register clock so we can configure the data

            //Compare the current color value to timer_clicks to Pulse Width Modulate the LED to create the designated brightness
            if(timer_clicks < blue_frame[LED])
                  sbi(PORTC, DATA);
            else
                  cbi(PORTC, DATA);

            sbi(PORTC, CLK);      //Raise the shift register clock to lock in the data
      }
      //Send Green Values
      for(uint8_t i = row_num*8 ; i < (row_num*8)+8 ; i++) //Step through bits
      {
            cbi(PORTC, CLK);      //Lower the shift register clock so we can configure the data

            //Compare the current color value to timer_clicks to Pulse Width Modulate the LED to create the designated brightness
            if(timer_clicks < green_frame[i])
                  sbi(PORTC, DATA);
            else
                  cbi(PORTC, DATA);

            sbi(PORTC, CLK);      //Raise the shift register clock to lock in the data
      }

      sbi(PORTC, EN);            //Disable the Shift Register Outputs
      sbi(PORTC, LATCH);      //Put the new data onto the outputs of the shift register

      PORTD = (1<<row_num); //Sink current through row (Turns colors 'ON' for the given row. Keep in mind that we can only display to 1 row at a time.)

      cbi(PORTC, EN);            //Enable the Shift Register Outputs
}
      

The last line of this breaks millis().  What is going on?

Thanks!
6  Forum 2005-2010 (read only) / Troubleshooting / arduino library with eclipse on: September 21, 2009, 05:00:06 pm
Hey All,

I want to use eclipse and the arduino libraries to program some atmega168 chips without any arduino hardware.  I just want to make use of the wicked arduino libraries. I have gone through the tutorial here:
http://www.arduino.cc/playground/Code/Eclipse
and everything seems to be working fine.  I'm using the stk500 as a programmer.  I have successfully compiled and programmed a chip with a simple blink program.  The problem is now I want to use other parts of the library (hardware serial) but I just get errors that seem to be related to not having the libraries setup correctly.
If I try "Serial.begin(19200);"  I get:
error: 'Serial' undeclared (first use in this function)

Any advice about how to get these libraries working with Eclipse would be greatly appreciated.

Thanks!
7  Forum 2005-2010 (read only) / Troubleshooting / powering Mega with 5 volts on: July 02, 2010, 08:17:37 pm
Hey All,

I need to power my Mega board with an external 5 volt power supply:
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=237-1306-ND

What is the best way to bypass the on-board regulator?  I've heard talk of going in through the USB jack but I would rather not use a USB cable...
Thanks in advance,
Francis
8  Forum 2005-2010 (read only) / Troubleshooting / Re: Arduino Mega, Serial.begin crashes? on: June 02, 2010, 02:59:01 pm
I found another post that talks about this issue... iam using Linux and had to downgrade my avr-gcc and avr-gcc-g++ (both to version 4.3.3)
It works now.
Thanks.
9  Forum 2005-2010 (read only) / Troubleshooting / Arduino Mega, Serial.begin crashes? on: June 02, 2010, 02:00:15 pm
Hey All,

I just got an Arduino Mega.  It seems to work OK except when i try to use serial communication.  I'm just trying to get the mega to send some serial info. to my computer via the following sketch, but it does nothing... the LED doesn't blink and I get nothing in the serial monitor.  If I comment out the two serial lines then the sketch seems to run ok.

Any help is greatly appreciated

Code:
int ledPin = 13;
void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop()
{

 Serial.println("Test");
 digitalWrite(ledPin,HIGH);
 delay(1000);
 digitalWrite(ledPin,LOW);
 delay(1000);
}
10  Forum 2005-2010 (read only) / Interfacing / Re: Driving Power N-Channel Mosfet, voltage drop :( on: July 14, 2010, 08:40:13 am
Thanks folks.  I'm finding now that I am getting no voltage drop with just the meter.  However, my load is a piece of muscle wire connected between +5V and Fet drain with two long pieces of 28AWG test lead wire.  When the Fet is activated, the voltage across the drain and +5V supply is 4.35V.  I'd like to get rid of this drop so the muscle wire works better.  Any suggestions?  I'll try replacing the 28AWG wire with thicker...

11  Forum 2005-2010 (read only) / Interfacing / Driving Power N-Channel Mosfet, voltage drop :( on: July 13, 2010, 10:24:26 pm
Hey All,

I'm using an Arduino Mega to drive this MOSFET:http://search.digikey.com/scripts/DkSearch/dksus.dll?lang=en&site=CA&WT.z_homepage_link=hp_go_button&KeyWords=IPP100N06S3L-04IN-ND&x=0&y=0
The Fet's gate is connected directly to a digital IO pin on the Mega.  From looking at the datasheet, there should be no problem driving this Fet from logic-level pin.  However, with the Fet's source connected to ground and the IO pin HIGH, I can never get a 5V reading between the +5v supply and the Fet's drain (no other load attached).  There is always a voltage drop to around 4.5 volts.  Any ideas why this is?  I want this Fet to act lik a switch and turn fully on.
Any help is greatly appreciated.
12  Forum 2005-2010 (read only) / Interfacing / change serial buffer size or make it LIFO on: May 26, 2010, 05:18:32 pm
Hey All,

I'm using two arduinos with xbee point-to-point wireless serial communication.  arduinoA is constantly sending data.  arduinoB reads a byte, does some work, then reads another byte.  The problem is that communication is too slow.  I want arduinoB to immediately get the most recent byte sent on its first Serial.read() after returning from work.  I think what is happening right now is that arduinoB has to read thgouh the entire 128 byte buffer before getting the "curent" byte.  I don't care about loosing data (don't care about what data was transmitted while arduinoB was working), I just want to instantly get whatever byte arduinoA is sending.  Is there a way to do this?
I thought mayby there was a way to make the serial buffer only 1 byte in size, or to make it LIFO instead of FIFO.

Any help is greatly appreciated

Francis
13  Forum 2005-2010 (read only) / Interfacing / Re: RGB LED PWM Matrix flickers on: April 01, 2009, 10:50:12 am
I'm using a 6x6 matrix and I get flickering if my delay is any longer than 1000 microseconds.  Also, if I use delayMicroseconds(1000) there is no flickering but if I use delay(1) they flicker like crazy.... aren't those two instructions supposed to do the ssame thing?
14  Forum 2005-2010 (read only) / Interfacing / Re: RGB LED PWM Matrix flickers on: March 31, 2009, 10:26:46 pm
Grumpy, i'll try the capacitor solution.  How would I synchronize the refresh of the matrix to the PWM frequency?  Can I alter the PWM frequency without changing the duty cycle and vise versa.  
I am using RGB LEDS, they are each 3 LEDS in one package with a common cathod.  I need the PWM for colour mixing.
15  Forum 2005-2010 (read only) / Interfacing / RGB LED PWM Matrix flickers on: March 30, 2009, 04:38:35 pm
Hey All,

I have been experimenting with with some some RGB leds in a matrix circuit.  I want to use pulse width modulation to control the brightness of each colour but I am getting a lot of flickering in the light.  I have a loop to test the circuit.  If I don't use PWM, all the leds light up as expected and there is no flickering:

for (int c = 0; c < columns; c++){
      for(int r = 0; r < rows; r++) {
          //turn an LED on
          digitalWrite(row_pins[r],LOW);
          digitalWrite(col_pins[c],HIGH);
          delayMicroseconds(100);
    
          //turn the LED off
          digitalWrite(col_pins[c],LOW);
          digitalWrite(row_pins[r],HIGH);              
      }
  }

But if I try to use PWM to achieve the same effect I get a lot of flickering in the leds:

for (int c = 0; c < columns; c++){
      for(int r = 0; r < rows; r++) {
          //turn an LED on
          digitalWrite(row_pins[r],LOW);
          analogWrite(col_pins[c],255);
          delayMicroseconds(100);
    
          //turn the LED off
          analogWrite(col_pins[c],0);
          digitalWrite(row_pins[r],HIGH);              
      }
  }

Does anyone know how to solve this so that I can use a PWM pulse to turn the columns lines on without flickering leds?

Thanks!
Pages: [1] 2