Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Sapozhnik posted:

well, shifting by more than the word size is also undefined. on some arches you get zero, on others the high-order bits of the shift parameter are ignored.

that's a feature, mapping a language feature to an arch feature is what C is for

if you don't like it, use a better language, like most of them

Adbot
ADBOT LOVES YOU

Sapozhnik
Jan 2, 2005

Nap Ghost
yeah like java, where >> means arithmetic right shift, a thing you'd want to do, ever

logical right shift is >>>

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Cybernetic Vermin posted:

common lisp has a great standard as well, but it came out when lisp was already passing out of relevance

heresy, Common Lisp is quite relevant

I've run it on an Intel Edison and I run it on Raspberry Pi and classic Macs a fraction the speed and it works great

(yeah yeah yeah real world relevance etc. but if you're just doing hobby poo poo you can use what you what and CL can fit right into that, as can Haskell and anything else)

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Cybernetic Vermin posted:

nah, the c standard is one of the few reasonably complete language standards not entirely bound to a single implementation. javascript and c++ are the only other of relevance i can think of (common lisp has a great standard as well, but it came out when lisp was already passing out of relevance)

the ANSI C standard from 1989 is why I was able to download the latest mbedTLS and libssh2 source code and get them building on a 2002 iMac G4 running Mac OS 9.2.2, doing nothing that (in principle) wouldn't also compile on a Mac Plus running System 6 (modulo code size, mbedTLS compiles to about 1MB of code)

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
that said I certainly wouldn't consider the C standard anywhere near "complete" given how many kinds of undefined and implementation-defined behavior it has, but the parts that are defined have turned out to be reasonably portable

hobbesmaster
Jan 28, 2008

eschaton posted:

the ANSI C standard from 1989 is why I was able to download the latest mbedTLS and libssh2 source code and get them building on a 2002 iMac G4 running Mac OS 9.2.2, doing nothing that (in principle) wouldn't also compile on a Mac Plus running System 6 (modulo code size, mbedTLS compiles to about 1MB of code)

uh, i use mbed-tls on a cortex m3 that definitely does not have 1mb of flash

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?
yeah, I'm just building everything in right now, including self-test, if I say I want to put data in "ROM" (actually Mac resources) and don't include self-test I bet it'll get plenty smaller even with all the cipher suites and such included

big shtick energy
May 27, 2004


spent a couple of hours checking the continuity of an improvised wire harness and trying to debug a chip I couldn't talk to over SPI until my coworker thought to ask "are you sure you're connecting to the right SPI bus?"

I was not

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe
just got tasked with enabling LED PWM support on the board I'm working with.

this board has been through 6 revisions over the course of 2 full years. And it's basically just a poo poo microcontroller, a few knobs, and a couple of LEDs.

turns out that even on the current revision, I can't use the microcontroller PWM because the only way to actually make the LED driver circuit work is to set the pin to an input and toggle the pullup resistor on and off.

JESUE loving CHRIST :suicide:

hobbesmaster
Jan 28, 2008

can you even toggle the pullup that fast?

Spatial
Nov 15, 2007

haha

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

hobbesmaster posted:

can you even toggle the pullup that fast?

probably not

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe
for extra lols, the LED brightness winds up depending on the value of the pullup (which goes from 50% to 200% of nominal) and also the transistor gain (which can be anywhere from 40 to 300)

if the transistor gain is high enough, the circuit doesn't work at all

Poopernickel fucked around with this message at 19:27 on Jul 8, 2017

Sapozhnik
Jan 2, 2005

Nap Ghost
jfc i'm pretty sure i could do a better job than that and i've never designed a pcb before in my life

BobHoward
Feb 13, 2012

The only thing white people deserve is a bullet to their empty skull
usually if it's just an indicator LED you can get away with driving it right off the microcontroller's gpio, no need for any external buffer circuit. even the current limit resistor is optional since most uC output drivers can't source more than 10 to 20 mA

and if you have to put in a transistor for higher current it should be a fet imo, lol @ using a pair of bjts for this application

Sagebrush
Feb 26, 2012

Poopernickel posted:


JESUE loving CHRIST :suicide:



what were they even going for here?

if it's something like a 5mm LED you can do it literally as GPIO -> resistor -> LED -> ground

why is there one transistor driving the LED and another transistor to drive that transistor (also is this a darlington pair?)? i guess i could see that being a thing if the LED is too powerful for the GPIO directly, and you picked some terrible drive transistor that needs more current to saturate than the microcontroller can provide?

mosfets or bust

Sagebrush fucked around with this message at 20:04 on Jul 8, 2017

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe
only reason I can come up with for that bullshit is that they're driving it from a 3.3V micro and have to high-side switch because the LED in question is a red/green common cathode LED (it's still garbage in the worst way)

also, it's a 2-channel common-cathode led (red/green) so of course they want ~*CoLoRs*~ for marketing reasons

the most ironic part is that once they dial in their magic PWM value which I'll have to provide manually with timer interrupts, the colors will change wildly from unit to unit because of this poo poo circuit

"constant-current source? what's that and why would we ever need it lol"

Poopernickel fucked around with this message at 20:07 on Jul 8, 2017

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

Sagebrush posted:

what were they even going for here?

if it's something like a 5mm LED you can do it literally as GPIO -> resistor -> LED -> ground

why is there one transistor driving the LED and another transistor to drive that transistor (also is this a darlington pair?)? i guess i could see that being a thing if the LED is too powerful for the GPIO directly, and you picked some terrible drive transistor that needs more current to saturate than the microcontroller can provide?

mosfets or bust

it's a bog-standard 5mm red/green comon cathode LED, driving it with ~15mA

all of these BJTs are one-per-package SOT-23s because why place one component when you could place two instead

the circuit would actually work(ish) if there was a limiting resistor between the two transistors, but as it is Q2's emitter-base current starves the LED current



Poopernickel fucked around with this message at 20:14 on Jul 8, 2017

longview
Dec 25, 2006

heh.
that's pretty terrible, but you gotta admire that dedication to saving $0.001 by not putting in an extra resistor to make it work

it's not like a SN74LVC2T45 is that expensive

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

longview posted:

that's pretty terrible, but you gotta admire that dedication to saving $0.001 by not putting in an extra resistor to make it work

it's not like a SN74LVC2T45 is that expensive

i would bet my left nut that it was an accident which stayed in the design through 6 revisions

nobody ever noticed because the last firmware engineer on this project didn't know that he was toggling the pullup resistor rather than the output

hobbesmaster
Jan 28, 2008

Poopernickel posted:

i would bet my left nut that it was an accident which stayed in the design through 6 revisions

nobody ever noticed because the last firmware engineer on this project didn't know that he was toggling the pullup resistor rather than the output

i was about to ask how but then I realized the registers are probably separated by a letter or something

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

hobbesmaster posted:

i was about to ask how but then I realized the registers are probably separated by a letter or something

it's the direction register that makes the difference - On the Attiny88 and friends, the 'value' register controls the pullup resistor if the pin is an input

and it's an input by default unless you set the pin to an output

hobbesmaster
Jan 28, 2008

i am so spoiled by cmsis its not funny

edit: er, technically vendor specific hals

Sapozhnik
Jan 2, 2005

Nap Ghost
why does anybody use atmel for anything

it was an iffy choice even before microchip bought them out and jacked up all the prices 500%

like it's not a bad 8-bit architecture by any means, it's just that we live in the year 2017 and cost-competitive 32-bit microcontrollers which can be targeted by the same compilers that see massive use for desktop and server applications are things that exist

Luigi Thirty
Apr 30, 2006

Emergency confection port.

arduinos

Sagebrush
Feb 26, 2012

probably cause you can still get avrs in 5v DIP packages that are easy to mess around with, and they do the job for a lot of dumb little things and unlike PIC their toolchain isn't garbage

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

Sapozhnik posted:

why does anybody use atmel for anything

it was an iffy choice even before microchip bought them out and jacked up all the prices 500%

like it's not a bad 8-bit architecture by any means, it's just that we live in the year 2017 and cost-competitive 32-bit microcontrollers which can be targeted by the same compilers that see massive use for desktop and server applications are things that exist

ikr

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

Sagebrush posted:

they do the job for a lot of dumb little things and unlike PIC their toolchain isn't garbage

this, and also msp430's toolchain is pretty good too

but in tyool 2017, there are m0+'s on the market that are on-par power-consumption wise, can compute a lot more, and are even cheaper sometimes

Poopernickel fucked around with this message at 23:42 on Jul 8, 2017

Sapozhnik
Jan 2, 2005

Nap Ghost
You can get NXP cm0 chips in dip packaging

Lol nothing you interface with is gonna be 5v grandpa

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Sapozhnik posted:

jfc i'm pretty sure i could do a better job than that and i've never designed a pcb before in my life

I'm pretty sure I could do a better job and I've basically never done or tried to do analog

how does one fail so spectacularly at blinking a loving LED?

(it reminds me of the analog-component-packed XNOR board Radio-Electronics published for their April Fool's issue one year in the late 1980s, it filled a 3x5 board and "only a few hundred of these and you can make a simple ALU!")

FlapYoJacks
Feb 12, 2009

Sapozhnik posted:

why does anybody use atmel for anything

I was thinking about using a sha256 authentication chip from them. Seems cheap and would be nice for storing a private key yes?

Is there another company/chip I should look at?

Edit:
Something like this: http://www.microchip.com/wwwproducts/en/ATSHA204A#buy

50c~ per unit seems ok.

FlapYoJacks fucked around with this message at 13:09 on Jul 9, 2017

BattleMaster
Aug 14, 2000

BobHoward posted:

usually if it's just an indicator LED you can get away with driving it right off the microcontroller's gpio, no need for any external buffer circuit. even the current limit resistor is optional since most uC output drivers can't source more than 10 to 20 mA

and if you have to put in a transistor for higher current it should be a fet imo, lol @ using a pair of bjts for this application

a current rating doesn't imply any form of current limiting by any means; those CMOS logic output drivers provide low-impedance paths from ground/VCC to the output when you put them on logic 0/1 so omitting the current-limiting resistor will cause it to briefly source a very large current until it and/or the LED both burn out. therefore it's up to you to obey the current rating

they'd be pretty lovely outputs if they worked any other way tbh

edit: I once accidentally hooked up a PIC wrong and didn't understand why it wasn't working properly until I smelled the burning plastic scent of the breadboard under the chip, and then burned my finger touching it

micro still worked after but that particular pin was screwed up

BattleMaster fucked around with this message at 13:27 on Jul 9, 2017

longview
Dec 25, 2006

heh.
the current limit is kind of there anyway for HC logic since the output drive transistors are physically tiny and so the on resistance is very large

different logic families have different maximum currents, HC logic is only actually good up to 4mA so they can't really drive a LED at full current (and will probably drive a LED directly since the output transistors are real wimps).

LVC/LCX logic is much faster and can drive more current (up to 32mA depending on supply voltage). TTL logic is even shittier and usually they have asymmetric output impedances with terrible sourcing capabilities.

this is part of why i use a pleasing shade of orange for all my LEDs unless absolutely necessary; they light up sufficiently for office environments at less than 1mA.

hobbesmaster
Jan 28, 2008

ratbert90 posted:

I was thinking about using a sha256 authentication chip from them. Seems cheap and would be nice for storing a private key yes?

Is there another company/chip I should look at?

Edit:
Something like this: http://www.microchip.com/wwwproducts/en/ATSHA204A#buy

50c~ per unit seems ok.

there's also gemalto secure element but they don't publicly release much. probably because they're used to selling SIM cards

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

ratbert90 posted:

I was thinking about using a sha256 authentication chip from them. Seems cheap and would be nice for storing a private key yes?

Is there another company/chip I should look at?

Edit:
Something like this: http://www.microchip.com/wwwproducts/en/ATSHA204A#buy

50c~ per unit seems ok.

atmel is fine for that stuff, I think he meant don't gently caress wit no AVR when you can use an m0 instead

BobHoward
Feb 13, 2012

The only thing white people deserve is a bullet to their empty skull

longview posted:

the current limit is kind of there anyway for HC logic since the output drive transistors are physically tiny and so the on resistance is very large

yeah it's this i was thinking of, most cmos gpios on µCs are just going to self limit. it's an iffy thing to do but you can sometimes get away with it. not recommended for mass production

a better low component count option is inverse logic: connect the µC gpio to the LED cathode, and vcc to a current limit resistor to the LED anode. microcontroller gpios can often sink much more than they can source, and if the µC supports open/drain outputs, this trick lets you run the led from a higher voltage than the microcontroller's vcc

movax
Aug 30, 2008

BobHoward posted:

yeah it's this i was thinking of, most cmos gpios on µCs are just going to self limit. it's an iffy thing to do but you can sometimes get away with it. not recommended for mass production

a better low component count option is inverse logic: connect the µC gpio to the LED cathode, and vcc to a current limit resistor to the LED anode. microcontroller gpios can often sink much more than they can source, and if the µC supports open/drain outputs, this trick lets you run the led from a higher voltage than the microcontroller's vcc

yep this is the way to go -- drive LEDs with a "____LED_B" signal and call it a day. lol i guess at the LEDs (potentially) briefly flicking while mcu is in reset / booting up

$0.001 for the requisite resistor ain't no thang

BattleMaster
Aug 14, 2000

a modern micro should boot up with the GPIO in high-z so even that won't be an issue; I can't think of any excuse for that weird-rear end transistor circuit even if it wasn't fundamentally broken

Bloody
Mar 3, 2013

Poopernickel posted:

just got tasked with enabling LED PWM support on the board I'm working with.

this board has been through 6 revisions over the course of 2 full years. And it's basically just a poo poo microcontroller, a few knobs, and a couple of LEDs.

turns out that even on the current revision, I can't use the microcontroller PWM because the only way to actually make the LED driver circuit work is to set the pin to an input and toggle the pullup resistor on and off.

JESUE loving CHRIST :suicide:



5

Adbot
ADBOT LOVES YOU

Sagebrush
Feb 26, 2012

got what i imagine is a real simple question:

assuming that the goal is to chop a large piece of data into individual bytes, is there a functional difference between

byte b = (32_bit_int >> 24);

and

byte b = (32_bit_int >> 24) & 0xFF;

?

I've seen both the bit-shifting alone and the shift-and-mask method and I dunno what is the difference.

  • Locked thread