Show Posts
Pages: 1 ... 78 79 [80] 81 82 ... 151
1186  Using Arduino / Programming Questions / Re: Random() on: November 18, 2012, 10:09:41 am
First 2500+ data points using the stock analogRead():

1187  Using Arduino / Programming Questions / Re: Random() on: November 18, 2012, 10:05:34 am
Here is the 1st ~2000 of adc data, using myanalogRead():

unsigned short myanalogRead(unsigned char pin) {
  ADMUX = 0x00;  //Vref = DEFAULT, adc on adc0, right justified
  ADCSRA =  (1<<ADEN) |    //enable adc
            (0<<ADSC) |    //don't start the adc yet
            (0<<ADATE) |  //no auto sampling
            (1<<ADIF) |    //clear adc flag by writing 1 to it
            (0<<ADIE) |    //no adc interrupt
            (1<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);  //1/16 adc prescaler
  ADCSRA |= (1<<ADSC);      //start the conversion
  while (ADCSRA & (1<<ADSC)) continue; //wait for the conversion to end
  return ADC;

I had it fixed on adc0.

1188  Using Arduino / Project Guidance / Re: PID output to PWM input on: November 18, 2012, 09:04:03 am
And I want to use my pid output to drive a pwm generator I just dont know how..

analogWrite() would be a starting point.

Whether it works for your engine is another question.

I'm kinda new to arduino..

In that case, you may want to spend some time reading the documentation for the compiler / ide. Diving into programming with tools you don't quite understand is counter-productive.
1189  Using Arduino / General Electronics / Re: Conrol the voltage of a buck converter .... on: November 18, 2012, 08:59:54 am
The typical approach is to apply a voltage to the feedback pin to fake the output.

If you apply a voltage higher than the rated voltage for that pin (3.3v/5v/etc. for fixed output or 1.23v for the adj version), the output voltage will go down. and vice versa.

The relative gain depends on the resistor mix (from  your control pin to feedback pin and from the output to the feedback pin).
1190  Using Arduino / LEDs and Multiplexing / Re: MAX6921 - need help on: November 18, 2012, 08:56:21 am
A couple possibilities:

1) I didn't spend enough time to see how the device does with 20+ pulses - I think it takes the last twenty. You may want to investigate into that.
2) pulse width: the device is fairly slow so you want to make sure that there is sufficient delay there.

I would rewrite your code as such:

void send_word(long data)
   digitalWrite(clockPin, LOW);
   digitalWrite(loadPin, LOW);

   for(byte i=0; i<20; i++)
      digitalWrite(clockPin, LOW); //data on rising edge

      if (data & (1 << i)) digitalWrite(dataPin, HIGH);
      else digitalWrite(dataPin, LOW);     

      digitalWrite(clockPin, HIGH);

You may want to take a scope on the clk pin to make sure that it is close to 50%.
1191  Using Arduino / Project Guidance / Re: PID output to PWM input on: November 18, 2012, 07:32:27 am
how do I go from the PID outcome to a signal for my engines.

It depends on what kind of output you get from your pid process and what kind of input your engine needs.

Your pid could be producing a numerical value in a range, and your engine could be expecting a pwm input. In that case, simply use the pid output to drive a pwm generator;

Your pid could be producing a on/off signal too. In that case, you may have to figure out what kind of pwm signal means 1 to your engine and what means 0. and configure your pwm generator accordingly.
1192  Using Arduino / Displays / Re: Hacking a LCD diplay on: November 18, 2012, 07:26:31 am
So I think I don't have no chance...

You do have a chance. It is just that without a datasheet, your chance of success is tiny.

1193  Using Arduino / Microcontrollers / Re: Attiny2313 analog comparator on: November 18, 2012, 07:23:40 am
Is that possible?

Maybe it is coincidental but I wouldn't give up hope.
1194  Using Arduino / General Electronics / Re: Voltage fluctuating too much. How to fix? on: November 18, 2012, 07:19:18 am
I checked the output of the AC at the plug and it's 5.39V

It sounds like a poor regulation.

I would try to use a higher voltage adapter and allow the onboard regulator to regulator power to the chip / peripherals.
1195  Using Arduino / Programming Questions / Re: Need help troubleshooting variable not getting set by interrupt on: November 18, 2012, 07:16:11 am
Basically it boiled down to variable decelerations!

It comes down to understanding what debugging is all about: trust nothing. You cannot presume the fault is with certain parts of your code and not others.

Chances are that whatever you think is working is actually causing you problems - that's why bugs are hard to find and often times firms  hire people not involved in writing the code to debug it - to bring in a different perspective and an open mind.

Understanding that is the first step to debugging.

I am also starting to realize just how much is possible if you think outside of the arduino core

You can think of arduino as a dumbed down avr: to present an easy solution for people who don't want to or are unable to read the datasheet. Fortunately, it allows you also some flexibility in coding directly to the core (not as efficiently as otherwise) so you can grow out of it.
1196  Using Arduino / Programming Questions / Re: Random() on: November 18, 2012, 07:11:09 am
You can actually use this approach to generate a truly random number (vs. the pesudo random number from rand() or random()), but it takes a lot more time.
1197  Using Arduino / Programming Questions / Re: Random() on: November 18, 2012, 07:10:00 am
That looks good.

One suggestion: you want to seed the random number generator with a truly random number. So do successive fills with the adc's lowest bit.

  unsigned long tmp = 0x01, rseed=0;
  //create a 32-bit random number
  do {
    if (analogRead(1) & 0x01) rseed |= tmp; //test bit 0
    else rseed |= 0x00;
    tmp = tmp << 1; //left shift the mask
  while (tmp);
  randomSeed(tmp); //seed the random number generator

I would actually use rand() and srand() for their portability.
1198  Using Arduino / Programming Questions / Re: programming an attiny on: November 17, 2012, 09:11:33 pm
a little help getting me going would be much appreciated.

Download AS5.0 and get a $5 avr programmer and start coding.
1199  Using Arduino / Programming Questions / Re: (solved)what's means about "PINB |= 1<<5" on: November 17, 2012, 09:06:14 pm
To make it more interesting, here is what the same compiler did to a slightly different code:

PINB |= (1<<7) | (1<<6);
    00009A   B103             IN      R16,PINB
    00009C   6C00             ORI     R16,0xC0
    00009E   B903             OUT     PINB,R16
 PINB  = (1<<7) | (1<<6);
    0000A0   EC00             LDI     R16,0xC0
    0000A2   B903             OUT     PINB,R16

Stuff like this would be a nightmare to debug. That's probably something like this is rarely seen - the authors of the arduino reference made the right call.

For the record, I always use PORTx ^= (1<<7); for something like this.
1200  Using Arduino / LEDs and Multiplexing / Re: Single transistor constant current power led driver. on: November 17, 2012, 09:03:10 pm
Using a transistor as a constant current device works well if the voltage is high enough compared to the load.

That depends on your definition of "well": the higher Vcc vs. forward voltage drop on the leds, the lower the efficiency of such a circuit.
Pages: 1 ... 78 79 [80] 81 82 ... 151