Show Posts
Pages: 1 [2] 3
16  Using Arduino / Programming Questions / math with float not working on: October 20, 2011, 01:21:22 pm
This code was working, but now all I get is 0.00 for temperature  smiley-confuse and I am confused about what happened
 
For these two routines, output is:
x2: 296.78, ReadTemperatureCal: 0.00°C
x3: 0.00  <<---- why is this zero? should be 23.63°C

Code:
//---------------------------------------------------------
float ReadTemperatureCal(void) {
  // reads calibration factor from EEPROM; float max. -10.0 - +10.0 degree offset range
  float Cal;
   Cal= EEPROMreadFloat(CAL_EEADDR); // read cal factor
   if ((Cal > 10.0) || (Cal < -10.0)) { // if garbage in fresh EEPROM
     Cal=0.0; //set to zero
     EEPROMwriteFloat(CAL_EEADDR, Cal); // save it;
     Serial.println("Reset Cal Factor to 0.0");
   }     
   Serial.print("ReadTemperatureCal: ");  Serial.print(Cal,2); Serial.print(0xB0,BYTE); Serial.println("C");
   return Cal;
}
//-----------------------------------------------------------
double Thermistor(int RawADC) {
 
  double Temp;
  // The coefficients below for 10K @ 25C thermistor from Radio Shack 271-110   
  //----------------------------------------------------------------
  Temp = log(((30720000/RawADC) - 30000)); //30k pulldown
  // S-H coefficients
  Temp = 1 / (0.00090145879873 + (0.00024921185913 * Temp) + (0.00000020123928 * Temp * Temp * Temp));
    Serial.print("x2: ");   Serial.print(Temp,2); Serial.print(", ");
  Temp = Temp - 273.15 - ReadTemperatureCal();         // Convert Kelvin to Celcius
    Serial.print("x3: ");   Serial.println(Temp,2);
  return Temp;
}
//-----------------------------------------------------------
17  Using Arduino / Project Guidance / Re: What is Mega 2560 power source preference on: October 06, 2011, 10:46:48 am
I need to disable the USB power on my Mega2560. The 8U2 prob. needs to see it which means disabling the comparator/USBVCC switch circuit.

My project has an on-off switch for external Vin and I don't want a sequence (turn on Vin, then plug in USB) to power things up, since 5V load is more than USB can provide.

I pulled the mosfet T2 (SOT-23) and it seems to work. A solder pad jumper would be nice instead.
18  Using Arduino / General Electronics / Re: LM2917 tachometer calculation help.. on: September 14, 2011, 01:06:06 pm
Sorry I got confused with single-coil dual-winding/two cylinder bike engines, they fire on exhaust stroke. The Royal Enfield is a 4-stroke some models with dual-sparkplug, so I figure 2 revs/spark.

2000RPM/60=33.3Hz crankshaft speed/2 = 16.67Hz ignition frequency.
At 800RPM =6.67 Hz, at 8,000 RPM = 133.3Hz
At 800RPM =150msec, at 8,000 RPM = 15msec between pulses

I would use a timer on the Arduino to measure time between ignition pulses and convert to RPM.
You are using the LM2917 to drive an analog meter? See page 10 on app. note http://www.national.com/an/AN/AN-162.pdf
also thread here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237171773


A capacitive ignition sensor can be made with a couple turns of wire wrapped around the spark-plug wire and then into the 555 circuit. I have never found a source for inductive pickups. You can make one with a split ferrite core (like EMI snap-on cores).
19  Using Arduino / Sensors / Re: Any pointers for Infrared Emitter on: September 14, 2011, 11:09:07 am
You have to pulse an IR led to transmit data. Sparkfun website is down so not sure what you got. People use a 555-timer chip circuit http://jap.hu/electronic/infrared.html to generate these fast pulses, which the micro then turns on/off to send data. Samsung standard is 39.2kHz and RC-5 modulation (32 bit, 1 start, 1 stop) is popular), more info here:
http://www.techdesign.be/projects/011/011_waves.htm
20  Using Arduino / Sensors / Re: Challenging gearwheel sensor problem on: September 14, 2011, 10:58:27 am
I think you have two things to sense.
When the lenses are at (either) end of travel, you need 3 or 6 (home) limit-switches also. VCR's use a small hole drilled in the gear with opto-sensor, or microswitches and a cam lobe to find home.

Next, to measure position- a slotted (quadrature) optical encoder wheel, from an old computer mouse, old DSLR lens or plastic cutout from laser print out. A hall-sensor on the motor might work but I have not tried. The gear teeth themselves are really small and aligning the sensor would be difficult.

What I have done is used ~1" plastic tubing to connect a rotary encoder to the mech. shaft. The tubing allows misalignment and stretches snug on the shafts, or use glue/clamps but it's low torque.
21  Using Arduino / General Electronics / Re: TIL 143 IR Source & Detector package spec required on: September 13, 2011, 09:13:37 pm
I couldn't find a datasheet, but I did cross-reference it to NTE3100 with pinout here: http://www.nteinc.com/specs/3100to3199/pdf/nte3100.pdf
Or you can use a multimeter on diode-test to ID the LED pins and the phototransistor if you shine a light on it, it will turn on.
22  Using Arduino / General Electronics / Re: LM2917 tachometer calculation help.. on: September 13, 2011, 09:01:41 pm
 smiley-confuse  if your bike is a 4-stroke engine, you get a spark every 4 engine revolutions. If your bike is a 2-stroke engine, you get a spark every 2 engine revolutions.
