Hi All,
Currently I am working on a project using the Attiny2313. The problem I am facing is that the sketch I wrote uses too much flash. The attiny has 2KB of flash for programming code.
A piece of code I have questions about:
void setSignal(int co2) {
int pwmSpeed = 0;
switch (range) {
case low:
pwmSpeed = calcSpeed(co2,600,1000);
break;
case mid:
pwmSpeed = calcSpeed(co2,800,1200);
break;
case high:
pwmSpeed = calcSpeed(co2,1000,1400);
break;
}
analogWrite( sig_out, pwmSpeed);
}
The total size of my sketch is 104% of the 2KB flash memory, so I cant upload the sketch. When I remove the analogWrite, the program fits inside the 2KB of flash memory (85% used). Apparently this line uses 20% of the flash memory. Strange thing in my opinion is that when I replace
analogWrite( sig_out, pwmSpeed);
with
analogWrite( sig_out, a value between 0 and 255);
the sketch uses 95% instead fo 104%. The calcSpeed() function returns an int so there is no conversion or anything when calling analogWrite();
Does anyone has a clue why the analogWrite uses different amounts of memory in this case?
Thanks in advance.