Author Topic: PIC and AVR thinking of a switch but need more info  (Read 31536 times)

0 Members and 1 Guest are viewing this topic.

Offline croberts

  • Regular Contributor
  • *
  • Posts: 94
  • Country: us
Re: PIC and AVR thinking of a switch but need more info
« Reply #25 on: March 19, 2013, 04:18:47 pm »
I've been doing a lot of projects and assembly language programming with the PIC16F690. Please check out my post https://www.eevblog.com/forum/microcontrollers/a-simple-state-machine/ for an example of the coding template I use.
« Last Edit: March 22, 2013, 11:56:11 pm by croberts »
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC and AVR thinking of a switch but need more info
« Reply #26 on: March 19, 2013, 04:28:12 pm »
I've been doing a lot of projects and assembly language programming with the PIC16F690. Please check out my post https://www.eevblog.com/forum/microcontrollers/a-simple-state-machine/ for an example of the coding template I use.

I am looking for a pic alternative sorry I just do not like the architecture but I will still check out your post later on tonight when I have time to read it.
 

jucole

  • Guest
Re: PIC and AVR thinking of a switch but need more info
« Reply #27 on: March 19, 2013, 05:13:42 pm »
Here's a couple of useful application notes from Microchip with some handy conditional assembler macros for doing some the tedious stuff, like bank switching.

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011030


But as I've always found with doing asm stuff - you'll need to go tell your mom you'll be late for supper! ;-)
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: PIC and AVR thinking of a switch but need more info
« Reply #28 on: March 19, 2013, 05:54:28 pm »
May I ask what is wrong with the ARM Cortex M0/M0+ I have heard nothing but awesome about them.  People say it gives 8 bit uC's a run for its money.

Nothing wrong with it. I think that Olsenn's "DON'T!!!!!!!!!!!!!!!!!!" was related specifically to the NXP Cortex M0 1114 DIP, which may still have some documentation issues due to being fairly new.

But as I've always found with doing asm stuff - you'll need to go tell your mom you'll be late for supper! ;-)

And late for breakfast the next morning as well. XD
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC and AVR thinking of a switch but need more info
« Reply #29 on: March 19, 2013, 06:26:25 pm »
This is a very interesting discussion.  I got people pushing just about every chip out there just insane. 

So I am starting to look from a different perspective I guess it comes down to what I like better and there is only one way to figure that out.

I am sure I can learn around PIC quirks.  So here is what I will do.  I will build a project with my PIC and then rebuild it with my Arduino AVR chip both in asm and see which one I like better.  I was thinking of something simple like a 4 bit led binary counter.
 

Offline Len

  • Frequent Contributor
  • **
  • Posts: 547
  • Country: ca
Re: PIC and AVR thinking of a switch but need more info
« Reply #30 on: March 19, 2013, 06:29:35 pm »
But as I've always found with doing asm stuff - you'll need to go tell your mom you'll be late for supper! ;-)
:D That brings back memories!

My advice: Assembly programming for AVR would be a bit less annoying than PIC. But when you feel you've pretty much got the hang of it, you might as well switch to C.

Assembly language for programmers is like calculus for engineers - helpful to know, but hopefully you won't have to use it. :) At least it gives you experience mucking around with control registers and such, which comes in handy when you want to do something "unusual" like change the PWM frequency in an Arduino program.

Addendum: Building a simple project with both chips - good idea!
« Last Edit: March 19, 2013, 06:31:23 pm by Len »
DIY Eurorack Synth: https://lenp.net/synth/
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC and AVR thinking of a switch but need more info
« Reply #31 on: March 19, 2013, 06:44:43 pm »
But as I've always found with doing asm stuff - you'll need to go tell your mom you'll be late for supper! ;-)
:D That brings back memories!

My advice: Assembly programming for AVR would be a bit less annoying than PIC. But when you feel you've pretty much got the hang of it, you might as well switch to C.

