Show Posts
Pages: [1] 2 3 ... 13
1  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Interupts on: December 19, 2006, 10:56:54 am
Schweet! I can do some tests if you want smiley It'll be BootCamp, but that should do, no?

Thanks Mellis!
2  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Interupts on: December 16, 2006, 05:18:50 am
I would very much like to do too and I'm now sure I want to fool around the wiring libraries to extract these features.
While were at it, the math functions could be nice too!
3  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: maximum delay() is 32767ms ? on: February 15, 2008, 02:03:32 pm
Wouldn't casting work fine? delay((uint16_t) 60 * 1000); ?

My 2 cents...
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Programming Arduino in plain C or C++ on: February 12, 2008, 04:04:51 pm
(Sorry for the double post)

Quote
Yes, the program will use functions like pinMode, digitalWrite, digitalRead to interface with multiple Arduinos, collecting data, processing it and then sending data. I'm planning to use one thread per board...

I'm still not sure I got this... Which program? The one that runs on the host machine? If so, that's not possible. What you're compiling is AVR object code. It will not run on a PC (x86) and talk to the parallel/serial port...
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Programming Arduino in plain C or C++ on: February 12, 2008, 04:01:49 pm
Quote
Anyway, I want to thank you. That Makefile was really useful. I now understand how it all works. smiley-wink

Pretty much the only thing it doesn't do that the IDE does is auto prototypes, "hot linking" of libraries and burning the bootloader (but there's already a makefile for that). So yeah, use at will!
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: Programming Arduino in plain C or C++ on: February 12, 2008, 01:29:36 pm
Quote
If you want to run multi-threaded code ON the arduino, then you're in trouble.

Actually there are one or two OS project for the AVR which supports multithreading. But that's out of the scope of this forum.

AVRx
http://picoos.sourceforge.net/features.html
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Programming Arduino in plain C or C++ on: February 12, 2008, 02:14:20 am
Quote
Are you wanting to write code to run on the Arduino board or on a "host" Windows/Mac OS X/Linux PC?

I have to say, I did ask myself the same question...
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Programming Arduino in plain C or C++ on: February 11, 2008, 02:31:32 pm
There is a makefile available somewhere on the site. It's a bit old and hasn't been updated for version 0010 of the API, but it's easy to port... as a matter of fact... here's mine (it may have some extras left in there) http://pastie.textmate.org/private/fl1fwwsqqfqm4tl2mmwsyw. It works nicely with 0010. I never use the IDE anymore, it's terrible when you're used to great stuff like TextMate (shameless plug). You'll have to edit the path to the Arduino directory and add any libraries you use manually (there are examples for TWI and OneWire). Also note that if you're not going to use the bootloader and use a ISP programmer you will need to remove the "-F" argument of the Avrdude flags or you're very possibly fry your chip. (-F is needed if you use the bootloader and upload your sketch using serial/usb). Enjoy! Hope this helps

EDIT: oh yeah if you're under windows, you could try integrating the API with AVR Studio, at that point you'd have a powerful API, IDE and Debugger...

EDIT 2: Oh yeah just as side note, when you use the IDE, you're still using "straight" C/C++.
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Issue with PWM and delay() on: December 18, 2007, 01:19:07 pm
Ok apparent I'm a moron...

Code:
for (rearLightIncrement=255;rearLightIncrement>=0;rearLightIncrement--)
      {
            analogWrite(pinRearLight, rearLightIncrement);
            delay(10);
      }

since I had >=0 when it go to zero is seems like it tried to take one away again and that messed up the whole thing!
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Issue with PWM and delay() on: December 18, 2007, 12:52:09 pm
I've just tested it and I get the same behavior on the Arduino board (using both 0009 and 0010!) :S

EDIT: Ok serial also seems to stop working when I start the PWM!!!
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Issue with PWM and delay() on: December 17, 2007, 02:13:02 pm
main.pde

Code:
#include <avr/eeprom.h>
#include <avr/wdt.h>

#include "main.h"

/**
      todo: display battery status
**/

void rearLightOff(void)
{
      digitalWrite(pinRearLight, HIGH);
}

void rearLightOn(void)
{
      analogWrite(pinRearLight, dimLevelDefault);
}

