Show Posts
Pages: 1 2 [3] 4 5 ... 442
31  Using Arduino / Microcontrollers / Re: Bot Interrupt Pins quit working. on: March 11, 2014, 07:46:00 pm
polling is not really energy efficient, you're doing stuff that can be done in hardware with software.

There is nothing at all wrong with doing in software what can be done in hardware, that is what microcontrollers are all about. If the mcu is running at full power anyway then energy efficiency doesn't come into it. I've already said that I use an interrupt where I want to wake up the mcu from power down mode.
32  Using Arduino / Microcontrollers / Re: Bot Interrupt Pins quit working. on: March 11, 2014, 03:41:48 am
I think it's a bad idea to detach/attach interrupts inside the ISR. You won't get nested interrupts anyway unless you re-enable interrupts inside the ISR, and doing that is best avoided. A more professional solution to the problem you are trying to solve is to use an edge-triggered interrupt (i.e. mode FALLING instead of LOW), and to record the time at which the interrupt occurred. You can do this by calling micros() within the ISR and storing the returned value. Then in the ISR you can do nothing if not enough time has elapsed since the last interrupt. I agree that in simple systems with very little else going on (e.g. no serial I/O), calling delayMicroseconds inside the ISR may be an inelegant but simple way of debouncing.

However, it is generally simpler to handle pushbuttons by polling, except in the case where the button is used to wake up the mcu from power down mode. In that case, I use the interrupt only to wake up the mcu, and poll it the rest of the time.
33  Using Arduino / Sensors / Re: TCRT1000 sensor... i really need help. on: March 08, 2014, 02:36:22 pm
plz help me the circuit posted by the guy is not working.giving lot of noise  smiley-lol

That is nowhere near enough information. What is your application, what is the material that you are reflecting the IR from, and what is the distance between the TCRT1000 and the material you are trying to detect?

The schematic published earlier in this thread is suitable for detecting at quite long distances, but only if the system is well-shielded from sunlight and incandescent artificial light (otherwise the detector will saturate). For detection at shorter ranges, ditch the op amp, reduce the detector load resistor to about 3K3, and feed the detector output directly into an ADC pin.
34  Using Arduino / Microcontrollers / Re: Attiny 45 38khz flash on: February 20, 2014, 04:29:03 am
In case it helps, here is code I am using to turn 3 devices on or off when a button is pressed. I build it in AVR Studio, so it doesn't use the Arduino libraries (although I borrowed some code from them), and I use the internal 8MHz oscillator.

Code:
/*
 * RemoteControl.cpp
 *
 * Created: 25/11/2012 12:41:35
 *  Author: David
 */


#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

#define F_CPU (8000000UL) // 8MHz

// Class to hold the data for the IR on/off signal for a particular device
class RemoteData
{
uint16_t headerMarkLength;
uint16_t headerNormalLength;
uint16_t headerRepLength;
uint16_t frequency;
uint16_t bitLength;
uint16_t bitPeriod;
uint32_t burstPeriod;
uint8_t numRepeats;
uint8_t numCycles;
const uint8_t *normalData;
const uint8_t *repeatData;

void generateBurst(bool isRepeat) const;

public:
RemoteData(uint16_t hml, uint16_t hnl, uint16_t hrl, uint16_t f, uint16_t bl, uint16_t bp, uint32_t up,
uint8_t nr, uint8_t nc, const uint8_t* nd, const uint8_t* rd)
: headerMarkLength(hml), headerNormalLength(hnl), headerRepLength(hrl), frequency(f), bitLength(bl), bitPeriod(bp), burstPeriod(up),
numRepeats(nr), numCycles(nc), normalData(nd), repeatData(rd)
{ }

void activate() const;
};

// Data for PVR on/off signal
const uint8_t pvrNormalData[] = {0b11111111, 0b11111011, 0b11111111, 0b11010101, 0b01010101, 0b01000000, 0};
const uint8_t pvrRepeatData[] = {0b10000000, 0};

const RemoteData pvr(9000, 13500, 11100, 38000, 555, 1110, 108000UL, 2, 1, pvrNormalData, pvrRepeatData);

// Data for TV on/off signal
const uint8_t tvNormalData[] = {0b10111111, 0b01011011, 0b11011000, 0};
const uint8_t tvRepeatData[] = {0b10111110, 0b01110110, 0b10101101, 0};

const RemoteData tv(0, 0, 0, 38000, 250, 1060, 66200UL, 1, 3, tvNormalData, tvRepeatData);

// Data for hifi on/off signal
const uint8_t hifiNormalData[] = {0b11110111, 0b01111111, 0b01010110, 0b10110101, 0b01010101, 0b11011111, 0b10101101, 0b01010101, 0};
const uint8_t hifiRepeatData[] = {0b10000000, 0};

const RemoteData hifi(9000, 13500, 13500, 38000, 555, 1120, 108000UL, 2, 1, hifiNormalData, hifiRepeatData);

// Set the frequency that we will get on pin OCR1A but don't turn it on
void setFrequency(uint16_t freq)
{
  uint32_t requiredDivisor = (F_CPU/2)/(uint32_t)freq;

  uint16_t prescalerVal = 1;
  uint8_t prescalerBits = 1;
  while ((requiredDivisor + prescalerVal/2)/prescalerVal > 256)
  {
    ++prescalerBits;
    prescalerVal <<= 1;
  }
  
  uint8_t top = ((requiredDivisor + (prescalerVal/2))/prescalerVal) - 1;
  TCCR1 = (1 << CTC1) | prescalerBits;
  GTCCR = 0;
  OCR1C = top;
}

// Turn the frequency on
void on()
{
  TCNT1 = 0;
  TCCR1 |= (1 << COM1A0);
}

// Turn the frequency off and turn off the IR LED.
// We let the counter continue running, we just turn off the OCR1A pin.
void off()
{
  TCCR1 &= ~(1 << COM1A0);
}

volatile uint32_t timer0_overflow_count = 0; // microseconds timer

// ISR for timer 0, counts microseconds
ISR(TIMER0_OVF_vect)
{
timer0_overflow_count++;
//TIFR |= _BV(TOV0);
}

// ISR for INT0, wakes up from sleep mode when button is pressed
ISR(INT0_vect)
{
GIMSK = 0; // disable INT0
}

// Return the number of microseconds from start
uint32_t micros()
{
uint8_t oldSREG = SREG;
cli();
uint32_t m = timer0_overflow_count;
uint8_t t = TCNT0;

if ((TIFR & (1 << TOV0)) && (t < 255))
{
m++;
}
SREG = oldSREG;

return (m << 8) | t;
}

void RemoteData::generateBurst(bool repeat) const
{
  setFrequency(frequency);
  uint32_t start = micros();
  if (headerMarkLength != 0)
  {
    on();
    while (micros() - start < headerMarkLength) {}
    off();
    uint32_t headerLength = repeat ? headerRepLength : headerNormalLength;
    while (micros() - start < headerLength) {}
  }

  const uint8_t* p = (repeat ? repeatData : normalData);
  uint32_t bitStart = micros();
  for(;;)
  {
    uint8_t b = *p++;
    if (b == 0) break;
    for (uint8_t i = 0; i < 8; ++i)
    {
      if (b & 0x80)
      {
        on();
        while (micros() - bitStart < bitLength) {}
        off();
      }
      while (micros() - bitStart < bitPeriod) {}
      b <<= 1;
      bitStart += bitPeriod;
    }
  }
  while (micros() - start < burstPeriod) {};
}

void RemoteData::activate() const
{
  for (uint8_t c = 0; c < numCycles; ++c)
  {
    generateBurst(false);
    for (uint8_t i = 0; i < numRepeats; ++i)
    {
      generateBurst(true);
    }
  }
}

void setup()
{
PORTB = 0b00011100; // pullup resistor on PB2/3/4 enabled, outputs PB0 and PB1 low
DDRB =  0b00000011; // PB0 and PB1 are outputs, rest are inputs

TCCR0A = 0;
TCCR0B = _BV(CS01); // prescaler = 8 so 1MHz count rate

TIMSK = _BV(TOIE0); // enable timer 0 overflow interrupt
GIMSK = 0;
PCMSK = 0;
}

