Pages: [1]   Go Down
Author Topic: [SOLVED] CT sensor with Attiny85  (Read 1390 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

Could you give me some hint?
I have connected a CT sensor (current outuput) to an Arduino ATmega 2560 and I have got some realistic values.
I used the schematic from here: http://openenergymonitor.org/emon/buildingblocks/ct-sensors-interface
The burden resistor I used was a 120ohm one (based on the calculations) in order to get the voltate in Arduino's range.

Now I would like to move the project to an Attiny85. The first thing I used was to put the code with no modification, and the values I got were quite different.
After a bit of research I instructed Attiny85 to use the internal refference voltage of 1.1v and re-calculated the burden resistor to ~30ohms.

Now the problem is that analogRead() on the pin connected to the current senzor gives me constant 1023, even if there is nothing connected to the plug.

What do I do wrong? Is the burden resistor correct?

Thank you!
« Last Edit: March 04, 2012, 07:59:19 pm by mirc84 » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12939
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
After a bit of research I instructed Attiny85 to use the internal refference voltage of 1.1v...

I suggest you refrain from changing the voltage reference until you make certain there is not a problem with your code or the wiring.

Quote
What do I do wrong?

You forgot to post your code.  Please use [code] [/code] tags.

Which core are you using?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am using the core posted here https://github.com/mchr3k/arduino-libs-manchester/downloads by mchr3k. I did so in order to get the Manchester library working.
As you may see below I'm troubleshooting the values by transmitting them wirelessly to another arduino and reading them there.

Thanks for your help.



Code:
//Basic energy monitoring sketch - by Trystan Lea
//Licenced under GNU General Public Licence more details here
// openenergymonitor.org


// for data TX using manchester coding library
#include <MANCHESTER.h>

#define TxPin 4  //the digital pin to use to transmit data
#define SensPin 0   //current sensor connected to A0 on AT Mega and on pin 3 on attiny85


//Sketch measures current only.
//and then calculates useful values like
//apparent power and Irms.
//Apparent power is calculated from set Vrms.
double Vrms=234.0;

//Setup variables
int numberOfSamples = 3000;

//Set current input pin
int inPinI = 1;

//Current calibration coeficient
double ICAL = 0.1;

//Sample variables
int lastSampleI,sampleI;

//Filter variables
double lastFilteredI, filteredI;

//Power calculation variables
double sqI,sumI;

//Useful value variables
double apparentPower,
       Irms;
     
void setup()
{
//   Serial.begin(9600);
  MANCHESTER.SetTxPin(TxPin);
}

void loop()
{

for (int n=0; n<numberOfSamples; n++)
{

   //Used for offset removal
   lastSampleI=sampleI;
   
   //Read in current samples.   
   sampleI = analogRead(inPinI);
   
   //tx calculated value
   MANCHESTER.Transmit(sampleI);

   //Used for offset removal
   lastFilteredI = filteredI;
 
   //Digital high pass filters to remove 2.5V DC offset.
   filteredI = 0.996*(lastFilteredI+sampleI-lastSampleI);
     
   //Root-mean-square method current
   //1) square current values
   sqI = filteredI * filteredI;
   //2) sum
   sumI += sqI;
}

//Calculation of the root of the mean of the current squared (rms)
//Calibration coeficients applied.
Irms = ICAL*sqrt(sumI / numberOfSamples);

//Calculation power values
apparentPower = Vrms * Irms;

//Serial.println(sumI / numberOfSamples);
//Serial.print(' ');
//Output to serial
//Serial.print(apparentPower);
//Serial.print(' ');
//Serial.println(Irms);

////tx calculated value
//MANCHESTER.Transmit(apparentPower);

//Reset current accumulator
sumI = 0;
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

for the sake of clarifications I used the following pins:

Code:
#define TxPin 4  //the digital pin to use to transmit data (for attiny is physical pin 3)
#define SensPin 3  //current sensor connected to A0 on AT Mega and on pin analog 3 on attiny85 physically pin 2 of the attiny

I also noticed that Attiny respons differently if I use the power source from ATmega or if I use an external 5v power source.

I have attached some results.

Thank you for your support!

* attiny_current_sensor.xls (86.5 KB - downloaded 12 times.)
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12939
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Hello,

I am using the core posted here https://github.com/mchr3k/arduino-libs-manchester/downloads by mchr3k. I did so in order to get the Manchester library working.

It's a slightly older version of core available here...
http://code.google.com/p/arduino-tiny/

There is nothing "Manchester library" specific in it.

Code:
//Set current input pin
int inPinI = 1;
...
   sampleI = analogRead(inPinI);

You are reading from ADC1.  This is PB2 / digital pin 2 (right side of chip, second pin from the top).  Is that where the sensor is connected?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AAhhh,
I missed that..
Thanks for your help!
Logged

Pages: [1]   Go Up
Jump to: