Recently I found some Arduino quantizer code out in the wild and I said, “Cool, Imma use that”. Messed around with it a bit on my Linux box before putting it on an Arduino. One thing was mysterious for a while: the same code worked on Linux and not on Arduino, and I traced it down to these two lines:
int distance = 32768;
...
if (distanceTemp > distance){
See the problem? Hint: I changed the constant to 32767 and it worked.
The other thing was that the code was using about 1500 bytes of dynamic memory out of 2048, storing information about scales. If you have constant data in your software, it’s stored in program memory (flash storage) but when you go to run it it gets copied to dynamic memory (RAM) for use, even though you’re not changing it. I did ditch some of the data it was storing since I didn’t need it and got it down to 1000 bytes. Then I went googling and learned about <avr/pgmspace.h> which lets you tell the system “keep this data in program memory” and gives you tools to access it. Took a while and more googling to figure out the details but in the end the code was using only 260 bytes of dynamic memory. I’m not sure I couldn’t have lived with 1000 bytes but at least now I’ve learned something potentially useful.
Something I learned today.
I could use what I learned in making a mixer/Muliple. In the CGS joystick circuit I am working on. I am adding Offset LEDs Blue and Red for -voltage/+voltage indication.
I could use a non-inverting amplifier too not only not Drag my CV signal down, but can boost the Signals Gain. So It can accurately display the voltage on the led Below The LED Forward voltage(+1.7VRed)(-3.3Blue).
Well I know what 2’s Complement and Signed is… But apart from discussin briefly with my 15 year old last year… last time I realy thought about them was in 1992…
Computers store data in a lot of common ways, in this case, a number is stored as an INT. This usually just means that its a number with no decimal place.
What analogoutput experienced was a result of computers only being able to store a value of a given size. Without being to technical here, the INT is capable of storing a value from -32,768 to 32,767. This is all assuming you are talking about the C programming language, and things based on it’s standard data types (really most everything is). The “signed/unsigned” part is just saying it either supports negative numbers or not. “unsigned” is when its only zero and positive, and “signed” is when it has both, but you effectively half your overall positive numbers. Modern computery deals have larger capacity to store bigger numbers, which is why there was an issue.
@analogoutput yeah, i dont typically have to worry about that shit either. Its only when we go to more low level shit like this right?
Great, something I learned today! Thanks @Caustic!
Clearly programming is not my field, even though I’m MERN stack certified. My degree is in 3D Computer Animation but I’ve spent my entire life working in the music industry for major labels or promoters in the artist development / marketing and Artist Support roles. All that means is I have had to babysit a lot of royal assholes. I’ve also worked with some amazing people. They do exist, but they are few and far between. So I may not know or understand synth DIY very well or computer programming, but ask me about anything music industry related and I’m your specialist
I was writing some code for a DMX interface ( sadly all my code was lost when my HDD died on boxing day ). I was writing the part that allowed the DMX address to be set with buttons and then be stored on the DUINO Non Volatile Memory, so when it rebooted it would get the saved address… All Sweet
Except sometimes, randomly (It Seemed) the address would not be correct after a reboot.
It realy should have twigged much sooner, much much much sooner… DMX to give it it’s fuller name is DMX512 ( as it can send/recive upt to 512 channels of data…)
512 in binary is a 9 bit word… 111111111
the duino memory bytes are standard 8 bit words, so could only store saved addresses up to 256…
So every time I saved the DMX address it lost one bit…
Resolved by storeying to 8 bit Bytes and all was good… ( until the HDD failure )
I have been programming for 38~ years, but not more than a little bit hear and there (apart from some hefty Linux shell scripts)… But doing more and more with the Arduino
In particular, on my Linux computer, an int is 32 bits long, which is enough to store numbers from -2147483648 to 2147483647, so it has no problem storing the number 32768 in an int. Then when it went to compare 5 to 32768 it found 5 was smaller. But on the Arduino an int is 16 bits, enough to store -32768 to 32767 and when you set an int variable to 32768 it happily tries to do so but the result is it gets set to -32768 instead. Now when you compare 5 to that it says it’s larger and the software doesn’t do what you wanted it to.
I thought you were just being case sensitive, like most modern programming languages (your average C/C++ compiler isn’t likely to know what an INT is, the fundamental type is spelled int).