Show Posts
|
|
Pages: [1] 2 3 ... 10
|
|
1
|
Forum 2005-2010 (read only) / Bugs & Suggestions / Re: add ability to write to EEPROM
|
on: July 01, 2006, 12:26:57 pm
|
And... byte eeprom_rd_byte (unsigned int const * ptr) { register byte sreg, tmp; sreg = SREG; cli(); while ( EECR & (1 << EEWE )) { SREG = sreg; cli (); } EEAR = (unsigned int)ptr; EECR |= (1 << EERE); tmp = EEDR; SREG = sreg; return tmp; }
unsigned int eeprom_rd_word (unsigned int const * ptr) { unsigned int uiTmp = (unsigned int)ptr; unsigned int iRet = 0; byte bH = 0; byte bL = 0; bL = eeprom_rd_byte ((unsigned int *)uiTmp); uiTmp++; bH = eeprom_rd_byte ((unsigned int *)uiTmp); iRet = bH; iRet = iRet << 8; iRet |= bL; return iRet; }
|
|
|
|
|
2
|
Forum 2005-2010 (read only) / Bugs & Suggestions / Re: add ability to write to EEPROM
|
on: July 01, 2006, 12:24:36 pm
|
Hello, I think, ... Declaration's of eeprom_read_byte (const uint8_t *addr) look wrong with tionuint8 (BYTE) for type of addr. I have made some functions to read/write from/to eeprom. void eeprom_wr_byte (unsigned int const * ptr, byte val) { register byte sreg;
sreg = SREG; cli(); while ( EECR & (1 << EEWE )) { SREG = sreg; cli (); } EEAR = (unsigned int)ptr; EEDR = val; EECR |= ( 1 << EEMWE ); EECR |= ( 1 << EEWE ); SREG = sreg; }
void eeprom_wr_word (unsigned int const * ptr, unsigned int val) { unsigned int uiTmp = (unsigned int)ptr; byte bH = (val >> 8) & 0xFF; byte bL = val & 0xFF; eeprom_wr_byte ((unsigned int *)uiTmp, bL); uiTmp++; eeprom_wr_byte ((unsigned int *)uiTmp, bH); }
|
|
|
|
|
4
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: changing PWM frequency
|
on: July 10, 2006, 06:40:05 pm
|
Hello Zeveland, Yes, you can do it, by changing some code in the file wiring.c. Look in the main function and in files timer.c and timer.h to understand what is done. The wiring.c file is shared by all your Arduino projects, save a copy before modifications. If you don't want to modify your wiring.c file, I think you can do something like this in the Setup function of your Arduino project : #define TIMER_CLK_STOP 0x00 ///< Timer Stopped #define TIMER_CLK_DIV1 0x01 ///< Timer clocked at F_CPU #define TIMER_CLK_DIV8 0x02 ///< Timer clocked at F_CPU/8 #define TIMER_CLK_DIV64 0x03 ///< Timer clocked at F_CPU/64 #define TIMER_CLK_DIV256 0x04 ///< Timer clocked at F_CPU/256 #define TIMER_CLK_DIV1024 0x05 ///< Timer clocked at F_CPU/1024
void Setup() { [...]
TCCR1B = (TCCR1B & ~TIMER_PRESCALE_MASK) | TIMER_CLK_DIV8);
[...] }
I does not test this code ! ! ! But I think it could work. Tell me if it work. Best regards, Benoît ROUSSEAU
|
|
|
|
|
6
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Array?
|
on: July 12, 2006, 04:17:54 pm
|
Hi Will, The next code was not test or compiled, take care... it's just an example : unsigned long ASensorDelay; unsigned long BSensorDelay;
unsigned long readSensor (int sensorpin) { // Setup // -------------------------------------------------------------------
int _register = port_to_input[digital_pin_to_port[sensorpin].port]; // register is a reserve word so _ before int bit = digital_pin_to_port[sensorpin].bit; int mask = 1 << bit; unsigned long pulsewidth = 0; // Send low-high-low pulse to activate the trigger pulse of the sensor // -------------------------------------------------------------------
pinMode (sensorpin, OUTPUT); // sensorpin to output
digitalWrite (sensorpin, LOW); // Send low pulse delayMicroseconds (2); // Wait for 2 microsecond digitalWrite (sensorpin, HIGH); // Send high pulse delayMicroseconds (5); // Wait for 5 microseconds digitalWrite (sensorpin, LOW); // Holdoff
// Listening for echo pulse // -------------------------------------------------------------------
pinMode (sensorpin, INPUT); // sensorpin to input
while ((_SFR_IO8(_register) & mask) == LOW); // wait for the pulse to start
while ((_SFR_IO8(_register) & mask) == HIGH) // wait for the pulse to stop pulsewidth++;
return pulsewidth * 20UL / 23UL; }
void loop() { ASensorDelay = readSensor (aultraSoundSignal); BSensorDelay = readSensor (bultraSoundSignal);
// Writing out values to the serial port // -------------------------------------------------------------------
serialWrite('A'); printInteger(ASensorDelay); serialWrite(10); serialWrite('B'); printInteger(BSensorDelay); serialWrite(10);
// Lite up LED if any value is passed by the echo pulse // -------------------------------------------------------------------
if(ASensorDelay + BSensorDelay > 0) digitalWrite(ledPin, HIGH);
// Delay of program // -------------------------------------------------------------------
delay(100); } I have made a function to read pulse inspired by pulseIn code in wiring.c file : /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH * or LOW, the type of pulse to measure. Works on pulses from 10 microseconds * to 3 minutes in length, but must be called at least N microseconds before * the start of the pulse. */ unsigned long pulseIn(int pin, int state) { // cache the port and bit of the pin in order to speed up the // pulse width measuring loop and achieve finer resolution. calling // digitalWrite() instead yields much coarser resolution. int r = port_to_input[digitalPinToPort(pin)]; int bit = digitalPinToBit(pin); int mask = 1 << bit; unsigned long width = 0;
// compute the desired bit pattern for the port reading (e.g. set or // clear the bit corresponding to the pin being read). the !!state // ensures that the function treats any non-zero value of state as HIGH. state = (!!state) << bit;
// wait for the pulse to start while ((_SFR_IO8(r) & mask) != state) ; // wait for the pulse to stop while ((_SFR_IO8(r) & mask) == state) width++; // convert the reading to microseconds. the slower the CPU speed, the // proportionally fewer iterations of the loop will occur (e.g. a // 4 MHz clock will yield a width that is one-fourth of that read with // a 16 MHz clock). each loop was empirically determined to take // approximately 23/20 of a microsecond with a 16 MHz clock. return width * (16000000UL / F_CPU) * 20 / 23; } Something wrong with my code is that you have to have pulse (LOW->HIGH->LOW) return from each sensor to work. Without a pulse, "while" loops are infinite. If you are uncertain of sensor pulse return, you have to add a counter to check "overload" and a break to exit each while loop. But, you will have minus precision on pulse width measure. Best regards, Benoît ROUSSEAU
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Array?
|
on: July 11, 2006, 06:59:49 pm
|
Good evening Will, Ok, I think that I start to understand your problem. It's too late for me to respond ZZzzz !  But I have a question: do you have to read the two sensors simultaneously? Some 10's milliseconds between the read of the two sensors could be acceptable for your project? At the first read, - I think that an array doesn't change anything ; - your code could have some problems if B sensor take a pulse before the A sensor ; - using external interrupt could be a best solution for you ; - you can reduce your code and optimize it by replacing : int aultraSoundSignal = 6; // US 1 int bultraSoundSignal = 7; // US 2by #define aultraSoundSignal 6 #define bultraSoundSignal 7note that there no ; at the end of the line. I'll take a break tomorow to make a new post about this. Please excuse my poor english. Best regards, Benoît ROUSSEAU
|
|
|
|
|
8
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Array?
|
on: July 09, 2006, 05:19:16 am
|
Hello Will, To complete response to you : In article http://www.arduino.cc/en/Tutorial/LCD8Bits you can see something interesting for you. int DB[] = {3, 4, 5, 6, 7, 8, 9, 10}; int Enable = 2;
void LcdCommandWrite(int value) { // poll all the pins int i = 0; for (i=DB[0]; i <= DI; i++) { digitalWrite(i,value & 01); value >>= 1; } digitalWrite(Enable,LOW); delayMicroseconds(1); // send a pulse to enable digitalWrite(Enable,HIGH); delayMicroseconds(1); // pause 1 ms according to datasheet digitalWrite(Enable,LOW); delayMicroseconds(1); // pause 1 ms according to datasheet }
In particular, see int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};void LcdCommandWrite(int value)and // poll all the pins int i = 0; for (i=DB[0]; i <= DI; i++) { digitalWrite(i,value & 01); value >>= 1; }Best regards, Benoît ROUSSEAU
|
|
|
|
|
9
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Array?
|
on: July 08, 2006, 08:43:14 am
|
Hello Will, The Arduino language define digitalWrite function as : void digitalWrite(int pin, int val) { if (digitalPinToPort(pin) != NOT_A_PIN) { // If the pin that support PWM output, we need to turn it off // before doing a digital write.
if (analogOutPinToBit(pin) == 1) timer1PWMAOff();
if (analogOutPinToBit(pin) == 2) timer1PWMBOff();
if (analogOutPinToBit(pin) == 3) timer2PWMOff();
if (val == LOW) cbi(_SFR_IO8(port_to_output[digitalPinToPort(pin)]), digitalPinToBit(pin)); else sbi(_SFR_IO8(port_to_output[digitalPinToPort(pin)]), digitalPinToBit(pin)); } } So you cannot use an array in place of int type definition of the pin parameter of the digitalWrite function. But I think you can make your own definition of a new function wich can use an int array as parameter. Benoît ROUSSEAU.
|
|
|
|
|
10
|
Forum 2005-2010 (read only) / Syntax & Programs / making a library using timer.c
|
on: July 07, 2006, 06:04:35 pm
|
Hello, First, please excuse me for my poor english. I'm trying to make a clock library using timer.c.By modify wiring.c & .h I have made a clock with Arduino : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1151887411. Now, I want to do it better by writing a library to generate precise delays using interrupts (at min vector 7). This library named "TicTac", I think, could be very useful for many users and projects. HELP ! :'( First I'm try to do this : [...]
#undef PI #include "timer.h"
[...]
void TicTac::Start() {
// arrêt des fonctions PWM timer1PWMOff();
// réglage du pré-diviseur de fréquence // TCNT1 sera incrémenté tous les 1024 tics // de l'horloge du micro-controlleur timer1SetPrescaler(TIMER_CLK_DIV1024);
// liaison de l'interruption TIMER1OUTCOMPAREA_INT // avec la fonction TicTac timerAttach(TIMER1OUTCOMPAREA_INT, Bip); [...] }
The compiler respond me : lib\targets\libraries\TicTac\TicTac.o: In function `TicTac::Start()':
/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:77: undefined reference to `timer1PWMOff()'
/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:93: undefined reference to `timer1SetPrescaler(unsigned char)'
/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:98: undefined reference to `timerAttach(unsigned char, void (*)())'I think that the linker does not found the timer.o. In second time I 'm trying to do something like that : Replacing all the timer.c functions by mine's, including the ISR function. [...] ISR(SIG_OUTPUT_COMPARE1B) { [...] }
[...]
void TicTac::Start() {
// arrêt des fonctions PWM // timer1PWMOff(); // turn off timer1 PWM mode cbi(TCCR1A,PWM11); cbi(TCCR1A,PWM10); // turn off channel A (OC1A) PWM output // set OC1A (OutputCompare action) to none cbi(TCCR1A,COM1A1); cbi(TCCR1A,COM1A0); // turn off channel B (OC1B) PWM output // set OC1B (OutputCompare action) to none cbi(TCCR1A,COM1B1); cbi(TCCR1A,COM1B0); // réglage du pré-diviseur de fréquence // TCNT1 sera incrémenté tous les 1024 tics // de l'horloge du micro-controlleur // timer1SetPrescaler(TIMER_CLK_DIV1024); outb(TCCR1B, (inb(TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER_CLK_DIV1024);
// liaison de l'interruption TIMER1OUTCOMPAREA_INT // avec la fonction TicTac // timerAttach(TIMER1OUTCOMPAREA_INT, Bip);
[...] }
The compiler respond me : C:\DOCUME~1\Benoit\LOCALS~1\Temp\build28293.tmp\timer.c.o: In function `__vector_7':
E:\Arduino\arduino-0004-win\arduino-0004\lib\targets\arduino\timer.c:458: multiple definition of `__vector_7'
lib\targets\libraries\TicTac\TicTac.o:/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:54: first defined here
/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/bin/ld: Warning: size of symbol `__vector_7' changed from 148 in lib\targets\libraries\TicTac\TicTac.o to 90 in C:\DOCUME~1\Benoit\LOCALS~1\Temp\build28293.tmp\timer.c.oOk, that's right, `__vector_7' was defined in timer.c. How can I do ? Is somebody have any idea ?
|
|
|
|
|
14
|
Forum 2005-2010 (read only) / Français / Re: [APL] Voir au travers d'une souris
|
on: July 31, 2007, 02:07:58 am
|
Hi Matt, Salut Matt, Post us a picture take by your mouse when it will be done. Envoie nous une photo prise par ta souris quand ce sera fait. Don't hesitate to post your experimentations in English here, I will transalate them. N'hésite pas à poster tes expérimentations ici, je traduirai. Mon anglais est vraiment limite  ! My eglish is really poor  !
|
|
|
|
|