Show Posts
Pages: 1 ... 77 78 [79] 80 81 ... 151
1171  Using Arduino / Programming Questions / Re: How to convert a number to binary ? on: November 19, 2012, 05:26:37 pm
If you are talking about a binary string: 3 = "00000011" for example, the following does it:

Code:
unsigned char *hex2binstr(unsigned char *str, unsigned char dat) {
  unsigned char mask = 0x80;
  do {
    if (dat & mask) *str='1'; //the bit is 1
    else *str='0'; //otherwise it is 0
    str+=1; //increment the pointer
    mask = mask >> 1; //shift mask
  } while (mask);
  return str;
}

It converts an unsigned char into an 8-char string.

You can then build on top of it routines that convert more complex structures into str.
1172  Using Arduino / Programming Questions / Re: Random() on: November 19, 2012, 05:22:22 pm
You already have that diode, in some mcus with a temperature sensor;

But the thermal noise is too small to produce a truly random figure by the onboard adc.
1173  Using Arduino / Microcontrollers / Re: SPI read write for 32bits data on: November 19, 2012, 06:30:53 am
Sending 8 bits 4 times = sending 32bits.
1174  Using Arduino / General Electronics / Re: Help on how to charge UltraFire 18650 4200mAh Rechargeable Lithium Battery on: November 19, 2012, 06:30:02 am
Quote
UltraFire 18650

Before you invest all the money / efforts to figure out a charger for it, you may want to crack open one of those batteries. What's inside may surprise you.
1175  Using Arduino / General Electronics / Re: Why does a 9V battery power a 5V Arduino? on: November 19, 2012, 06:29:14 am
Quote
Why does a 9V battery power a 5V Arduino?

Some people have a lot of money.
1176  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 19, 2012, 06:26:25 am
Code:
[quote]..Meaning put it in "for" loop where u need it?[/quote]

It depends.

The following protects the width of '1':

[code]
  cli();
  clk_set();
  NOP();
  NOP();
  NOP();
  NOP();
  NOP();
  sei();
  clk_clr();
  ...

or you can expand to protect the period of a transition:

Code:
  cli();
  clk_set();
  NOP();
  NOP();
  NOP();
  NOP();
  NOP();
  //sei();
  clk_clr();
  NOP();
  NOP();
  NOP();
  NOP();
  NOP();
  sei();

Or to protect all 24 transmission:
  cli();
  for (i=0; i<24; i++) {
    clk_set();
    NOP();...
    clk_clr();
    NOP();...
  }
  sei();
[/code]

...

All depends on what you are trying to do.
1177  Using Arduino / Programming Questions / Re: What type of code to use on: November 18, 2012, 05:35:19 pm
Code:
  while (reed_read()==LOW) continue;

will do it.
1178  Using Arduino / Microcontrollers / Re: Attiny2313 analog comparator on: November 18, 2012, 05:33:02 pm
Here is what I would use:

Code:
/*
 */
//some chips use ana_comp_vect and others analog_comp_vect
#if defined(ANA_COMP_vect)
ISR(ANA_COMP_vect) {
#else
ISR(ANALOG_COMP_vect) {
#endif
//clear the flag
//_comp_isr_ptr(); //run user isr handler
        //insert your code here
        //example
        if (ACSR & (1<<ACO)) {//aco asserted. do something}
        else {//aco cleared. do something else}
}

//reset the comparator
void comp_init(void) {
//ain0/ain1 assumed to be input

//configure output pin

//configure the analog comparator
#if defined(DIDR)
DIDR = (1<<AIN1D) | //disable ain1's digital input
(1<<AIN0D) //disable ain0's digital input
;
#endif

#if defined(DIDR1)
DIDR1 = (1<<AIN1D) | //disable ain1's digital input
(1<<AIN0D) //disable ain0's digital input
;
#endif

//configure ACSRB if available
#if defined(ACSRB)
ACSRB &=~(0<<ACME); //disable acme
#endif

//configure ACSR
ACSR &=~(1<<ACIE); //disable interrupt
ACSR = (0<<ACD) | //analog comparator power on
#if defined(ACBG)
(0<<ACBG) | //bandgap reference not selected. Use AIN1 for non-inverting input
#endif
(1<<ACI) | //clear acif by writing '1' to it
(0<<ACIE) | //interrupt not yet enabled
(0<<ACIC) | //analog comparator input capture disabled
(0<<ACIS1) | (0<<ACIS0) //interrupt on output toggle
;

ACSR |= (1<<ACIE); //enable the interrupt

//rest comp_ptr
}


In your code, you would need to run comp_init() to initialize the analog comparator module. After that, the processing of ACO is done in the isr.

The code is written to run a variety of mcus and with user-installed isr so if you want, you can delete some of the stuff that's not relevant to your module.
1179  Using Arduino / LEDs and Multiplexing / Re: looking for a super source driver chip any ideas? on: November 18, 2012, 05:27:31 pm
Quote
im looking for a source driver than drive 500mA per output channel.

You may want to look into dc/dc converters: they can be easily configured to produce your desired current levels and they are much more efficient than linear solutions, especially at that kind of current levels.

All you do is to use a resistor to program the desired current levels.
1180  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 18, 2012, 05:22:57 pm
If you have to protect the transmission, you may want to think what it is that you are trying to protect: you can protect the pulse width (high or low, or high and low); you can protect every 8 pulses; or you can protect all 24 pulses.

That will determine where / when  you disable / re-enable the interrupts.

The key is to minimize the duration of disabling them.
1181  Using Arduino / Programming Questions / Re: Random() on: November 18, 2012, 04:55:41 pm
Quote
Maybe the /16 div factor you're using,

That's not done without reason, smiley

Quote
They seem to use 2.

smiley
1182  Using Arduino / Programming Questions / Re: Random() on: November 18, 2012, 04:46:42 pm
With the stock analogRead(), here are the top value counts after about 2500*8 samples:

Code:
value  count
0 107
84 96
42 89
21 89
10 81
64 79
80 78
8 78
85 77
2 77
1183  Using Arduino / Programming Questions / Re: Pin output toggling error.......signal tearing? on: November 18, 2012, 04:41:26 pm
Quote
cli (); is needed to Disable Interrupt flag.

It doesn't disable interrupt flags: it disable interrupt execution. The flags will be set as they otherwise would be, except that they don't trigger isrs anymore.

Before you disable it, think hard if you have to. If your pulses needs to be generated absolutely as you had written, without interruption, you then have no choice but to disable interrupts.
1184  Using Arduino / LEDs and Multiplexing / Re: Single transistor constant current power led driver. on: November 18, 2012, 04:36:17 pm
Quote
I think you always have to do some experimentation regarding the base resistor as the Hfe has a large spread,

You don't have to: the only essential assumption here is that Vbe is constant. Once you have that, the base resistor only needs to be sufficient for the two diodes (or your voltage reference) to be conducting.

Most of the times, something like 330ohm is sufficient.
1185  Using Arduino / Programming Questions / Re: Random() on: November 18, 2012, 10:21:37 am
Looks pretty random to me.
Pages: 1 ... 77 78 [79] 80 81 ... 151