Assembly language for programmers is like calculus for engineers - helpful to know, but hopefully you won't have to use it. :) At least it gives you experience mucking around with control registers and such, which comes in handy when you want to do something "unusual" like change the PWM frequency in an Arduino program.

Addendum: Building a simple project with both chips - good idea!

Yes I think it will be a good idea too many solid arguments to sort lol.  My biggest fear with PIC is when I need to implement division because although division not too difficult to implement the cycle setup of the pic would take close to 4 times as long to process which would suck.
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
Re: PIC and AVR thinking of a switch but need more info
« Reply #32 on: March 19, 2013, 10:15:33 pm »
... My biggest fear with PIC is when I need to implement division because although division not too difficult to implement the cycle setup of the pic would take close to 4 times as long to process which would suck.
Well, you are doing this to learn asm aren't you?

What better platform than a crippled one. You'll learn a lot more shifting and rotating bits and creating macro's than simply jumping to a platform with an increased instruction set and in the future you'll be better equipped to scrutinise C/C++ compiler output
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: PIC and AVR thinking of a switch but need more info
« Reply #33 on: March 20, 2013, 01:28:07 am »
 
Quote from: originalPoster
I already have a Arduino which I can use for AVR
So what are you waiting for?  Get reading, get programming.  Some things will be great, some not so great.  And you'll be in a much better position to evaluate your THIRD architecture (ARM, MSP430, MIPS, whatever.)
A person's second assembly language is usually the most educational.  Or it should be!

Quote from: ve7xen
1. Accumulator - AVRs have 32 general purpose registers, and most instructions can use any of them as target (and source). Some are fixed though.
2. Paging - AVR has flat address space
Hmm.  Marketing talk.  AVRs have 16 general purpose registers, and an additional 16 less-general-purpose registers.  And a few (different numbers on different chips) that combine into 16-bit pointers.   And no paging until you exceed 64kB of RAM or 128kB of instructions.

Quote from: blewisjr
Also how is the AVR ASM?  Or rather maybe I mean to say how does the AVR ASM flow?
movlw  0xA1
movwf Foo
   2 instruction cycles instead of a simple
mov Foo, 0xA1
Still two instructions on an AVR.
Code: [Select]
ldi r16, 0xA1
sts Foo, r16
Assuming Foo is in RAM.  The first instruction is one of the ones where only 16 registers can be used.  The second instruction takes two words and two cycles, so IIRC the sequence is bigger than on a PIC (not counting banking.)  OTOH, since the AVR has at least 16 registers to hold the A1, you might never need the memory location Foo...
This is an architecture issue rather than an assembler issue; stuff pretty much has to move through registers on both PIC and AVR.  The PIC only has the accumulator, the AVR has more.
I think the MSP430 can do this in a single instruction.  But the instruction will be three words long and take "many" (4+?) cycles.  Aren't there common macros for doing this sort of thing on PIC?  ("movlf" was apparently standard in the Parallax PIC assembler, and widely implemented elsewhere.)

 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: PIC and AVR thinking of a switch but need more info
« Reply #34 on: March 20, 2013, 09:29:55 am »
Quote from: originalPoster
I already have a Arduino which I can use for AVR
So what are you waiting for?  Get reading, get programming.  Some things will be great, some not so great.  And you'll be in a much better position to evaluate your THIRD architecture (ARM, MSP430, MIPS, whatever.)
A person's second assembly language is usually the most educational.  Or it should be!

Quote from: ve7xen
1. Accumulator - AVRs have 32 general purpose registers, and most instructions can use any of them as target (and source). Some are fixed though.
2. Paging - AVR has flat address space
Hmm.  Marketing talk.  AVRs have 16 general purpose registers, and an additional 16 less-general-purpose registers.  And a few (different numbers on different chips) that combine into 16-bit pointers.   And no paging until you exceed 64kB of RAM or 128kB of instructions.

Quote from: blewisjr
Also how is the AVR ASM?  Or rather maybe I mean to say how does the AVR ASM flow?
movlw  0xA1
movwf Foo
   2 instruction cycles instead of a simple