int main(void)
{
setup();
sei();
for (uint8_t i = 0; i < 6; ++i)
{
uint32_t start = micros();
PORTB ^= 0b00000001; // toggle visible LED
while (micros() - start < 250000UL) {} // wait 0.25 secs before toggling it again
}

    for (;;)
    {
// Wait for button to be pressed
do
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
cli();
if (PINB & 0b00000100)
{
GIMSK = _BV(INT0);
sleep_enable();
sei();
sleep_cpu();
sleep_disable();
}
sei();
uint32_t now = micros();
while ((micros() - now) < 5000) {}
} while (PINB & 0b00000100);

PORTB |= 0b00000001; // turn on visible LED
uint32_t start = micros();

// The TV doesn't always respond to the PVR HDMI signal up unless we activate it a short while before the PVR. So start the TV first and PVR last.
tv.activate();
while (micros() - start < 250000UL) {} // wait until 200ms after we started
hifi.activate();
while (micros() - start < 500000UL) {} // wait until 500ms after we started
pvr.activate();

while (micros() - start < 1000000UL) {} // keep LED on for at least a second

PORTB &= 0b11111110; // turn LED off

// Wait for button to be released
start = micros();
for (;;)
{
uint32_t now = micros();
if (!(PINB & 0b00000100))
{
start = now;
}
else if (now - start >= 5000)
{
break;
}
}
    }
}
35  Using Arduino / General Electronics / Re: NPN transistor switching on: February 20, 2014, 03:03:08 am
Glad you got it working. It sounds to me that the output driver on that pin has failed and only the internal pullup resistor is working (just as if you hadn't made the pinMode call).
36  Using Arduino / Microcontrollers / Re: Attiny 45 38khz flash on: February 20, 2014, 03:01:11 am
So have you programmed the fuses in the attiny to use the external crystal and clear the CLKDIV8 fuse?

I normally use the 8MHz internal clock on the attiny. The frequency doesn't need to be precise for 38kHz IR.
37  Using Arduino / General Electronics / Re: NPN transistor switching on: February 19, 2014, 03:53:38 pm
On that faulty channel:

1. Check that the 1K base resistor really is 1k and you have not inadvertently used a higher value. Similarly for the 150 ohm resistor in series with the LED.

2. Check that you have made a call to set the pinMode of the pin driving the TIP122 to OUTPUT.

3. Check that when the LED is switched on by the TIP122, the TIP122 emitter is at 0V in case you have a bad or missing ground connection..
38  Using Arduino / Microcontrollers / Re: Attiny 45 38khz flash on: February 19, 2014, 03:32:32 pm
What clock frequency are running the attiny45 at? Did you set F_CPU in the board definition entry to match that frequency? If you are using the internal 8MHz clock, did you clear the CLKDIV8 fuse in the attiny?
39  Using Arduino / Motors, Mechanics, and Power / Re: High level switching with PNP darlington on: February 11, 2014, 05:07:53 pm
1. Halogen lamps take much more current for a short while when you first turn them on. That is temporarily overloading your power supply.

2.You may have difficulty keeping your TIP125s cool enough if you put 5A through them, even with the heatsinks. Mosfets would normally be used for this application, because they dissipate much less power when switching high currents, so if chosen carefully they would not need heatsinks at all.
40  Using Arduino / General Electronics / Re: Reverse polarity protection: P channel or N channel MOSFET ? on: February 10, 2014, 03:23:46 am
You can use that circuit without the resistor and zener diode if you can guarantee that there will never be transients on the 12V input that take it higher than the Vgs rating of the mosfet (20V for the one you have chosen).

The mosfet you have chosen is IMO not suitable for 3A load current because it is likely to overheat at that current. You need a mosfet with either lower Rds(on), or higher heat dissipation capacity (for which you will need a mosfet in a larger case style such as SOT223). Or two of those in parallel.
41  Using Arduino / Displays / Re: Graphical LCD (ST7920 Driver) - a warning and a question on: February 03, 2014, 04:04:40 am
You may need to use a multimeter to check whether PSB is connected to R9. My guess is that PSB is connected to both R9 and R10, that the other side of R9 goes to +5V, and the other side of R10 goes to ground. So the display can be fixed in serial or parallel mode depending on which one is fitted, or can be selected via the PSB pin if neither is fitted. So if you want to use it in serial mode, you will have to unsolder R9.
42  Using Arduino / General Electronics / Re: Arduino digital input, 80Vdc on: February 02, 2014, 07:32:29 pm
One more question: how many 72V inputs are there that you wish to monitor?
43  Using Arduino / Displays / Re: Graphical LCD (ST7920 Driver) - a warning and a question on: February 02, 2014, 07:27:57 pm
Looking at the photo, it appears possible that PSB is connected to one side of R9, and R9 may be a 0 ohm resistor (with the other end presumably connected to +5V). Can you check this by visual inspection and with a multimeter? The ST7920 board I have is unfortunately different in that area and so not directly comparable.
44  Using Arduino / General Electronics / Re: Arduino digital input, 80Vdc on: February 02, 2014, 01:57:37 pm
With voltages varying so much, I am having problems choosing the components. Either they use too much power, or the resistors do not suit to all cases.

Please could you suggest another method ? Anyone else?

You need to state your requirements better. You have said that you want to detect the difference between (1) 60 to 80V, and (b) 0V. Anything else? e.g. do you require a particular behaviour when there is more than 0V but less than 60V? Do you need to allow for more than 80V input, if so what is the maximum voltage? And what is an acceptable power consumption at 80V input?
45  Using Arduino / Displays / Re: Graphical LCD (ST7920 Driver) - a warning and a question on: February 02, 2014, 01:52:04 pm
i have the same problem with such a display...do you remeber, which resistor caused to problem ?

Please describe what problem you have, and post a photo of the back of the display.
Pages: 1 2 [3] 4 5 ... 442