2000RPM/60=33.3Hz crankshaft speed = 8.33Hz (4 stroke)  or 16.67Hz (2 stroke) ignition frequency.
23  Using Arduino / General Electronics / Re: Using tranistors on PWM outputs on: September 13, 2011, 08:55:08 pm
Wait - do you have the pinout correct on the BC546 C-B-E? It looks like your excess current is not the LED's staying on, but the Arduino outputs staying high during sleep mode and driving the transistors? First you need a base drive resistor a few kohms, never direct. Second you can drive the pins low, or pinMode them to inputs before you go to sleep, to save power.
24  Using Arduino / Programming Questions / Re: Strange behaviour from Arduino with I2C on: September 13, 2011, 08:40:17 pm
I've been assigning SPI pins CS,MISO,SCK,MOSI as input/output pins with pinMode(), and enabling pullup resistors on CS and MISO in Setup(). With a scope, I noticed these pins can float and cause weirdness. Check it by touching them with your finger and seeing if things change.
I'm not sure what the MAX6675 library does for SPI setup, but it's good for 4.3MHz SPI which seems fast enough.
25  Using Arduino / Programming Questions / Re: How to convert a long into float? on: September 12, 2011, 05:28:38 pm
The LTC2418 24-bit A/D is a real bear to get working smiley-evil The conversion data and channel numbering are from Mars. Its output data is "somewhat" 2's complement- there are status bits to tell -ve or +ve over range and I finally have a signed long for the conversion (I will post my sketch in another thread once I get it finished). I need a float to print voltage.

Code:
//This code works fine, I get a float with the static(?) cast:

signed long adc_value;

   adc_value=getAtoD();
   adc_result= (float) adc_value;
   adc_result= /838860.8; // R divider 9V max; A/D=2.5Vfsd
   Serial.println(adc_result,4);
However, I went to using a union to store the A/D data and it doesn't work properly:
Code:
union
{
  float v_modem;    // Ch. 4 scaled voltage 0-5V
  float v_solar;    // Ch. 3 scaled voltage 0-5V
  float modem_vreg; // Ch. 2 scaled voltage modem vreg 0-9V
  float I_monitor;  // Ch. 1 scaled current 0-2A
  float v_board;    // Ch. 0 scaled voltage 0-9V
}
adc;
//--------------------------------------

void mysub() {

signed long adc_value;

  adc.v_board = 0.0;
  adc.I_monitor = 0.0;
  adc.modem_vreg = 0.0;
  adc.v_solar = 0.0;
  adc.v_modem = 0.0;

  adc_value=getAtoD();
  adc.v_board = (float)adc_value/838860.8;

  Serial.println(adc.v_board,4);
  Serial.println(adc.I_monitor,4);
  Serial.println(adc.modem_vreg,4);
  Serial.println(adc.V_solar,4);
  Serial.println(adc.V_modem,4);
}
V_board is correct i.e. 6.0512V but ALL channels in the union have the same value 6.0512V  smiley-confuse
26  Using Arduino / Installation & Troubleshooting / Re: Loading code to Arduino through USB in Windows 7 on: September 07, 2011, 06:43:02 pm
I found my USB hub made things not work properly- connect directly to your PC.
Then uninstalling the USB driver then reinstalling in Windows7 fixed things.
I go to Computer->Manage->Device Manager and see if connecting/disconnecting the Arduino shows COM port assignment.
COM1 can be your motherboard RS-232, not a USB assignment.

I had some hassles with the Mega2560 under Windows7. It does not use the FTDI USB chip, instead uses Atmel 8U2 so I had to load the USB driver from drivers\Arduino MEGA 2560.inf ...  but not so with the Mega328.
27  Using Arduino / Programming Questions / How to convert a long into float? on: September 07, 2011, 01:18:02 pm
I have a 24-bit signed quantity (from A/D converter LTC2418) and need to convert it to a float (voltage). I'm finding this really hard and not sure where things go wrong. I get the 24-bit A/D data and sign-extend into a 32-bit long:

signed long adc_value;

   adc_value=getAtoD();
   Serial.println(adc_value,HEX);

   adc_result= (float)adc_value;
   Serial.println(adc_result,2);


Results
A/D data:
0xC0000000 (+2.5V fullscale) sign extends to -> 0xFFC00000 gives-> -4194304.00 (expect 838608.00)
0x80000000 (zero)               sign extends to -> 0xFF800000 gives-> -8388608.00 (expect 0)
0x7FFFFFFF (-1 LSB)            sign extends to -> 0x007FFFFF gives->  8388608.00 (expect -1.00)
0x40000000 (-2.5V fullscale)  sign extends to -> 0x00400000 gives->  4194304.00 (expect -838607.00)

I can't understand why the values are off.
28  Using Arduino / Project Guidance / Re: What is Mega 2560 power source preference on: September 07, 2011, 12:41:38 pm
How do I disable the Mega2560 from powering up via USB? I am supplying external power VIN and only want to use that, as the current drain is too high for USB. The voltages are too low when USB is connected.
29  Using Arduino / Programming Questions / Re: How to convert 4 bytes into a long? (SOLVED) on: September 02, 2011, 06:50:35 pm
byte d[4];
long adc_value;

<.... stuff deleted>

adc_value  =  (long)d[0] << 24;
adc_value += (long)d[1] << 16;
adc_value += (long)d[2] << 8;
adc_value += (long)d[3];

This code works fine now. (Without proper casting to a long, I get swapped nibbles i.e. 21346587)
Thanks to everyone, esp. jraskell for the help.
30  Using Arduino / Programming Questions / Re: How to convert 4 bytes into a long? on: September 01, 2011, 11:54:45 am
Yes it should be: unsigned long adc_value; but I get the same results.
Pages: 1 [2] 3