mov Foo, 0xA1
Still two instructions on an AVR.
Code: [Select]
ldi r16, 0xA1
sts Foo, r16
Assuming Foo is in RAM.  The first instruction is one of the ones where only 16 registers can be used.  The second instruction takes two words and two cycles, so IIRC the sequence is bigger than on a PIC (not counting banking.)  OTOH, since the AVR has at least 16 registers to hold the A1, you might never need the memory location Foo...
This is an architecture issue rather than an assembler issue; stuff pretty much has to move through registers on both PIC and AVR.  The PIC only has the accumulator, the AVR has more.
I think the MSP430 can do this in a single instruction.  But the instruction will be three words long and take "many" (4+?) cycles.  Aren't there common macros for doing this sort of thing on PIC?  ("movlf" was apparently standard in the Parallax PIC assembler, and widely implemented elsewhere.)

I do understand what you are saying westfw.  Sure it is possible to macro it but the point remains that it is possible under a lot of circumstances on the AVR with those 16 registers to avoid having to grab a file register from ram which reduces it to 1 inst. cycle instead of 2.

Like I stated above I think it will be best at this point to do a project with both even tho I never used AVR ASM before I should be able to easily find the registers and opcodes I need to match the pic project and then I can compare the flow I was talking about myself.  There is so much info in this thread and I do greatly appreciate it marketing pitches and all.

Ultimately chip really won't matter too much when I move to C but I want to at least learn the ASM side first.  Worst case I find I can deal with the major PIC quirks and after a few projects and after I get more comfortable with the chip I can switch to AVR and learn that and then I have 2 chips under my belt.
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1672
  • Country: pl
  • Troll Cave Electronics!
Re: PIC and AVR thinking of a switch but need more info
« Reply #35 on: March 20, 2013, 09:37:26 am »
Go for ARM. Same or lower price and an order of magnitude (no overexaggeration here) jump in performance. And all necessary development tools can be had for free without restrictions and other shit like that.

Here are some prices from a microcontroller shop where i usually buy.

mcu   usd price@1   usd price @10
atmega8   $1.81   $1.69
atmega16   $4.41   $4.13
pic16f628   $2.14   $2.14
pic18f4550   $7.83   $7.34  :palm:
msp430f2011   $3.31   $3.04
lcp1111   $2.06   $1.83
stm32f100c4t6b   $2.83   $2.59
lpc1113fbd   $3.24   $2.88
I love the smell of FR4 in the morning!
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC and AVR thinking of a switch but need more info
« Reply #36 on: March 20, 2013, 10:35:17 am »
Go for ARM. Same or lower price and an order of magnitude (no overexaggeration here) jump in performance. And all necessary development tools can be had for free without restrictions and other shit like that.

Here are some prices from a microcontroller shop where i usually buy.

mcu   usd price@1   usd price @10
atmega8   $1.81   $1.69
atmega16   $4.41   $4.13
pic16f628   $2.14   $2.14
pic18f4550   $7.83   $7.34  :palm:
msp430f2011   $3.31   $3.04
lcp1111   $2.06   $1.83
stm32f100c4t6b   $2.83   $2.59
lpc1113fbd   $3.24   $2.88

Do those prices include shipping they seem over inflated from microchip you can get most chips for less then $2 usd bulk or single.  Do not know of the others.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13742
  • Country: gb
    • Mike's Electric Stuff
Re: PIC and AVR thinking of a switch but need more info
« Reply #37 on: March 20, 2013, 10:56:49 am »
For small quantities, differences in part prices are insignificant compared to differences in development effort. e.g. using what you know, quicker learning curve etc.
Also bear in mind that costs of things like voltage regulators, xtals,eeproms  etc. can add to the parts cost difference.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC and AVR thinking of a switch but need more info
« Reply #38 on: March 20, 2013, 11:16:10 am »
Well right now PIC has the leg up on learning speed because I have been tinkering with it for about a month.

