This is a circuit that I made to automatically switch a CCTV camera from main supply to battery power after the main power goes off; And to charge the battery up to 13V if the battery goes below 11v! (The battery is an old car battery from a Chevy Cruze!)
There are no errors seems to pop up in the IDE; But, It doesn't do anything other than slowly turning on the light in pin1 (light), Which seems to be the PWM code works!
I'm using the MicroCore library by MCUDude. And I used the following code to find the resistor values!
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Well first of all your sketch doesn't actually fit on an ATtiny13 ! just looking at it i was already thinking this with all the floating point calculation sucking up a lot of the available memory, and then just as i read
i thought, let's have a look.
So yes the compiler spits out a warning and then calculates 1176 bytes of flash, which is at 114% then.
So i figure you never successfully uploaded the sketch to the ATtiny, and that is why it doesn't work.
If you want to use an Attiny13 you should avoid floating point calculus (and even float variables i general)
You also don't really need floats. You only need an accuracy of 1 or 2 numbers behind the dot (excused my Dutchism) you can easily create those values in 16-bit integers. (eg 11.1 = 111 or even 1110) Even the Resistor value does not need that accuracy, since the the analog read only has 4 numbers (10-bit)
Try and do multiplications first before division but keep observing the maximum value the variable can hold.
10-bit x 10-bit x 10-bit still fits into a 32-bit variable at any time.
Now you are doing a comparison on a voltage that has a value that makes complete sense to you, but there is no real need for that.
You may not even need to go that far, but i the easiest is just to get rid of the floats, because that just doesn't easily fit onto an ATtiny13's 1KB
First, I couldn't get your code to work (the calculations) without making r2 float
float r2 = 10030.0;
which is why I was even tryting the calculations, it looked like it might be wrong. So maybe I am only confirming my own bias.
Anyway making it all integer is easy. This code uses 4 byte integers, so be careful. I just bluffed my way through this. Note that intAnswer does not use the function or any floating point maths.
# include <stdio.h>
float volt, voltage, temp, temp1, in, input;
int r1 = 104280;
float r2 = 10030.0;
float read_volt(int reading)
{
volt = reading;
temp = volt * (4.9 / 1023);
voltage = temp / (r2/(r1+r2));
return voltage;
}
int main()
{
printf("Jello Whirled!\n");
for (int aIn = 0; aIn <= 1024; aIn += 128) {
int intAnswer = (aIn << 6) / 293 + 2;
intAnswer >>= 2;
printf("%d\t%f\t%d\n", aIn, read_volt(aIn), intAnswer);
}
}
You should probably let the compiler figure out the constants. I had a calculator.
now if we use the 4 significant digits 5459 (rounded) we need to move the dot 5 digits.
, so the result of
in * 5459
will result in a value where 10 volts = 10 * 10,000 = 100,000
and it will be larger than 16 bit so you need to make sure that the calculation is done 32-bit, and we will divide by 100 to get 4 digits significant values. (edit Or divide by 1000 ? someone please check it's 5 a.m here )
uint32_t in = analogRead(A0);
uint16_t voltage = in * 5459 / 100;
now i've declared these types locally but with your code they should be global (or not accessible in other functions, but the result can be compared like this
If you (or the preprocessor) figured out the equivalent direct readings those values must come from, you could use those numbers directly, no floating point, no multiplication or division.
int reading = analogRead(A0);
if (reading >= 199 && reading <= 240) {
Can't say if it'll work for you but, on an UNO, using this library your code compiles to 1514 bytes flash. Without the library it compiles to 1776 bytes flash.