1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Microcontroller Tutorial is up!

Discussion in 'Modding' started by Hazer, 30 Aug 2003.

  1. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    I dont have the greatest experience with a ton of programmers, mostly just the JDM programmer and the ICProg software.

    If you try to program a Pic and the verification fails, theres 2 causes: It never was programmed, or the code had the 'code protection' bits set.

    Im guessing, but it sounds that maybe the reason why your programmer wont program the chips is that it uses low-voltage programming. The typical way a JDM design works is to apply 13V to the MCLR pin. In the 16F series, it is possible to set a configuration bit for low voltage programming (where you only need 5V on MCLR) but the only way to change those config bits is through first programming in 13V mode. If the chips come from the factory with those bits turned off, and your programmer only does low-voltage programming, then your going no-where. But this is just a guess.

    If you want, Ill need more information:
    Programmer maker and model number.
    Software used and connection type(serial/parallel/USB).
    Chip model your attmepting to program and package type.
    History of the chip your programming (brand-new or previously programmed by you).
     
  2. MechWarrior

    MechWarrior What's a Dremel?

    Joined:
    13 Oct 2003
    Posts:
    55
    Likes Received:
    0
    Nice tutorial! Whens an update?
     
  3. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    Im hoping to get 1 to 2 sections up per week. Im working on a couple of projects, and trying to fix my oscilloscope.

    I should have some new stuff up in a couple days.
     
  4. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    New section: HD44780 LCD example introduction and code. Within a week I will have advanced info for interfacing the HD44780, incuding 4x40 interfacing and some theoretical VFD interfacing (VFD w/ HD44780 compatable pinout).


    PS: Has anyone scrolled down the topmost banner?
     
  5. Smilodon

    Smilodon The Antagonist

    Joined:
    25 Mar 2003
    Posts:
    6,244
    Likes Received:
    102
    ...and empty soda cans? :hehe:
     
  6. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    New sections:

    Detailed HD44780 stuff, and moving into the analog peripherals using the Capture module to measure fan RPM. The Capture module part is good just for learning some particulars on how the fan sense line works and how to use it.

    Coming soon: PWM fan control, ADC voltage sensing, stepper motor control, and 2/3 wire communication.
     
  7. relix

    relix Minimodder

    Joined:
    14 Nov 2001
    Posts:
    5,948
    Likes Received:
    41
    I just want to say the ADC part is great (just like the whole tutorial btw ;)) :thumb:

    The circuit-diagram saves me the trouble of finding out how to make it work. Do you also know if the ADC actually gives a good result (accuracy?). I heard some things about the built-in ADC that it doesn't work that well.
     
  8. The Bodger

    The Bodger What's a Dremel?

    Joined:
    26 Dec 2003
    Posts:
    421
    Likes Received:
    4
    Excellent job Hazer! :thumb:

    The web has needed an introductory course like this for a long time. I especially like the mathematics section; extremely useful, and would have saved me hours last year when I ended up writing my own 16 x 16 bit multiply routine. This should be a great starting place for any new PIC users.

    My recomendation to bit - tech forum: add a link to Hazers page in the useful links sticky thread in the Electronics forum

    My recomendations to Hazer:
    1) Any chance of using a more eye - friendly / printer friendly colour scheme? Became hard to read after afew mins, due to eye strain!

    2) Adding a separate 'Links' section would be useful, pointing to improtant places such as download centre for IC Prog, MPLAB, etc, and other useful PIC reference centres on the web such as www.piclist.com. (One of my favourites - if your'e lazy, the automatic delay calculator and constant multiplier routine generator in the Source Code Library are very useful!)

    2) Keep up the great work!! :thumb:


    Additional: www.farnell.co.uk sell virtually all PIC mircocontrollers in the range. EPE (Everyday Practical Electronics) magazine, http://www.epemag.com/ available in USA and UK, (see UK mirror link for UK) has a PIC related project virtually every month - great way to get new ideas. Take a quick look through the past projects section if you want to see whether it is for you.
     
  9. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    Thanks guys. All feedback is helpful.

    Relix: I tested the circuits before posting them. Using the example provided, I originally had a 120mV difference from 2 DMMs. Using the op-amp helped get rid of it. Even still, the Pic was exactly 120mV offset, throughout 5-12V difference. I think its pretty good. Resolution is the only concern, and that all depends on how much your willing to code in order to get it.

    For example: Say you want to measure from 0V to 12V. You can first use a 20k|100k Ohm resisatnce voltage divider plugged into an op-amp. Then use a 3V reference voltage. Using 10bit results instead of 8 bits, you get a resolution of 3mV per bit sampling. But in order to calculate the real voltage, you multiply the result by 5, giving real-world resolution of 15mV steps.

    The Bodger: Im running this sight of the meager space given to me by my ISP. The whole thing is self written in HTML. I have a bud who said he would do a professional site if I asked. I was considering it, but first I would need to pay for a real bandwidth site and register a domain. That is in the future (hopefully short future). I preffer the dark background, but hadn't given printing that much thought. Im open to suggestions about the color scheme. Ill start working on the links section this weekend.

    More electronics part coming soon. Temperature sensing using external voltage refference on the way.
     
  10. LukR

    LukR What's a Dremel?

    Joined:
    11 Oct 2003
    Posts:
    43
    Likes Received:
    0
    Nice tutorial:)
    hope you got a job, and this is the cause of the delay:)

    I have a question: not exactly to your tutorial, but: What is the cheapest way to erase an UV-eraseable-PIC? Buying an eraser would be expensive, and i wouldn't use it much anyway. Especially, it would be cheaper to buy atmel's similar IC with flash&built in eeprom.
     
  11. acrimonious

    acrimonious Custom User Title:

    Joined:
    8 Nov 2002
    Posts:
    4,060
    Likes Received:
    3
    You could leave it outside for a long time (no, that really does work!)

    Or you could go to a sun-bed shop (like i did once with PCB's :baby: )

    Or you could buy a bunch of UV Leds or a UV cold cathode and use that.
     
  12. LukR

    LukR What's a Dremel?

    Joined:
    11 Oct 2003
    Posts:
    43
    Likes Received:
    0
    Thanks, just asked because i heard/read it needs specific wave length, most UV led/cathodes don't work, but buy our fine quartz lamp for~40€


    10^27LOL :clap: :jawdrop:



    other question (if you don't mind Hazer):
    Is it possible to add external program memory to a PIC16C745? It has no internal flash or EEPROM, so it would be much easier to use an external eeprom for storing programs during development.

    I know the theory, but had not found anything in its datasheet.

    edit: Microchip has no PIC with FLash&USB port right now, and local Atmel distrib had only the 89c5132 in 80pin VQFP package. No thanks, i have no SMD facility :D
     
  13. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    Just to make sure: You do know that the PIC16FXXX family has flash program memory and internal EEPROM, right?

    But onto the other questions: You can easily hook up parallel EEPROM to any PIC that has at least one 8bit port. Or, you can use a serial EEPROM (24LCXXX series) and either use I2C thats built-in to the PIC, or bit-bang it on any 2 I/O pins.

    If your looking for stored data (not something that gets modified), you can always use some of the program memory as data storage and retrieve it using a look-up table that basically uses unused program memory by writing a bunch of RETLW instructions.

    I recently got an engineering job (that I will be using PICs to do automation) and have neglected the tutorials a bit. Im hoping to continue very soon. I should sit-down this weekend and bang-out some things Ive already done like I2C commands, look-up tables, internal EEPROM writing/reading, and other such things. Soon to be coming will be RS232 interfacing and also RS-485 multi-device bus. Maybe even some MODBUS protocols.

    When I have a spare moment, Im working on a interface to a VFD I bought. Its interface is simply to read.write just like an EEPROM. Im creating a controller to give it general commands like Erase display, Write text, Adjust brightness, etc etc. Im about ready to do the serial interface, but I dont have much VB experience. Anyone know a program that I can use to easily manipulate the COM or parallel port in windows?
     
  14. LukR

    LukR What's a Dremel?

    Joined:
    11 Oct 2003
    Posts:
    43
    Likes Received:
    0

    Thanks for your answer, and it's good to hear that you got a job:)

    Yes, i know that about pic16Fxxx-s, but my question was a bit off-topic: i have a 16C745 . That is either OTP, or UV eraseable, with no internal eeprom.
    It has a USB interface, and simply it would be faster/easier to program an eeprom online instead of UV-erasing the pic. (read the mid-range manual's pg. 516, so it can be altered a bit without erasing).

    Hooking up a serial or paralel eeprom should be no problem, maybe some datasheet reading. But i want to use the external eeprom as code memory, not data. Execute the program from the eeprom.


    edit: /me sleepy. so i want to upload the program to the external eeprom, and just put a
    JMP <external memory address>
    in the PIC's program memory. I know, it would be slower, but would it work?
     
    Last edited: 9 Apr 2004
  15. kbn

    kbn What's a Dremel?

    Joined:
    17 Mar 2004
    Posts:
    603
    Likes Received:
    0
    Nice tutorial.
    Can you explain more about the programmers, what does JDM mean? Would anyone be able to make me a programmer or point me to somewhere selling them (Im in UK).

    Can PIC's be used to convert parellell lcd's to serial ones so LCDC can be used to run them? or could a pic be used to write to a graphic lcd?

    I have some very basic assembler (X86/DOS) knowledge and I find the programming parts of the tutorial are very easy to understand :)
     
  16. nleahcim

    nleahcim What's a Dremel?

    Joined:
    22 Apr 2003
    Posts:
    550
    Likes Received:
    1
    Though I haven't gotten a chance to look at the tutorial in depth (as i'm learning AVR ASM right now) - my one suggestion for you is that you need to change how it looks! First of all - lose the frames. Please for the love of all that is holy. Go to every single famous webpage on the internet - you probably won't find one site with frames (iframes don't count!) there's a reason for this! They're awful - though so tempting to use. Also the colors are not the best - and you should use a different font. All of this is very easily remedied though - and from what I did look at it looked great and I added a bookmark for future use! Thanks! :thumb:
     
  17. Starbuck3733T

    Starbuck3733T Look out sugar, here it comes

    Joined:
    16 Sep 2002
    Posts:
    920
    Likes Received:
    0
    The tutorial made for a good refresher course (haven't used my ASM skillz in about 4 years) and a good conversion over to the PICs way of doing things. I'm used to the Hitach H8, and I rather like the way the pic does things. The huge amount of GPRs makes things nice, although the H8s I used did have it beat on shear # of onboard peripherals.

    Anyway, a few fixes:
    Check your links to your example .txt files, they're using the backslash (\) when they should be using the forward slash (/). I caught it and was still able to use the tutorial. This may only effect people browsing with Mozilla.

    And a question:
    On the H8, the timer interupt (I don't remember hwat it was called, doesn't matter) fired off when the counter matched the value in the counter register. The 16F872's documentation says the interupt fires when the time overflows... This seems rather silly to me. Let me see if I'm getthign this right

    Timer0 is 8 bit, has interuptting ability when it rolls from 0xFF to 0x00. TMR0 loads the timer with a value. say I want the interupt to fire when the timer reaches 55d(ecimal), so I load TMR0 with 200d so it has 55 to count before it pops its interupt? :confused:

    Very cool tutorial! I'm ordering a pic programmer (so much easier to know the chip isn't being programmer correctly when you know the hardware is good) and am looking forward to diving in headfirst!

    Do you have any recommendations on either a DIY or kit prototyping board for the PICs?
     
  18. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    Yes. Also remember that the TMR0 can use both prescaler and postscaler settings, so your not just limited to 256 cycles. Also, if yuo wanted to do things like th H8, you can setup the CCP module in compare mode which does the same thing you described with TMR1 (16bit). Since I couldnt really find any application that couldnt be done with the other timers, I skipped the Compare mode in the tutorial.

    You can find a $12USD JDM programmer on Ebay from the seller pha555. This guy is P.H.Anderson. He is a Massachusettes Professor in Electrical Engineering, and has his own website for programming PICs. The programmer is the Olimex PG2C. Alternately, I provided a schematic on the tutorial page so you could build or even breadboard one up yourself. Ive built 2 so far myself and they seem really easy.

    Im not a webpage designer, Im sorry. :sigh: I promised people that the design would be done very simply (HTML). This allowed 2 things: Faster writing of the tutorial so people could get started, and also easy on 56k people. The color scheme is just my own personal prefference. A subtle grey, with brighter colors to differentiate/extenuate the important parts. Ive been told more than once that it is not easy on the eyes. Im sorry about that. I once changed it lighter collors (what Ive seen everyone else do) and then I personally had trouble reading it in daylight (glare). So I ditched the changes. Once I have some free money to get a domain and unlimited space/bandwidth, I know someone who is great at unique yet pleasing designs who offered to do some work on this site.

    earlier in this thread, I found some preliminary UK online sites that sell the Olimex PG2C (what I use). JDM is just the name of the freely distributed programmer design. I cant remember exactly what the JDM initials stand for. Whats important about it is that it uses the serial ports RS-232 +15 to -15V swing to provide the 13V programming voltage so you have no need to hook-up and external power supply when you program your PIC.

    It would be very easy to use a PIC as a parallel-to-serial interface. Unfortunately, I havent gotten around to writing chapters on using the USART. But basically, making a serial interface for LCDC would be relatively easy to convert over to a parallel LCD interface. I may get around to doing just that, but it will be some time yet. Tell me which LCD you have.

    I just looked over Pg516 to make sure what you are reffering to. Look back over it carefully. It says that you can program a OTP device twice. But twice only. This is because a blank instruction is 0x3FF. OTP devices come with all 1's in the program memory. Once you program code in, the 0's stay forever. But you can use the trick on pg.516 by simply erasing all previously programmed code into nop's (0x000) and using the blank program space to write new code. So effectively, you only can write twice using this trick. It can also be done with UV parts, but same restriction applies, only twice and then you HAVE to UV erase it.

    What I beleive you want to do is a boot-code. This is where you write a code when the PIC boots up that will actively search an external memory source for new code to self-program. If it finds it, it then goes through the process of retrieving new code and programs itself using its internal EEPROM registers. By setting unique addresses for the internal EEPROM, it writes new instructions into the program memory. Once your new code is in place, it starts to execute it and stays there even after reset/power off (unless you have new code available in your external memeory source). Unfortunately, this only works with 16F devices. Im familiar with the 16C745. I want to play with USB myself. But OTP and UV parts are out of the scope of this tutorial. They were meant for final designs and people with enough money to throw away dozens of these parts at whim. Microchip will have a 18F chip out (hopefully soon) that uses the same USB peripheral. And if your gonna be using USB protocols, I would recommend this device over the 16C745 for three reasons: Flash reprogrammability, faster MIPS (40MHz), and more instructions voer the 16 family so that you can keep up with the USB speeds and be able to do block reads/writes.

    If your set on the 16C745 for now, Google it up or check piclist.com for some better info. Unforunately, Im waiting for the 18F chips before I play around with USB.
     
  19. ConKbot of Doom

    ConKbot of Doom Minimodder

    Joined:
    2 Jul 2003
    Posts:
    2,160
    Likes Received:
    6
    very nice tutorial hazer, but I have one question, In the math section, using subtraction as an example, you borrow using a borrow subroutine, but you goto that subroutine, and at the end of the subroutine, there is a return. if you want to go back from where you came, shouldn't you call the subroutine instead of using a goto?

    Just confused there.

    As for the color scheme, its ok, just on the lefthand side, the topic names/links are hard to read, it would be better if they were lighter, everything else is fine.
     
  20. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    The whole subroutine is a called function. Depending on how the borrow is implemented, there are 3 ways to return from the subroutine altogether. In other words, the goto's are used to skip certain aprts that wont be needed in case of a borrow.

    You call the subtraction routine by using:

    call D_sub

    Maybe this would help:

    Code:
    ;Double precision subtraction (16bit)***********
    ;
    ;	ACCb - ACCa -->  ACCb
    ;
    ;********************************************************
    
    D_sub
    		movf		ACCaLO, w  
    		subwf		ACCbLO, f   ;subtract a from b
    		btfss		STATUS, C  ;C is clear for a borrow
    		goto		Borrow
    		movf		ACCaHI, w   ;no borrow, so subtract 
    		subwf		ACCbHI, f    ;highbytes and return
    		return
    Borrow		incfsz		ACCaHI, w  ;add 1 to 'a' to subtract
                                                                        ; one more
    		goto		Borrowlo     ;If adding 1 to 'a' causes
                                                                       ; a rollover, then highbyte
                                                                       ;will be equal to what b is 
                                                                       ;now
    		bcf		STATUS, C  ;and we clear 'C' to 
                                                                        ;indicate 16bit borrow
    		return
    Borrowlo	             subwf		ACCbHI, f    ;otherwise we continue
    		return                                  ;the subtraction

    Lets look at this. If subtracting 'a' from 'b' causes a borrow, then the Carry bit in STATUS will be cleared. The btfss will skip the 'goto Borrow' instruction if there is no borrow and subtracts the highbytes and returns.

    If there is a borrow, we goto the 'incfsz ACCaHI, w'. We need to take one more from 'b' hgihbyte. So I incremment the 'a' highbyte once and throw it into the work register. But what if ACCaHI is 0xFF? Adding one to it will roll it over to zero. We need to test that, and if that one case is true, the result from subtracting the highbytes would come out to equal what ACCbHI was beforehand. But we also need to indicate that a 16bit borrow occured so we clear that manually before returning.

    If adding one to ACCaHI does not result in a rollover, we simply continue the highbyte subtraction and return from there.
     
    Last edited: 10 Apr 2004

Share This Page