As a side track what is a good place to buy uC's and other components?  I know of digikey but heard some people had issues with them.  Then there is sparkfun/adafruit but inventory at these places has limited selection.
 

Offline deephaven

  • Frequent Contributor
  • **
  • Posts: 796
  • Country: gb
  • Civilization is just one big bootstrap
    • Deephaven Ltd
Re: PIC and AVR thinking of a switch but need more info
« Reply #39 on: March 20, 2013, 11:18:22 am »
As a side track what is a good place to buy uC's and other components?  I know of digikey but heard some people had issues with them.  Then there is sparkfun/adafruit but inventory at these places has limited selection.

Which country are you in?
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC and AVR thinking of a switch but need more info
« Reply #40 on: March 20, 2013, 11:24:45 am »
USA
 

Offline deephaven

  • Frequent Contributor
  • **
  • Posts: 796
  • Country: gb
  • Civilization is just one big bootstrap
    • Deephaven Ltd
Re: PIC and AVR thinking of a switch but need more info
« Reply #41 on: March 20, 2013, 11:31:19 am »
USA

Ah OK, I'll leave it for the USA guys to give you some answers. I have a good UK source, but shipping would put them out of the running.

By the way, you probably already do this, but always make sure you read any errata sheets from the manufacturer. That can stop a lot of heartache sometimes!
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC and AVR thinking of a switch but need more info
« Reply #42 on: March 20, 2013, 11:33:21 am »
USA

Ah OK, I'll leave it for the USA guys to give you some answers. I have a good UK source, but shipping would put them out of the running.

By the way, you probably already do this, but always make sure you read any errata sheets from the manufacturer. That can stop a lot of heartache sometimes!

I agree!  I hate when there is no errata especially books.
 

Offline BravoV

  • Super Contributor
  • ***
  • Posts: 7547
  • Country: 00
  • +++ ATH1
Re: PIC and AVR thinking of a switch but need more info
« Reply #43 on: March 20, 2013, 11:43:49 am »
There's no need to use an ARM to blink a led , when a single input is toggled.
Or to display the temperature from a ds18b20 on a LCD (witch often is 5v anyway)
If you're a pro, I'm wholeheartedly agree, hell, you even have to get your hand dirty into clock by clock optimization at assembly say to do the DSP processing using the ancient 8051 if needed.  >:D

But in this topic,  especially in the context that the OP is at early stage of learning period, and in the middle of taking important decision to invest his time & energy & money and prolly tears  :'(, c'mon, currently choosing ARM platform is one of the best choice.
« Last Edit: March 20, 2013, 11:48:32 am by BravoV »
 

Offline MikeK

  • Super Contributor
  • ***
  • Posts: 1314
  • Country: us
Re: PIC and AVR thinking of a switch but need more info
« Reply #44 on: March 20, 2013, 12:11:32 pm »
As a side track what is a good place to buy uC's and other components?  I know of digikey but heard some people had issues with them.  Then there is sparkfun/adafruit but inventory at these places has limited selection.

In the U.S.?  I mostly buy from Mouser.  Sometimes Jameco.
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5018
  • Country: ro
  • .
Re: PIC and AVR thinking of a switch but need more info
« Reply #45 on: March 20, 2013, 01:17:22 pm »
I prefer Farnell, mainly due to low shipping fees to my country.  For larger orders, Digikey works fine with the minor annoyance of having to pay customs taxes and VAT when I get the package.

I've tried RS-components as well, but the shipping fees are slightly bigger than Farnell and they don't ship straight to me, they ship it to a company in the capital of the country, which then couriers packages to me, so it's just an unnecessary delay.
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
Re: PIC and AVR thinking of a switch but need more info
« Reply #46 on: March 20, 2013, 01:24:30 pm »
This thread got me looking at some of my PIC asm code. Haven't looked at it for years and years... gotta tell you, got a bit of a stiffy  ;D
 