void changeBreakStatus(void)
{
      breakStatus != breakStatus;
      
      if (breakStatus) {
            rearLightOn();
      } else {
            rearBlinkPhase            = 0;
      }
      
      return;
}

void setFrontLight(void)
{
      // Set the front led output
      if (frontHighState) analogWrite(pinFrontLight, frontDimLevel);
      // Set front led output in low state
      else analogWrite(pinFrontLight, (uint8_t) (dimLevel0 - (dimLevel0 - frontDimLevel) * dimLevelLow));
      
      return;
}

void changeFrontHighStatus(void)
{
      frontHighState != frontHighState;
      
      setFrontLight();
      
      return;
}

void readDimLevel(void)
{
      uint8_t eepromValue = 0;
      
      // Wait for the eeprom to be ready
      while (!eeprom_is_ready());
      
      eepromValue = eeprom_read_byte(0);
      
      frontDimLevel      = eepromValue;
      
      return;
}

void writeDimLevel(void)
{      
      // Wait for the eeprom to be ready
      while (!eeprom_is_ready());
      
      eeprom_write_byte(0, frontDimLevel);
      
      return;
}

void setup(void)
{
      
      // Set pin modes
      pinMode(pinRearLight, OUTPUT);
      pinMode(pinFrontLight, OUTPUT);
      pinMode(pinSettingBtn, INPUT);
      
      // Attach external interrupts
      attachInterrupt(0, changeBreakStatus, CHANGE);
      attachInterrupt(1, changeFrontHighStatus, CHANGE);
      
      // Read the previous dim level
      readDimLevel();
      
      // Set the front light on
      setFrontLight();
      
      // Enable watchdog
//       wdt_reset();
// #ifdef WDTO_4S
//       wdt_enable(WDTO_4S);
// #else
//       wdt_enable(WDTO_2S);
// #endif
}

void loop(void)
{
      /**
       * START settings routine
      **/
      /*
      settingBtnVal = digitalRead(pinSettingBtn);
      
      if (bounceTime == -1 && settingBtnVal == HIGH) {
            bounceTime = 0;
      }

      if (settingBtnVal == LOW && settingBtnLastVal == LOW) {
            bounceTime++;
            if (bounceTime >= bounceInterval) {
                  bounceTime = -1;
                  settingBtnVal = HIGH;
            }
      }
      
      if (settingBtnVal == HIGH && settingBtnLastVal == LOW) {
            settingBtnLastVal = HIGH;
            settingBtnPhase++;
            previousMillisSettingBtn = millis();
      }
      
      if (settingBtnVal == LOW && settingBtnLastVal == HIGH && bounceTime != -1) {
            settingBtnLastVal = LOW;
      }
      
      if (millis() - previousMillisSettingBtn < 1000 && settingBtnPhase >= 0)
      {
            if (settingBtnPhase == 0)
            {
                  frontDimLevel = dimLevel4;
            }
            
            if (settingBtnPhase == 1)
            {
                  frontDimLevel = dimLevel3;
            }
            
            if (settingBtnPhase == 2)
            {
                  frontDimLevel = dimLevel2;
            }
            
            if (settingBtnPhase == 3)
            {
                  frontDimLevel = dimLevel1;
            }
            
            if (settingBtnPhase == 4)
            {
                  frontDimLevel = dimLevel0;
            }
            
            if (settingBtnPhase == 5)
            {
                  settingBtnPhase = -1;
            } else {
                  writeDimLevel();
                  setFrontLight();
            }
      } else {
            settingBtnPhase = -1;
      }
      */
      // END settings

      // Throbbing back led routine
      if (!breakStatus && settingBtnPhase == -1) {
            if (rearBlinkPhase == 0)
            {
                  for (readLightIncrement=255;readLightIncrement>=0;readLightIncrement--)
                  {
                        analogWrite(pinRearLight, readLightIncrement);
                        delay(1);
                  }
                  
                  rearLightOn();
                  
                  previousMillis = millis();
            
                  rearBlinkPhase++;
            }
            else if (rearBlinkPhase == 1) {
                  if (millis() - previousMillis > 5000)
                  {
                        rearBlinkPhase++;
                  }
            }
            else if (rearBlinkPhase == 2) {
                  for (readLightIncrement=0;readLightIncrement<256;readLightIncrement++)
                  {
                        analogWrite(pinRearLight, readLightIncrement);
                        delay(2);
                  }
                  
                  rearLightOff();
                  
                  previousMillis = millis();
            
                  rearBlinkPhase++;
            }
            else if (rearBlinkPhase == 3){
                  if (millis() - previousMillis > 5000)
                  {
                        rearBlinkPhase = 0;
                  }
            }
      }

      // Reset the watchdog timer
      //wdt_reset();
}
12  Forum 2005-2010 (read only) / Syntax & Programs / Issue with PWM and delay() on: December 17, 2007, 02:10:35 pm
Hello, I'm writing this simple PWM led controller program and it looks like whenever I start using analogWrite(), the delay() function stops working. I'm using a breaboard version of the arduino with the internal osc. set at 8Mhz (with no divider) with a makefile (both CPU_FREQ and F_CPU are set at 8000000 using -D). Fuses are set as such: L:0xE2, H:0xDD, E:0xFF (0x07 for  avrdude not to mess up).

