Pages: [1]   Go Down
Author Topic: Problem: TSL235R Light to pulse converter  (Read 634 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am using deumilinove ATMega328 i attached this sensor to interrupt 0 to count pulses but when i expose it to high intensity light it causes an abrupt random movement in my servo attached to pin 9, i found that the way servo library is written servos are interrupt driven could that be a problem??? Please somebody help me!!
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PLease post your code sofar, so we can see if something is wrong ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some testcode I wrote some time ago
Code:
/*
 *    FILE: demo01.pde
 *  AUTHOR: Rob Tillaart
 *    DATE: 2011 05 16
 *
 * PURPOSE: prototype TSL235R monitoring 
 *
 * Digital Pin layout ARDUINO
 * =============================
 *  2     IRQ 0    - to TSL235R
 *
 * PIN 1 - GND
 * PIN 2 - VDD - 5V
 * PIN 3 - SIGNAL
 *
 */

volatile unsigned long cnt = 0;
unsigned long oldcnt = 0;
unsigned long t = 0;
unsigned long last;
unsigned long msec = 0;
unsigned int cf = 1466;  // cf = 10^0.166 * 1000 (figure 1 datasheet)

void irq1()
{
  cnt++;
}

///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
  Serial.begin(115200);
  Serial.println("START");
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, irq1, RISING);
}

///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop()
{
  msec = millis() - last;
  if (msec >= 1000)
  {
    last += msec;
    t = cnt;
    unsigned long hz = (t - oldcnt) * 1000 / msec;
    oldcnt = t;
    unsigned long mw = (hz * cf/1000 + 50)/100; // +50 == rounding last digit
   
    // smoothing possible...
    Serial.print("FREQ: ");
    Serial.print(hz);
    Serial.print("\t ");
    Serial.print(mw); 
    Serial.println(" mW/m2");
  }
}

// END OF FILE
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 603
Posts: 33386
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you powering the servo from the same source as the arduino. Is it USB?
Most servos take more current than the arduino can supply, most of the time you actually need to power the servos with a separate supply.
Also add some supply decoupling to your sensor.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Logged

Pages: [1]   Go Up
Jump to: