EmbeddedRelated.com
Forums

Fundamental C question about "if" statements

Started by Oltimer September 20, 2015
On 22/09/15 00:33, Hans-Bernhard Br�ker wrote:
> Am 21.09.2015 um 20:11 schrieb Simon Clubley: >> On 2015-09-21, John Temples <usenet@xargs-spam.com> wrote: > >>> The PIC24 is a completely new-from-scratch core that has nothing >>> whatsoever do with the PIC18. > >> Yes, it has a new instruction set, etc, but it was advertised by >> Microchip >> as effectively an extension of the PIC18. > > And being engineers we of course take all advertising statements 100% > exactly at face value. Sure. No doubt about that. None at all. Yeah, > right. >
Being mere engineers, we don't get to make all of the decisions - some decisions are made by people who /do/ believe all the advertising. And being human (or at least roughly humanoid), we still judge things based on names, adverts and rough first impressions. My line of thinking on first hearing of the PIC24 was: The PIC16 is a crap 8-bit cpu advertised as a 14-bit cpu. The PIC18 is a slightly less crap 8-bit cpu advertised as a 16-bit cpu. So the PIC24 will be a less crap 8-bit cpu advertised as 16-bit, or 24-bit, or whatever - because Microchip doesn't know how cpu "bitness" works. And when the PIC32 came out, I knew it had a MIPS core - but because they had called it a PIC, I assumed they had found a way to make it as bad a cpu as the other PIC families. And I was right - by using sub-optimal MIPS core (MIPS has many cores that would be far better in a microcontroller family), combined with a full-scale effort to cripple the compiler and make the MIPS core run as fast as a traditional PIC, they did manage to make a bad device. And I gather that the key selling point of the PIC32 - 480 Mbps USB - /still/ doesn't work reliably. To my mind, the terrible shame of all this is that MIPS makes cores that are highly competitive in power, speed, and die area to ARM's cores - and the embedded world would be far better off if there was a selection of MIPS-based microcontrollers competing with ARM ones. But people assume MIPS must be useless processors since they are in PIC's. (Note - I make a lot of use of Microchips memory devices, analogue parts, communication devices, and other bits and pieces. It's just their microcontrollers I don't like.)
On 21/09/15 19:23, Tim Wescott wrote:
> On Mon, 21 Sep 2015 11:06:02 +0000, Simon Clubley wrote: > >> On 2015-09-20, Tim Wescott <tim@seemywebsite.com> wrote: >>> >>> Any C compiler that targets an 8-bit PIC is not the best for learning >>> -- >>> at least not for learning C. The PIC architecture is a very bad fit to >>> the C virtual machine, and as such a compiler writer is forced to >>> choose between making a compiler that is not compliant to the >>> standards, or making a compiler that generates hugely inefficient code. >>> >>> >> It's also very resource limited by today's standards. >> >>> I can't speak to the XC8 compiler, but the C18 not only wasn't >>> compatible, it pretty much required you to do Really Bad Things in >>> order to get the most efficient code (this, by the way, is the same >>> problem exhibited by the 8051 -- it's a totally different architecture >>> from the PIC, but it misses the C virtual machine by a similar-sized >>> mile). >>> >>> Given that you can get ARM Cortex-M0 parts that are nearly as small as >>> the smallest 8-bit parts, and are nearly as cheap (I think they get >>> down to $0.75 or less in onsies from DigiKey), I don't see any reason >>> not to use a part that's a better fit to the language. >>> >>> >> The PIC18 has one thing going for it and that is it's available in PDIP >> so it's easy to breadboard them. >> >> Until the PIC32 came along, it was also the only MCU range to have a USB >> device capability in a PDIP format so that made it of natural interest >> for some people wanting to do USB work. >> >> I've played with the PIC18 in the past and I _really_ disliked it, but >> it was the only viable option for PDIP based USB device MCUs at the time >> so I stuck with learning it instead of tossing it on the scrap heap >> where it belongs. >> >> I designed a library at the time which was designed to be portable but >> needed to include the PIC18, so I made some decisions I wasn't happy >> about even at the time and which made the code more cumbersome than it >> needed to be. This was mainly due to the limited resources on the PIC18. >> >> The irony is that I never even got the library actually ported to the >> PIC18 due to other things coming up. :-) >> >> I'm now revisiting that work for another reason and it didn't take me >> long to decide to dump the PIC18 style API for that library and to redo >> the API on the assumption that more resource rich MCUs are available >> instead. >> >> The reason I am mentioning this is to suggest to the OP that they >> rethink the choice of PIC18, even for hobbyist use, in 2015. >> >> BTW, does anyone actually use PIC18s for new production quality projects >> these days ? >> >> [In this discussion, I'm treating the PIC24 as an extension of the PIC18 >> but also as something that comes across as an evolutionary dead-end. >> The PIC24 is even more poorly supported than the PIC18 for open source >> or hobbyist work; at least the PIC18 has SDCC available for it.] > > There are some Cortex-M0 parts showing up in PDIP, and there are Cortex-M0 > parts with USB. I don't know if the two sets intersect, however. > > With the exception of packages that have pads underneath (damn, what's > the name?), hand-soldering surface-mount assemblies just takes a steady > hand and a decent microscope. And, I suspect one could make a good- > enough microscope with the right web-cam and a 'puter. So I don't see > why surface-mount and hobbyist should be mutually exclusive. >
There are endless numbers of ready-made boards available with Cortex devices of all sorts, including USB, Ethernet, and whatever, that sit on DIP-40 sized boards or have similar hobby and prototype friendly layouts and connectors. If someone thinks they can't use a Cortex because it doesn't come in DIP and they can't solder surface mount, they have no imagination. Get a simple eval board from TI or Freescale or whoever, and use that as your base.
On 2015-09-22, David Brown <david.brown@hesbynett.no> wrote:
> > There are endless numbers of ready-made boards available with Cortex > devices of all sorts, including USB, Ethernet, and whatever, that sit on > DIP-40 sized boards or have similar hobby and prototype friendly layouts > and connectors. If someone thinks they can't use a Cortex because it > doesn't come in DIP and they can't solder surface mount, they have no > imagination. Get a simple eval board from TI or Freescale or whoever, > and use that as your base. >
I said nothing about not being able to use Cortex parts - using eval boards for the larger MCUs is exactly what I do. It's just that for the projects with low resource requirements, I prefer to build my own circuits if possible. Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world
On 2015-09-21, John Devereux <john@devereux.me.uk> wrote:
> Wouter van Ooijen <wouter@voti.nl> writes: >> >> I know of only two dip ARM chips: lpc810 (dip8, Cortex-M0+) and >> lpc1114 (dip28, cortex-M0). >> >> The lpc810 used to be priced nice (< $1 IIRC), but recenty they are >> priced much higher (~ $3). Anyobe know why??
So I'm not imagining things. :-( Farnell are currently charging 2.46 GBP/qty 1, 1.79 GBP each/qty 10.
> > Only hobbyists buy them? >
I did think about it being a low volume part, but on other parts with a PDIP packaging option the extra cost of the PDIP option appears to be reasonably constant over time. Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world
On 22/09/15 14:54, Simon Clubley wrote:
> On 2015-09-22, David Brown <david.brown@hesbynett.no> wrote: >> >> There are endless numbers of ready-made boards available with Cortex >> devices of all sorts, including USB, Ethernet, and whatever, that sit on >> DIP-40 sized boards or have similar hobby and prototype friendly layouts >> and connectors. If someone thinks they can't use a Cortex because it >> doesn't come in DIP and they can't solder surface mount, they have no >> imagination. Get a simple eval board from TI or Freescale or whoever, >> and use that as your base. >> > > I said nothing about not being able to use Cortex parts - using eval > boards for the larger MCUs is exactly what I do. > > It's just that for the projects with low resource requirements, I prefer > to build my own circuits if possible. >
Fair enough - it sounds like you make your decisions here in a balanced way. Some people insist on using only DIP parts, and therefore limit their choices drastically and unnecessarily.
On 22.9.2015 &#1075;. 17:11, David Brown wrote:
> On 22/09/15 14:54, Simon Clubley wrote: >> On 2015-09-22, David Brown <david.brown@hesbynett.no> wrote: >>> >>> There are endless numbers of ready-made boards available with Cortex >>> devices of all sorts, including USB, Ethernet, and whatever, that sit on >>> DIP-40 sized boards or have similar hobby and prototype friendly layouts >>> and connectors. If someone thinks they can't use a Cortex because it >>> doesn't come in DIP and they can't solder surface mount, they have no >>> imagination. Get a simple eval board from TI or Freescale or whoever, >>> and use that as your base. >>> >> >> I said nothing about not being able to use Cortex parts - using eval >> boards for the larger MCUs is exactly what I do. >> >> It's just that for the projects with low resource requirements, I prefer >> to build my own circuits if possible. >> > > Fair enough - it sounds like you make your decisions here in a balanced > way. Some people insist on using only DIP parts, and therefore limit > their choices drastically and unnecessarily. > >
Oh come on, it is time we stop commenting on wanting to use a DIP processor. I have not used one since the 6809 days, i.e. since the 80-s. There is no sensible reason to use one in whatever design. If we must go archaic let us go valves :D. Dimiter ------------------------------------------------------ Dimiter Popoff, TGI http://www.tgi-sci.com ------------------------------------------------------ http://www.flickr.com/photos/didi_tgi/
> Oh come on, it is time we stop commenting on wanting to use a DIP > processor. I have not used one since the 6809 days, i.e. since the 80-s. > There is no sensible reason to use one in whatever design.
That depends on your purpose. I like the ability to wiggle a fried LPC1114 out of my students boards and insert a fresh one for a few $. And to have them put an LPC810 in a solderless breadboard and connect all the wires themselves. Wouter
On Tue, 22 Sep 2015 08:53:28 +0200, David Brown wrote:

