Show Posts
Pages: 1 [2] 3
16  Using Arduino / Programming Questions / What hardware timers available on the Arduino ? on: November 14, 2011, 05:43:06 pm
What hardware timer/counters are available on the Arduino (ATmega328)? Of the three, it looks like one is used for the Delay() and AnalogWrite() library routines. Milli() prob uses one? Also I'm not sure what timer interrupts exist in the stock Arduino.

Just trying to see what MCU resources I can use. I couldn't find docs about this.

17  General Category / General Discussion / Re: Professional Engineers' Perspective? on: October 28, 2011, 05:48:46 pm
Some engineers (like me 10 yrs ago) did hard-core programming in assembly and worried about bytes and micro-seconds and saving every penny. Those days are gone, thankfully. Instead, I can quickly put together a hardware/software solution 10x faster, without the learning curve, without mastering the bit-level and compiler. There is so much community support and libraries too.

I was going to use an ARM7 from scratch for an in-house project. The old-school engineering approach I have done many times. Then I saw the MCU alone has an 1,100+ page datasheet! The software development tools were also buggy, layered and complicated. Do I have time to dig into this, and do PCB layout and coding/debugging with my boss's scheduling and deadlines in my face? I decided to go Arduino and have some fun instead- wasting a few bytes and clock cycles. My Arduino projects are a total success. I just let go of perfection.

But I would not use the Arduino (hardware) in commercial products as they're a bit expensive, the shields (physically) are silly awkward and most Arduino's have limitations that are deal breakers- like my need for them to work at -40C, be micropower run off batteries/solar, something you can bolt down etc. I find them a bit hobby/generic.

My only negatives about the Arduino are the poor documentation for the language and routines. My peers at work did not freak out when they saw the Arduinos on my desk (instead of me "rolling my own" from scratch) so my manliness did not take a hit. I will keep using the Arduino a lot for in-house, development, hobby stuff.
18  Using Arduino / Programming Questions / Re: math with float not working on: October 20, 2011, 06:35:15 pm
Thanks for verifying the code  smiley-surprise  I was running a Mega328 and tried it on a Mega2560, as a quick check if more RAM would help, but no change. It has to be a side-effect, stack mismatch. I found the EEPROM read routine seems to be the culprit, having a Union declared inside (?)
float EEPROMreadFloat(int address) {
  union floatStore {
    byte floatByte[4];
    float floatVal;
  } floatOut;
  for (int i = 0; i < 4; i++)
    floatOut.floatByte[i] = + i);
  return floatOut.floatVal;

I moved the union declaration up to the top of the program it started working. I hope that's it. I checked all other routines for in/out variable passing and couldn't see anything off. I assume doubles and floats are the same (size).
19  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

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;
20  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.
21  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
also thread here:

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).
22  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 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:
23  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.
24  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:
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.
25  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.
26  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.
27  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.
28  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.

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

signed long adc_value;

   adc_result= (float) adc_value;
   adc_result= /838860.8; // R divider 9V max; A/D=2.5Vfsd
However, I went to using a union to store the A/D data and it doesn't work properly:
  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

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.v_board = (float)adc_value/838860.8;

V_board is correct i.e. 6.0512V but ALL channels in the union have the same value 6.0512V  smiley-confuse
29  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.
30  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_result= (float)adc_value;

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.
Pages: 1 [2] 3