Show Posts
Pages: 1 [2] 3 4 ... 176
16  Using Arduino / General Electronics / Re: Current rating on datasheet.. per channel or total? on: August 17, 2014, 06:44:31 pm
Looking good!
17  Using Arduino / General Electronics / Re: Is this a grounding issue? on: August 17, 2014, 06:29:43 pm
Your video is marked private.
18  Using Arduino / General Electronics / Shielding multiple wires on: August 17, 2014, 05:31:01 pm
If you ever need to shield multiple wires, use the method shown in the image below:
19  Using Arduino / Programming Questions / Re: A better way to do my bit reordering? on: August 17, 2014, 02:02:13 pm
Thas all for sharing your skill sets.
20  Using Arduino / Programming Questions / Re: A better way to do my bit reordering? on: August 17, 2014, 02:33:39 am
Quote
it's very general and obvious.
That's what I thought too.

Quote
__builtin_avr_insert_bits()
Way out of my league  smiley-eek


Prescaler bit 11 also goes to D2 (int0) where it is used to manage the overflows.

Doesn't need to be faster as the fastest signal I will be looking at will be 60Mhz.
60 MHZ / 4096 ~ 15 Khz  well within the capability of the 16Mhz 1284Weeny.
21  Using Arduino / Programming Questions / Re: A better way to do my bit reordering? on: August 17, 2014, 02:13:12 am
Yes it was me.  BANG!
The reason is I only use single sided boards.
With a SS PCB there were no jumpers needed when this configuration is laid down.
If I could do double sided PCBs with plated through holes I would have done it the direct way.

Anyway, I came to this compromise, works great. (an offshoot from Crossroads idea)

Code:
// function to read the Pre-Scaler
unsigned int PreScaler ()
{
  //Outputs from the Pre-Scaler (Q0 to Q15) go to Ports C and D. They are wired as shown in the array actualBits[]
  //                         |-------PORTC--------|  |-------PORTD--------|
  //                         0, 1, 2, 3, 4, 5, 6, 7  0, 1, 2, 3, 4, 5, 6, 7
  //actual prescaler bits =  0, 1, 2, 3, 6, 4, 5,11,15,14,13,10, 9, 7,12,08
  //examples:  Q0 goes to PINC[0] . . . Q11 goes to PINC[7] . . . Q8 connects to PIND[7]

  //read the current value coming from the Pre-Scaler
  unsigned int y = (PIND << 8) | PINC;  
  //y now contains the bit values, according to the way things are wired.
  //Bit position in y                   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
  //Value of the Pre-Scaler output pin 00,01,02,03,06,04,05,11,15,14,13,10,09,07,12,08
  //in reality, bits 12, 13, 14 and 15 do not exist.

  unsigned int actual = 0;  //this will be the corrected value when all bits are place in their proper position

  //now let's place all the bits in their proper positions
  bitWrite(actual, 0, bitRead(y,0));
  bitWrite(actual, 1, bitRead(y,1));
  bitWrite(actual, 2, bitRead(y,2));
  bitWrite(actual, 3, bitRead(y,3));
  bitWrite(actual, 4, bitRead(y,5));
  bitWrite(actual, 5, bitRead(y,6));
  bitWrite(actual, 6, bitRead(y,4));
  bitWrite(actual, 7, bitRead(y,13));
  bitWrite(actual, 8, bitRead(y,15));
  bitWrite(actual, 9, bitRead(y,12));
  bitWrite(actual, 10, bitRead(y,11));
  bitWrite(actual, 11, bitRead(y,7));

  return actual;
}

//               End of PreScaler()

22  Using Arduino / Programming Questions / Re: A better way to do my bit reordering? on: August 16, 2014, 11:48:01 pm
PCB is made already.
@Crossroads
Neat.
I'll give it a try and compare it for speed.

23  Using Arduino / Programming Questions / A better way to do my bit reordering? on: August 16, 2014, 11:14:54 pm
I have a 4040 binary counter (I use it as a prescaler) which is attached to PORT C and D on a Atmega 1284.
Q1 through Q12 are connected in such a way that there isn't a 1 to 1 relationship to the Ports.
As a result I wrote this code section to place the bits in proper order.

The code woks fine, however I don't like the using the "if" statement and feel like things could be done better.

Considering speed of execution, would you recommend a more concise way for doing the reordering of the  bits?

Thanks

Code:
// function to read the Pre-Scaler
void PreScaler ()
{
  //Outputs from the Pre-Scaler (Q0 to Q15) go to Ports C and D. They are wired as shown in the array actualBits[]
  //                  |-------PORTC--------|  |-------PORTD--------|
  //                  0, 1, 2, 3, 4, 5, 6, 7  0, 1, 2, 3, 4, 5, 6, 7
  //actualBits[16] ={ 0, 1, 2, 3, 6, 4, 5,11,15,14,13,10, 9, 7,12,08};
  //examples:  Q0 goes to PINC[0] . . . Q11 goes to PINC[7] . . . Q8 connects to PIND[7]

  //read the current value coming from the Pre-Scaler
  unsigned int y = (PIND << 8) | PINC; 
  //y now contains the bit values, according to the way things are wired.
  //Bit position in y                   0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
  //Value of the Pre-Scaler output pin 00,01,02,03,06,04,05,11,15,14,13,10,09,07,12,08

  unsigned long actual = 0;  //this will be the corrected value when all bits are place in their proper position

  //now let's place all the bits in their proper positions
  for (int i = 0; i < 16; i++)
  {
    byte bitValue = bitRead(y , i); //get the current value for this bit
    byte x = actualBits[i];         //get the actual position for this bit

    if (bitValue == 1)
    {
      actual = actual | 1 << x;     //put the bit in the proper location
    }
  }

  //now that we have all the bits in the proper order we remove bits 12 thru 15 as they don't exist
  //bit position      FEDCBA9876543210
  actual = actual & 0b0000111111111111;
  botPScounter =actual;
  return;
}

//                       End of PreScaler


24  Using Arduino / Project Guidance / Re: Wiring and interrupts on: August 16, 2014, 12:36:19 pm
Yes
25  Using Arduino / Programming Questions / Re: Should be simple: What's wrong with my loop? on: August 16, 2014, 01:15:01 am
In your first post, click on MODIFY then add the word [SOLVED] to the title
26  Using Arduino / General Electronics / Re: Current rating on datasheet.. per channel or total? on: August 16, 2014, 01:13:06 am
@Crossroads
I like power LEDs on my boards.
27  Using Arduino / Programming Questions / Re: Should be simple: What's wrong with my loop? on: August 16, 2014, 01:09:30 am
Why 2 loops???
28  Using Arduino / Project Guidance / Re: Wiring and interrupts on: August 16, 2014, 01:07:40 am
Not sure what you are doing but try this (use Rising interrupt)
29  Using Arduino / Programming Questions / Re: Should be simple: What's wrong with my loop? on: August 16, 2014, 01:00:59 am
These do the same thing.
j++
j = j + 1;
30  Using Arduino / Project Guidance / Re: Weird Problem on: August 16, 2014, 12:59:10 am
Quote
I use the arduino 5 volts to power the relay.
Don't.
Pages: 1 [2] 3 4 ... 176