I really don't get it Ô.o

Any ideas?

Here's the code
main.h
Code:
#ifndef _MAIN_H_
#define _MAIN_H_
      
      /**
       * Pin definitions
      **/
      #define pinRearLight            9
      #define pinFrontLight            10
      #define pinSettingBtn            8
      
      /**
       * Dim level definitions
      **/
      #define dimLevel0                  255
      #define dimLevel1                  190
      #define dimLevel2                  125
      #define dimLevel3                  63
      #define dimLevel4                  0
      #define dimLevelDefault            dimLevel1
      
      // High/low ratio
      #define dimLevelLow                  0.66
      
      // Setting button debounce interval
      #define bounceInterval            50
      
      /**
       * Variable declarations
      **/
      uint16_t previousMillis, previousMillisSettingBtn;
      uint8_t rearLightInterval, rearLightValue, readLightIncrement;
      
      boolean settingBtnVal            = false;
      boolean settingBtnLastVal      = false;
      int8_t bounceTime                  = 0;
      int8_t settingBtnPhase            = -1;
      
      boolean breakStatus                  = false;
      uint8_t rearBlinkPhase            = 0;
      
      boolean frontHighState            = false;
      uint8_t frontDimLevel            = 0;
      
      /**
       * Prototypes
      **/
      void rearLightOff(void);
      void rearLightOn(void);
      void writeDimLevel(void);
      void readDimLevel(void);
      void changeFrontHighStatus(void);
      void setFrontLight(void);
      void changeBreakStatus(void);
      
#endif /* End of Main.h */

main.pde to follow
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: Source code? on: October 15, 2007, 10:31:14 am
everything is in ARDUINO/lib/targets
14  Forum 2005-2010 (read only) / Syntax & Programs / Using simulavr and avr-gdb with the Arduino on: August 27, 2007, 08:33:34 pm
Hi, so doing that NTSC thing an not having a soft reset Diecimila I realized it would be great to be able to test code without using the Arduino (it was far away when I needed to reset it). I had installed OSX-AVR anyway to use the USBTiny so simulavr came with it (why is it not in the Macports?). I modified the Makefile (0007) to generate a .bin to load up in simulavr and got simulavr-disp loaded in X11 (pretty darn sweet if you ask me!). Now I connected using gdb... but I'm not really sure what to do from there on. Any one has pointers here? All I'm looking for something like setting break points and stepping through. I know this is a little out of the scope of the Arduino project, but since some of you guys know uC's very well I figured I might ask here.
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: duration of signal on: August 26, 2007, 11:38:03 am
From http://www.arduino.cc/playground/Learning/PortManipulation:

Quote
If you look at the source code in lib/targets/arduino/wiring.c, you will see that digitalRead() and digitalWrite() are each about a dozen or so lines of code, which get compiled into quite a few machine instructions. Each machine instruction requires one clock cycle at 16MHz, which can add up in time-sensitive applications. Direct port access can do the same job in a lot fewer clock cycles.

I suggest you take a look at the article for more information on the subject. But basically you will need to use the port registers if you want to achieve 1 instruction per cycle.
Pages: [1] 2 3 ... 13