> On 21/09/15 19:24, Tim Wescott wrote: > >> But it is a point -- who IS the Egyptian god of computing? >> >> > I don't know that one - but some candidates could be: > > Am-heh &ndash; A dangerous underworld god Apep &ndash; A serpent deity who > personified malevolent chaos Heka &ndash; Personification of magic > > (I justify including Heka on the list from what customers expect of us.) > > When I develop my own programming language to be the perfect replacement > for C and all it's quirks, I shall call it Apep.
There's a large population of programmers out there who believe it's been done -- they call the language "Ada". I've never programmed in Ada, but I've debugged it. We had a multi- million dollar contract stall because our box (programmed in C) and the prime's box (programmed in Ada) could not talk to each other. We went back and forth on it for months, until finally the prime decided that they needed to fly half a dozen people all the way across the continent to smack us stupid Oregonians until we saw the light and fixed our bug. I ended up getting sucked into it at the last minute (in retrospect I think it was because the project manager on our side knew that, when handled right, I can act like a demented terrier who's just coming down with second stage rabies -- and mange). So there I am, in a meeting room with half a dozen software engineers from two companies, plus half a dozen sales and project management types to lend weight and credence to the whole "this is serious business" air of the thing. Two things became apparent to me, in the order that I present them here. One, these weren't just Ada programmers, they were (as many Ada programmers seem to be), devout members of the Ada cult. Their simple rule for localizing bugs in a project that contained Ada code and C code was that the bug had to be in the C code -- end of story. On top of that, they had a complete and completely contemptuous ignorance of C -- trying to actually show them code was roughly equivalent to a devout pagan trying to explain what Aphrodite was really about to Jimmy Swaggart in his pre-caught days. Two, the bug had to be in the Ada code. It came about because things had devolved into a very genteel argument, with the Disciples of Ada adamantly insisting that all problems are C problems, with their management team backing them up and making veiled threats to our management team, and our management team fighting a courageous rearguard action. While this all was going on I sort of disengaged and started reading their code, line by line. Now, the problem was that a message was getting bit-reversed. I won't get , and I saw the following lines: <something or other> this_message[0..31]; <something or other> that_message[1..31]; <something or other> trouble_message[31..0] So right in the middle of the discussion, which had been growing ever more heated in an ever more quiet and genteel way, I blurted "Hey! I think I found it!" You may imagine the sorts of looks I got. I explained the whole 0..31 vs. 31..0 business, and the Ada people _would not listen_ -- because Ada code is automatically bug-free, right? Particularly when you've cot C code in the vicinity acting like fresh, extra-sticky fly paper. I tried explaining again -- have you ever tried to hold an intelligent conversation with a rock? A pissed-off rock? I got nowhere. So I had to resort to intellectual violence: "hey, I know that I'm just a dumb-ass C programmer, and moreover that I'm Oregon born and bred. So could you Really Smart Ada people 'splain this here feature of your ever- so-wonderful language to me, in short words?" Then I went over it "so this line says zero to thirty-one. And THIS line says 1 to thirty one." Then, resisting the urge to drool a bit "and THIS HERE line says thirty one to 0 and DAMN but stupid little old me just can't unnerstand what it all MEANS!" At which point their chief Ada programmer and High Priestess of Blessed Code actually LOOKED at her code, slammed her printout on the table, and stomped out of the room. So, anyway -- Ada, because it's always bug free, and infinitely better than C in every possible way. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Wouter van Ooijen <wouter@voti.nl> writes:

>> Oh come on, it is time we stop commenting on wanting to use a DIP >> processor. I have not used one since the 6809 days, i.e. since the 80-s. >> There is no sensible reason to use one in whatever design. > > That depends on your purpose. I like the ability to wiggle a fried > LPC1114 out of my students boards and insert a fresh one for a few > $. And to have them put an LPC810 in a solderless breadboard and > connect all the wires themselves. > > Wouter
Hi Wouter There are also any number of SMT:DIP adapters that can be used, cost is ~$1. <http://www.ebay.co.uk/sch/i.html?_odkw=dip+adapter+-socket&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313.TR0.TRC0.H0.Xdip+adapter+-socket+-sockets+-sop8.TRS0&_nkw=dip+adapter+-socket+-sockets+-sop8&_sacat=0> -- John Devereux
On 22.9.2015 &#1075;. 21:39, John Devereux wrote:
> Wouter van Ooijen <wouter@voti.nl> writes: > >>> Oh come on, it is time we stop commenting on wanting to use a DIP >>> processor. I have not used one since the 6809 days, i.e. since the 80-s. >>> There is no sensible reason to use one in whatever design. >> >> That depends on your purpose. I like the ability to wiggle a fried >> LPC1114 out of my students boards and insert a fresh one for a few >> $. And to have them put an LPC810 in a solderless breadboard and >> connect all the wires themselves. >> >> Wouter > > Hi Wouter > > There are also any number of SMT:DIP adapters that can be used, cost is > ~$1. > > <http://www.ebay.co.uk/sch/i.html?_odkw=dip+adapter+-socket&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313.TR0.TRC0.H0.Xdip+adapter+-socket+-sockets+-sop8.TRS0&_nkw=dip+adapter+-socket+-sockets+-sop8&_sacat=0> > >
I was about to write something like that, good thing I delayed. You looked up some examples, I would not have done it :-). I remember back in the HC11 days (20+ years ago) there was a PLCC 52 socket which soldered as through hole at a 2.54 grid, I think I used it once for a one-off thingie (that may have been some 15 years ago though). Dimiter