Offline ve7xen

  • Super Contributor
  • ***
  • Posts: 1192
  • Country: ca
    • VE7XEN Blog
Re: PIC and AVR thinking of a switch but need more info
« Reply #47 on: March 20, 2013, 06:38:53 pm »
But in this topic,  especially in the context that the OP is at early stage of learning period, and in the middle of taking important decision to invest his time & energy & money and prolly tears  :'(, c'mon, currently choosing ARM platform is one of the best choice.
I'd agree, ARM is great value for money and seems to be the future. However for beginners I'm not sure it's quite there yet as far as (free) development tools are concerned. I've had a lot of difficulty figuring out how to set up linker scripts, startup code, linking a libc and other annoying and unproductive minutiae. Also the whole CMSIS library architecture is a bit over-engineered and is kind of an awkward pain to properly link and include in an IDE like Eclipse. Once working it's pretty nice to use though.

MSP430 and AVR, while perhaps less flexible, mostly handle this for you and you can go from C/ASM source -> compiler -> uC without any other scaffolding.

As far as buying chips, I find DigiKey has the best selection of ICs, but the worst prices. Mouser's prices tend to be a little better, but their selection of ICs is not as good. Future Electronics has very good prices, especially passives, but their selection is pretty slim, especially for DIP (if you're into that). For larger projects I often find it is worthwhile, even with shipping costs, to order passives, connectors and available ICs from Future and everything else at DigiKey or Mouser.
73 de VE7XEN
He/Him
 

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: PIC and AVR thinking of a switch but need more info
« Reply #48 on: March 21, 2013, 11:06:35 am »
As far as buying chips, I find DigiKey has the best selection of ICs, but the worst prices. Mouser's prices tend to be a little better, but their selection of ICs is not as good. Future Electronics has very good prices, especially passives, but their selection is pretty slim, especially for DIP (if you're into that). For larger projects I often find it is worthwhile, even with shipping costs, to order passives, connectors and available ICs from Future and everything else at DigiKey or Mouser.

What does Future charge for overnight delivery for Canucks? Do they take care of any brokerage customs crap in the price. Both Newark and Digikey do. I like Mouser as well but the 20 bucks for overnight delivery makes them my last choice and only if they have someting I can't get at Newark or Digikey.
I found Newark to be the cheapest for micro's and the majority of other stuff, you might want to check them. They charge flat rate 8 bucks overnight delivery.

To the OP a lot of the things you dislike about PIC's are not as bad or non-existent in the enhanced PI16f series or the PIC18f's. There is a command to transfer data for example register to register on 18f's movff two instruction cycles. Banking and paging overhead is reduced to one cycle in the enhanced version of the 16f's. The enhanced 16f's max clock speed is now 32MHz.

The quirks do exist in the enhanced PIC16 I am using a PIC16F1829 which is the enhanced mid-range. The enhanced mid-range architecture is just like the standard PIC10-PIC16.  I also have a PIC18F14K22 which I did not tinker around with yet but I do know it solves the screwed up banking and paging as far as I know the PIC18 still only has 1 accumulator but configuring your fuses is much easier and has hardware multiply.  Over all a better chip.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: PIC and AVR thinking of a switch but need more info
« Reply #49 on: March 21, 2013, 03:48:00 pm »
Quote
They should have just a basic fast micro with minimal peripherals.
Scenix/Ubicom tried this.  With some relative brief success, even.  But not MUCH success. (I guess "propeller" is still moving along those lines.)
I think the problem boils down to the fact that the number of engineers you can find who can implement ethernet given a shift-register and a bitslice is pretty vanishingly small.  And when you step up from 3 MHz Ethernet to 100MHz Ethernet, you can't afford the delay involved in having part of your peripheral be off-chip.

I used to work for a company that implemented a bunch of things in bitslices.  But the bitslices didn't keep up with the mainstream CPUs in terms of clock rate, and bitslice programmers were ... difficult to find.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf