PIC10F322 AD Project in Assembly, RS232

(instructions, reset, WDT, specifications...) PIC10F2xx, PIC12F5xx, PIC16F5x

Re: PIC10F322 AD Project in Assembly, RS232

Postby MMcLaren » Tue Sep 02, 2014 3:39 pm

It's a very nice demo, Tom. Thank you! And the documentation is excellent.

The 10F322 is actually a pretty interesting device. Besides all the really cool built-in peripherals, all of the SFRs and GPRs fit in a single 128 byte 'bank' so there's no bank switching. How cool is that? And it was a surprise to find a LATA register in a non "enhanced" 14-bit core device, too.

Take care. Cheerful regards, Mike
MMcLaren
 
Posts: 18
Joined: Sun Aug 31, 2014 10:08 pm
PIC experience: Experienced Hobbyist

Re: PIC10F322 AD Project in Assembly, RS232

Postby Olin Lathrop » Tue Sep 02, 2014 4:04 pm

Tom Maier wrote:Hey Olin, Why don't you post something?


OK, here is a example WAIT macro like I mentioned. This is for a PIC 10F204:

Code: Select all
////////////////////////////////////////////////////////////////////////////////
//
//   Macro WAIT  sec
//
//   Wait the indicated time from the previous instruction until the next
//   instruction is executed.  SEC is amount of time to wait in seconds.  The
//   preprocessor constant FREQ_INST must be previously defined to indicate the
//   instruction clock frequency.
//
//   The actual wait will be rounded to the nearest number of whole instruction
//   cycles.
//
//   The variable WAITCNT is trashed.
//
/var new labeln integer = 0  ;for making unique number per macro invocation

/macro wait
  /var local sec real = [arg 1] ;desired wait time in seconds
  /var local nwait integer   ;number of cycles left to wait
  /var local ii integer      ;scratch integer
  /var local r real          ;scratch floating point

  /set labeln [+ labeln 1]   ;make unique 1-N number of this macro invocation

  /set nwait [rnd [* sec freq_inst]] ;make total cycles to wait
  /set nwait [- nwait 1]     ;account for 1 cycle from previous to next instr
  /if [<= nwait 0] then      ;no cycles to wait ?
    /quitmac
    /endif

  /set r [/ nwait freq_inst] ;actual additional wait time, seconds
  /write
  /write "         ;  Wait " [eng r] "s (" nwait " cycles)"
  /write "         ;"
//
//   Do long waits by spinning in a loop.  This loop waits 3 cycles for each
//   iteration plus 4 overhead cycles.
//
  /if [>= nwait 7] then      ;at least one iteration to wait ?
    /set nwait [- nwait 4]   ;account for loop entry/exit overhead cycles
    /set ii [div nwait 3]    ;determine number of loop iterations
    /set nwait [- nwait [* ii 3]] ;update cycles left to wait
    /if [> ii 255] then      ;too many iterations for this algorithm ?
      /show "  Wait time of " [eng sec] "s is too long for the WAIT macro"
         error   Wait
         end
      /stop
      /endif
         movlw   [and [+ ii 1] 16#FF]
         movwf   waitcnt
waitloop[v labeln]
         decfsz  waitcnt
         goto    waitloop[v labeln]
    /endif
//
//   Wait two cycles at a time by using GOTO $+1
//
  /block
    /if [< nwait 2] then     ;not enough cycles left for this method ?
      /quit
      /endif
         goto    $+1
    /set nwait [- nwait 2]
    /repeat
    /endblock
//
//   Wait the remaining cycles by explicit NOPs.
//
  /block
    /if [<= nwait 0] then    ;no cycles left to wait ?
      /quit
      /endif
         nop
    /set nwait [- nwait 1]
    /repeat
    /endblock
  /endmac


This uses the macro facility and other features of my preprocessor. That's easier for me to write and results in a more flexible macro, but something similar could have been done with bare MPASM too. My preprocessor is available for free, and is documented at http://www.embedinc.com/pic/prepic.txt.htm.

Here is code that tests various waits:

Code: Select all
         wait    1e-6
         wait    2e-6
         wait    3e-6
         wait    4e-6
         wait    5e-6
         wait    6e-6
         wait    7e-6
         wait    8e-6
         wait    54e-6
         wait    771e-6


And here is the MPASM code resulting from the WAIT invocations above:

Code: Select all
         ;  Wait 1.00 us (1 cycles)
         ;
         nop

         ;  Wait 2.00 us (2 cycles)
         ;
         goto    $+1

         ;  Wait 3.00 us (3 cycles)
         ;
         goto    $+1
         nop

         ;  Wait 4.00 us (4 cycles)
         ;
         goto    $+1
         goto    $+1

         ;  Wait 5.00 us (5 cycles)
         ;
         goto    $+1
         goto    $+1
         nop

         ;  Wait 6.00 us (6 cycles)
         ;
         goto    $+1
         goto    $+1
         goto    $+1

         ;  Wait 7.00 us (7 cycles)
         ;
         movlw   2
         movwf   waitcnt
waitloop8
         decfsz  waitcnt
         goto    waitloop8

         ;  Wait 53.0 us (53 cycles)
         ;
         movlw   17
         movwf   waitcnt
waitloop9
         decfsz  waitcnt
         goto    waitloop9
         nop

         ;  Wait 770 us (770 cycles)
         ;
         movlw   0
         movwf   waitcnt
waitloop10
         decfsz  waitcnt
         goto    waitloop10
         nop


Note that the deliberate wait inserted between instructions is one cycle less than the time specified in the WAIT parameter. This is because it always takes at least one cycle to get from one instruction to the next.
User avatar
Olin Lathrop
Verified identity
 
Posts: 48
Joined: Fri May 30, 2014 3:38 pm
Location: Littleton, MA USA
PIC experience: Professional 5+ years with MCHP products

Re: PIC10F322 AD Project in Assembly, RS232

Postby Tom Maier » Tue Sep 02, 2014 4:31 pm

Olin,

I want you to pick a processor you have never seen before, from a family you have never seen. How about the Atmel tiny?

Use a ide you have never tried. How about studio?

With a programmer you just got that day in the mail.

Come up with a small project to teach yourself C (since you mostly seem to know assembly).

Make all documentation (schematics, description, proofs).

Write the code and use proper headers for the moudles with comments on every line.

Build the prototype.

Test your code.

Test the electrical stabilty of the design.

Post it here in two days.

I shall be awaiting here to critique your work. It damn well better be good :lol:

I've been trying to add some content to this forum, but it seems to have devolved into whinning. I challenge other people to try doing something constructive and stop playing around. Otherwise, this forum is slowly dying. What can you contribute?
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: PIC10F322 AD Project in Assembly, RS232

Postby Tom Maier » Tue Sep 02, 2014 4:43 pm

MMcLaren wrote:The 10F322 is actually a pretty interesting device. Besides all the really cool built-in peripherals, all of the SFRs and GPRs fit in a single 128 byte 'bank' so there's no bank switching. How cool is that? And it was a surprise to find a LATA register in a non "enhanced" 14-bit core device, too.

Take care. Cheerful regards, Mike


It also has an 8 deep stack, so it's pretty much a mid range pic16 with size of a pinhead. I just can't believe it. I still haven't had an application for it yet, but I'm ready if it happens. I just had to see a 6 pin micro run.

I ordered a dozen of the new pics to try them out; pic12, pic 24, pic32... On all the others I used the XC compilers, but I used asm on this one because I have a fear that the C will consume what precious little resources this chip has. I've been out of microchip for 12 years so everything is "new again" for me in their product line. I like what I see.

It would be interesting to try the unoptimzed C and see what it can do on this small architecture.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: PIC10F322 AD Project in Assembly, RS232

Postby Olin Lathrop » Tue Sep 02, 2014 4:56 pm

Tom Maier wrote:I want you to pick a processor you have never seen before, from a family you have never seen. How about the Atmel tiny? Use a ide you have never tried. How about studio?


This is a PIC forum, and you show yourself as being a professional with 5+ years PIC experience. You are judged here within that context. You didn't say until later that all this was new to you. If you want slack for not being a expert at something, you should say so up front, especially when your profile proclaims differently.

Of course the flip side is that if you're not good at something yet, you probably want to wait a little before posting a example for newbies to take as being done by a expert. It's understandable that the first code on an new machine with new tools will have a few issues, but then you shouldn't be holding it up as a example for others to follow. You can't have it both ways.

What can you contribute?


Did you look at the macro I posted? I stand by that as a pretty good example of how to automate such things. It's also a example of using my preprocessor to get much more powerful macro capabilities than MPASM has. I think everyone should be using the preprocessor and writing code like that. There are many man-weeks of effort behind the preprocessor, but I make it freely available.
User avatar
Olin Lathrop
Verified identity
 
Posts: 48
Joined: Fri May 30, 2014 3:38 pm
Location: Littleton, MA USA
PIC experience: Professional 5+ years with MCHP products

Re: PIC10F322 AD Project in Assembly, RS232

Postby Tom Maier » Tue Sep 02, 2014 5:04 pm

Oilin,

I've designed dozens of commercial products with microchip products. And with many other processors.

You do realize that microchip is more than 12 years old right?

If you are unfamilar with the pic10f322, then please read the data sheet and stop making such a fool of yourself.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: PIC10F322 AD Project in Assembly, RS232

Postby Joseph Watson » Tue Sep 02, 2014 5:07 pm

I liked your project, Tom.

I don't remember you saying that it was presented as a good example for newbies to follow. I would say that even a newbie can read that this was done in a hurry and so would be less likely to believe everything shown to be the best way to have done it. I do not believe that any method of generating code to the be the "best" way possible. Our skills and habits change all the time. The important thing was that you managed to get it to work which was clearly your intended goal.

Crossing the finished line 2 days after the starting gun while working with a new chip is a pretty good trick in my book. I read between the lines that you were actually having a lot of fun doing it and that is an important part of this activity.
NCR once refused to hire me because I was too short. I'm still waiting on my growth spurt.
User avatar
Joseph Watson
 
Posts: 49
Joined: Sat May 31, 2014 8:06 pm
Location: Ohio, USA
PIC experience: Experienced Hobbyist

Re: PIC10F322 AD Project in Assembly, RS232

Postby Tom Maier » Tue Sep 02, 2014 5:43 pm

Positive critisism is welcome, but derogatory comments will recieve return fire. I have a low tolerance for that kind of thing. Mike spotted the timing issue and even re-coded it, and that's great.

Olin may not mean it, but his tone is very offending. He has also had this issue on the microchip site from what I understand. He probably doesn't mean to come off that way, but that is just the reality of it. What he is doing will discourage anybody from posting anything in the future.

I'm a professional designer and coder, so I have very little to give away to hobbiests. I don't design for fun, it's how I make a living. I just happened to heavily document this learning experience and nobody owns it, so I dumped it here.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: PIC10F322 AD Project in Assembly, RS232

Postby jtemples » Tue Sep 02, 2014 6:22 pm

Tom Maier wrote:It would be interesting to try the unoptimzed C and see what it can do on this small architecture.


I can't speak for the unoptimized version of the compiler, but I've done a couple of 10F200 projects (256 words flash/16 bytes RAM) with the Hi-Tech compiler. The generated code was very efficient.
jtemples
Verified identity
 
Posts: 173
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: PIC10F322 AD Project in Assembly, RS232

Postby Joseph Watson » Tue Sep 02, 2014 6:39 pm

Many years ago, it became clear that my technical intuition was quicker than most and tended to be more accurate with regard to what could and what could not be done in many of our company's equipment designs. In brainstorming meetings, I was always quick to pounce on ideas put forth by others that I could see would not work. One day, my supervisor took me aside after such a meeting and pointed out that my approach was offending others. He told me that I needed to learn to be tactful. It wasn't that I needed to not speak up about ideas that could not work but at least to be much gentler about how I went about it.

I tried to learn that when someone else puts forth an idea that could not work, the best approach was to ask a line of questions that would lead that person to see the fault in their own ideas. It took a little longer but it surely kept a lot of people from developing a hate for me. Along the way, it would help the other person gain some insight and it also gave me a little time to better develop my own ideas.

In the long run, what I brought to the table with technical intuition was well more than matched by the advanced educations of the others. Over the years, I learned a lot by working with people who really knew what they were talking about. Most of them were quite tactful about how they treated me. We all taught each other as we went along. We all learned that nobody has the only answer or even the best answer to a problem because there are so many different dimensions along which "goodness" can be measured. Together we made a wonderful team of engineers and the magic flowed out.

Now, decades later, some of us who are still alive get together once a month for lunch and to talk about what's new and what once was.
NCR once refused to hire me because I was too short. I'm still waiting on my growth spurt.
User avatar
Joseph Watson
 
Posts: 49
Joined: Sat May 31, 2014 8:06 pm
Location: Ohio, USA
PIC experience: Experienced Hobbyist

PreviousNext

Return to 12-Bit Core

Who is online

Users browsing this forum: No registered users and 1 guest

cron