1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

PIC PWM outputs?

Discussion in 'Microcontrollers' started by Andy1845c, Nov 25, 2007.

  1. jeremygaughan

    jeremygaughan New Member

    Joined:
    Sep 26, 2007
    Messages:
    129
    Likes:
    1
    Location:
    Hot Springs, AR
    Here's a code that you can put a led with a resistor on any of the PORTB bits. I put it on bit3 like you are already using. In the code there is a place that says
    movlw 0x44
    movwf runn
    If you change this value the time it takes to fade changes. As is it fades out a few times a second. Something I noticed when writing this code is that leds do not light up in a linear fashion. You have to have an exponential increase in the PWM to get an even fade. This code if really long for what it does, but I hope it's easy to follow and does what you want. I also put a circuit that shows how to put the led. The short leg/the flat side is the - side.

    Code (text):
    ;andy fade some lights


        list P=16f628a
    #include <p16f628a.inc>
        __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CP_OFF
        ERRORLEVEL -302
       
        cblock      20h
        BH,BL,wait,del_clk1,del_clk2,run,runn
        endc
       
        bsf STATUS,RP0      ;bank 1
        movlw   0x00
        movwf   TRISB       ;make all outputs
        bcf STATUS,RP0
       
        movlw   0x07        ;turn off comparitors
        movwf   CMCON
       
        movlw   0x44            ;adjustment for speed of fade
        movwf   runn
       
    start
        call    firstt
        call    secondd
        call    thirdd
        call    fourthh
        call    fifthh
        call    sixthh
        call    seventhh
        call    eighthh
        call    ninthh
        call    tenthh
        call    ninthh
        call    eighthh
        call    seventhh
        call    sixthh
        call    fifthh
        call    fourthh
        call    thirdd
        call    secondd
        goto    start

    firstt
        movf    runn,0
        movwf   run
    first
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x01        ;set on time of duty cycle
        movwf   BH
    loop
        decfsz  BH,1        ;count down the on time
        goto    loop
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x01        ;set off time of duty cycle
        movwf   BH
    loop2
        incfsz  BH,1        ;count up to the off time
        goto    loop2
        decfsz  run,1   ;run the PWM for a moment
        goto    first
        return
       
    secondd
        movf    runn,0
        movwf   run
    second
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x03        ;set on time of duty cycle
        movwf   BH
    loopa
        decfsz  BH,1        ;count down the on time
        goto    loopa
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x03        ;set off time of duty cycle
        movwf   BH
    loop2a
        incfsz  BH,1        ;count up to the off time
        goto    loop2a
        decfsz  run,1   ;run the PWM for a moment
        goto    second
        return


    thirdd
        movf    runn,0
        movwf   run
    third
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x05        ;set on time of duty cycle
        movwf   BH
    loopb
        decfsz  BH,1        ;count down the on time
        goto    loopb
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x05        ;set off time of duty cycle
        movwf   BH
    loop2b
        incfsz  BH,1        ;count up to the off time
        goto    loop2b
        decfsz  run,1   ;run the PWM for a moment
        goto    third
        return



    fourthh
        movf    runn,0
        movwf   run
    fourth
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x07        ;set on time of duty cycle
        movwf   BH
    loopc
        decfsz  BH,1        ;count down the on time
        goto    loopc
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x07        ;set off time of duty cycle
        movwf   BH
    loop2c
        incfsz  BH,1        ;count up to the off time
        goto    loop2c
        decfsz  run,1   ;run the PWM for a moment
        goto    fourth
        return

       
    fifthh
        movf    runn,0
        movwf   run
    fifth
        movlw   0xff
        movwf   PORTB       ;turn on leds      
        movlw   0x09        ;set on time of duty cycle
        movwf   BH

    loopd
        decfsz  BH,1        ;count down the on time
        goto    loopd
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x09        ;set off time of duty cycle
        movwf   BH
    loop2d
        incfsz  BH,1        ;count up to the off time
        goto    loop2d
        decfsz  run,1   ;run the PWM for a moment
        goto    fifth
        return


    sixthh
        movf    runn,0
        movwf   run
    sixth
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x11        ;set on time of duty cycle
        movwf   BH

    loope
        decfsz  BH,1        ;count down the on time
        goto    loope
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x11        ;set off time of duty cycle
        movwf   BH
    loop2e
        incfsz  BH,1        ;count up to the off time
        goto    loop2e
        decfsz  run,1       ;run the PWM for a moment
        goto    sixth
        return
       
       
    seventhh
        movf    runn,0
        movwf   run
    seventh
        movlw   0xff
        movwf   PORTB
        movlw   0x17        ;set on time of duty cycle
        movwf   BH
    loopf
        decfsz  BH,1        ;count down the on time
        goto    loopf
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x17        ;set off time of duty cycle
        movwf   BH
    loop2f
        incfsz  BH,1        ;count up to the off time
        goto    loop2f
        decfsz  run,1   ;run the PWM for a moment
        goto    seventh
        return
       

    eighthh
        movf    runn,0
        movwf   run
    eighth
        movlw   0xff
        movwf   PORTB
        movlw   0x25        ;set on time of duty cycle
        movwf   BH
    loopg
        decfsz  BH,1        ;count down the on time
        goto    loopg
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x25        ;set off time of duty cycle
        movwf   BH
    loop2g
        incfsz  BH,1        ;count up to the off time
        goto    loop2g
        decfsz  run,1   ;run the PWM for a moment
        goto    eighth 
        return
       
       
    ninthh
        movf    runn,0
        movwf   run
    ninth
        movlw   0xff
        movwf   PORTB
        movlw   0x35        ;set on time of duty cycle
        movwf   BH
    looph
        decfsz  BH,1        ;count down the on time
        goto    looph
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x35        ;set off time of duty cycle
        movwf   BH
    loop2h
        incfsz  BH,1        ;count up to the off time
        goto    loop2h
        decfsz  run,1   ;run the PWM for a moment
        goto    ninth  
        return
       
       
    tenthh
        movf    runn,0
        movwf   run
    tenth
        movlw   0xff
        movwf   PORTB
        movlw   0x50        ;set on time of duty cycle
        movwf   BH
    loopi
        decfsz  BH,1        ;count down the on time
        goto    loopi
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x50        ;set off time of duty cycle
        movwf   BH
    loop2i
        incfsz  BH,1        ;count up to the off time
        goto    loop2i
        decfsz  run,1   ;run the PWM for a moment
        goto    tenth
        return
        end
     

    Attached Files:

  2. bananasiong

    bananasiong New Member

    Joined:
    Mar 7, 2006
    Messages:
    1,893
    Likes:
    7
    Location:
    Malaysia
    Hi,
    Why isn't it working? Is the LED turned on? Have you seen anything on RB3 using oscilloscope?
     
  3. Andy1845c

    Andy1845c Active Member

    Joined:
    Apr 2, 2006
    Messages:
    1,164
    Likes:
    8
    Location:
    Southern Minnesota
    Hey, thanks for the code. It does work. It dosn't seem to fade down as far as I want to go, but i'll play with it.

    What needs to be changed in order to use a 16F628 code on a 16F628A? I thought the two were interchagable to a point?

    bananasiong, I never bothered putting the scope on RB3. I guess i could try it though.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Gayan Soyza

    Gayan Soyza Active Member

    Joined:
    Oct 23, 2006
    Messages:
    1,821
    Likes:
    19
    Location:
    Colombo

    Hi andy whats your plan for smaller pics i'm using crude delay loops.working well.But the code gets bigger to do a smooth fade:D

    BTW if you have problem with PIC's to do a PWM until you learn why not try with a simple opamp.

    http://hw.metku.net/colorfade/index_eng.html
     
  6. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,022
    Likes:
    317
    Location:
    Brisbane Australia
    The only difference, as far as I'm aware, is the config value. As long as you use the labels then it will either throw up an error or will work correctly. This is why I hate seeing hex values in config statements.

    The line posted earlier be Jeremy has a slight mistake,
    Code (text):

    __config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _[COLOR="Red"]DATA[/COLOR]_CP_OFF & _CP_OFF
     
    I added the bit in red.

    Also, the config above has both the internal oscillator and MCLR off. This is not recommended and you should probably turn MCLR on to prevent programming problems.

    Mike.
    Edit, I just noticed you posted the code above and your config is fine the way it is.
     
  7. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    An observation.

    It is good to know assembler and the details of the hardware but maybe it is better to start with a high leve language like C.

    For a person who does not know how to program the task of learning hardware + assembler + logic of the task at hand, may be too much.

    If you find that the C code I posted earlier is understandable, I could provide a working example for the 18F1320 (Microchip C18 compiler).
     
  8. jeremygaughan

    jeremygaughan New Member

    Joined:
    Sep 26, 2007
    Messages:
    129
    Likes:
    1
    Location:
    Hot Springs, AR
    Andy the code to fade the lights doesn't fade the PWM all the way down to zero but that would be easy to fix. Change the "duty cycle values" The closer to zero the darker it gets. Remember when you change them that the leds light up in an exponential fashion.

    The header of the code I used was taken from another code. When I got errors from MPLAB I changed them until they stopped showing errors. (pretty scientific huh) I'm still learning about how to write code properly. Actually I wanted the internal oscillator turned on but I don't understand the data sheet so well. I tried to fix the header. Hopefully someone who knows will double check it. Really I don't know the secret to get the code from one pic to the other is. What I did was steal a header from a code that I know works and then I copied it into my code. In the rest of the code and circuit I use the datasheet to make sure the ports and bits are all assigned properly and wired correctly.

    Here is a new code with two switches. They change the speed of the fade when you turn them on (close the switch). Also I put a revised circuit. I hope this helps.

    Code (text):
    ;andy fade some lights


        list P=16f628a
    #include <p16f628a.inc>
        __config _INTOSC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _DATA_CP_OFF & _CP_OFF
        ERRORLEVEL -302
       
        cblock      20h
        BH,BL,wait,del_clk1,del_clk2,run,runn
        endc
       
        bsf STATUS,RP0      ;bank 1
        movlw   0x00
        movwf   TRISB       ;make all PORTB outputs
        movlw   0xff
        movwf   TRISA       ;make all PORTA inputs
        bcf STATUS,RP0
       
        movlw   0x07        ;turn off comparitors
        movwf   CMCON
       

       
    start
        movlw   0x44            ;adjustment for speed of fade
        movwf   runn
        btfss   PORTA,0         ;call to see if low, if low make fade slower
        call    slower
        btfss   PORTA,1         ;call to see if low, if low make fade faster

        call    faster 
        call    firstt
        call    secondd
        call    thirdd
        call    fourthh
        call    fifthh
        call    sixthh
        call    seventhh
        call    eighthh
        call    ninthh
        call    tenthh
        call    ninthh
        call    eighthh
        call    seventhh
        call    sixthh
        call    fifthh
        call    fourthh
        call    thirdd
        call    secondd
        goto    start

    firstt
        movf    runn,0
        movwf   run
    first
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x01        ;set on time of duty cycle
        movwf   BH
    loop
        decfsz  BH,1        ;count down the on time
        goto    loop
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x01        ;set off time of duty cycle
        movwf   BH
    loop2
        incfsz  BH,1        ;count up to the off time
        goto    loop2
        decfsz  run,1   ;run the PWM for a moment
        goto    first
        return
       
    secondd
        movf    runn,0
        movwf   run
    second
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x03        ;set on time of duty cycle
        movwf   BH
    loopa
        decfsz  BH,1        ;count down the on time
        goto    loopa
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x03        ;set off time of duty cycle
        movwf   BH
    loop2a
        incfsz  BH,1        ;count up to the off time
        goto    loop2a
        decfsz  run,1   ;run the PWM for a moment
        goto    second
        return


    thirdd
        movf    runn,0
        movwf   run
    third
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x05        ;set on time of duty cycle
        movwf   BH
    loopb
        decfsz  BH,1        ;count down the on time
        goto    loopb
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x05        ;set off time of duty cycle
        movwf   BH
    loop2b
        incfsz  BH,1        ;count up to the off time
        goto    loop2b
        decfsz  run,1   ;run the PWM for a moment
        goto    third
        return


    fourthh
        movf    runn,0
        movwf   run
    fourth
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x07        ;set on time of duty cycle
        movwf   BH
    loopc
        decfsz  BH,1        ;count down the on time
        goto    loopc
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x07        ;set off time of duty cycle
        movwf   BH
    loop2c
        incfsz  BH,1        ;count up to the off time
        goto    loop2c
        decfsz  run,1   ;run the PWM for a moment
        goto    fourth
        return

       
    fifthh
        movf    runn,0
        movwf   run
    fifth
        movlw   0xff
        movwf   PORTB       ;turn on leds      
        movlw   0x09        ;set on time of duty cycle
        movwf   BH

    loopd
        decfsz  BH,1        ;count down the on time
        goto    loopd
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x09        ;set off time of duty cycle
        movwf   BH
    loop2d
        incfsz  BH,1        ;count up to the off time
        goto    loop2d
        decfsz  run,1   ;run the PWM for a moment
        goto    fifth
        return


    sixthh
        movf    runn,0
        movwf   run
    sixth
        movlw   0xff
        movwf   PORTB       ;turn on leds
        movlw   0x11        ;set on time of duty cycle
        movwf   BH

    loope
        decfsz  BH,1        ;count down the on time
        goto    loope
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x11        ;set off time of duty cycle
        movwf   BH
    loop2e
        incfsz  BH,1        ;count up to the off time
        goto    loop2e
        decfsz  run,1       ;run the PWM for a moment
        goto    sixth
        return
       
       
    seventhh
        movf    runn,0
        movwf   run
    seventh
        movlw   0xff
        movwf   PORTB
        movlw   0x17        ;set on time of duty cycle
        movwf   BH
    loopf
        decfsz  BH,1        ;count down the on time
        goto    loopf
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x17        ;set off time of duty cycle
        movwf   BH
    loop2f
        incfsz  BH,1        ;count up to the off time
        goto    loop2f
        decfsz  run,1   ;run the PWM for a moment
        goto    seventh
        return
       

    eighthh
        movf    runn,0
        movwf   run
    eighth
        movlw   0xff
        movwf   PORTB
        movlw   0x25        ;set on time of duty cycle
        movwf   BH
    loopg
        decfsz  BH,1        ;count down the on time
        goto    loopg
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x25        ;set off time of duty cycle
        movwf   BH
    loop2g
        incfsz  BH,1        ;count up to the off time
        goto    loop2g
        decfsz  run,1   ;run the PWM for a moment
        goto    eighth 
        return
       
       
    ninthh
        movf    runn,0
        movwf   run
    ninth
        movlw   0xff
        movwf   PORTB
        movlw   0x35        ;set on time of duty cycle
        movwf   BH
    looph
        decfsz  BH,1        ;count down the on time
        goto    looph
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x35        ;set off time of duty cycle
        movwf   BH
    loop2h
        incfsz  BH,1        ;count up to the off time
        goto    loop2h
        decfsz  run,1   ;run the PWM for a moment
        goto    ninth  
        return
       
       
    tenthh
        movf    runn,0
        movwf   run
    tenth
        movlw   0xff
        movwf   PORTB
        movlw   0x50        ;set on time of duty cycle
        movwf   BH
    loopi
        decfsz  BH,1        ;count down the on time
        goto    loopi
        movlw   0x00        ;turn leds off
        movwf   PORTB
        movlw   0x50        ;set off time of duty cycle
        movwf   BH
    loop2i
        incfsz  BH,1        ;count up to the off time
        goto    loop2i
        decfsz  run,1   ;run the PWM for a moment
        goto    tenth
        return
       
    slower
        movlw   0x88        ;puts higher value in speed adjustment
        movwf   runn
        return
    faster
        movlw   0x11        ;puts lower value in speed adjustment
        movwf   runn
        return
       
        end
     

    Attached Files:

  9. futz

    futz Active Member

    Joined:
    Sep 15, 2007
    Messages:
    2,043
    Likes:
    24
    Location:
    Vancouver, B.C.
    I very much disagree. That might be somewhat true with PC's, but when you're doing microcontrollers and the associated electronics you absolutely MUST know what's going on with the hardware, in detail. I believe that assembler should be the first language you learn, starting simple and working up to more complex things.

    Once you've got a handle on that, only then should you start using higher level languages (if you even want to at that point).

    I believe higher level languages tend to insulate you from the details somewhat, making understanding more difficult, especially for newbs.

    Not only that, but they make porky, fat code that eats up memory and runs slow. :D
     
  10. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    You do not need to know much hardware detail to blink a LED, or even to do PWM. I makes understanding/learning easier......

    In a more perfect world preople would learn a high level language first on a PC. Ater that we could have them learn assembly and processor details. But programing on the PC has lost the luster that programming uC's still have. You have to start where the interest is and currently that is uC's.

    Start them with a high level language. Let them get good at blinking LEDs and such. You hold their hand, hide the details, and they get hooked. Over time you introduce more complex hardware and how it work.

    At this point you can teach assembler. You teach assembler not because it is the worlds greatest programming language. You teach it because it is the best way to expose them to the nuts and bolts that you have been hidding.

    The fact that compiled code takes more memory is not a big concern here. The inexpensive 18F family has memory to spare for learning.
     
    Last edited: Nov 29, 2007
  11. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,232
    Likes:
    641
    Location:
    Derbyshire, UK
    ONLINE
    I would disagree, assembler forces understanding of the hardware on you, a high level language hides it from you - unless the compiler has specific commands for implementing hardware PWM you essentially copy the way you do it in assembler, and it's MUCH easier to implement if you have an understanding of assembler.

    Do learning assembler first, you then have the hardware understanding required if you move to a high level language.

    Where this advantage is starting to blur is the 18F series, simply because there's a free compiler available, and the application notes are mainly provided written in C. So in that case, I would suggest learning a little assembler on a 16F (so you understand PIC hardware), and probably go directly to C on the 18F.

    Incidently, in Universities in the past you weren't allowed to use high level languages until you had mastered machine code, never mind assembler! :D
     
  12. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Nigel:

    This is very real for me in that I am teaching young people to use uC's.

    I understand why you feel the way you do about assembly. Anyone programming uC's needs a solid understanding of the hardware. But not when he/she/it is very green.

    Learn a higher level language first, you then have the understanding of programming required to learn assembler.

    From a structure and style viewpoint assembler is a bad first language.

    As I tried to point out in my previous post it is far easier to teach people to program first. Then teach them about uC's. Learning machine language is easier if the student already understands basic flow control etc.

    Current thinking in computer education is to start intro students at an abstract level. One school I know of starts with ALICE. At another first term students do not do any programming They spend there time learning logic and problem solving. Not sure but I think their first language is JAVA.

    I think this is an effort to both bring people up to where they are ready to learn programming, and maybe weed out a few that would fail if they tried.

    One can illustrate PWM in 10 or 12 lines of C code. The transistion to hardware PWM is all about setting up the hardware to do it. Can the student read a data sheet. As you said setting up the hardware is much the same. But the basic concept is better taught in a higher level language.
    Why learn a little assembler on a 16F then move to C and the 18F? Just use the 18F start to finish.

    The truth is that I do not much care what people learn first. The point is that they learn. It is great that you help people with their assembly problems. Hats off.

    Perspective has a lot to do with our differing viewpoints.
     
  13. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,232
    Likes:
    641
    Location:
    Derbyshire, UK
    ONLINE
    I think the difference here is that YOU are teaching them, so they have you to ask about the hardware, and presumably you teach them about it from a high level perspective?. This isn't an option without you there, the datasheets and application notes are all in assembler, and unless you understand a modicum of assembler a beginner is going to struggle.
     
  14. blueroomelectronics

    blueroomelectronics Well-Known Member

    Joined:
    Jan 21, 2007
    Messages:
    12,536
    Likes:
    168
    Location:
    Toronto, Canada
    IMO there is no easy answer to this debate.
    If I started with the excellent 18F series I'd have a tough time going back to the 16F or worse 12bit 12F chips like the 12F509
    I did start with the dirt simple 16C54, C was not a good option for that chip and CCS C was a bugfest back then. So I learned PIC assembler and it's not that difficult at all even with the 16F bank switching and small but powerful instruction set.
    Since C supports inline code it's handy to know the basics, on the other hand the job market will expect C.
    That said the 18F was designed with C in mind and the free SE C18 compiler is a real bargain, the extended instuction set and wider memory (16bit) makes assembler a breeze, (no hunting around for what bank that SFR is in).
    Being able to read the code produced by the compiler will certainly come in handy for some.
     
  15. Wingmax

    Wingmax New Member

    Joined:
    Sep 16, 2007
    Messages:
    163
    Likes:
    6
    Location:
    Australia
    We do need a strong background in software model of the micro. Also, there are only about 35 to 40 asm instructions to learn, and if timing is critical, asm is a must. But high level language such as C is always used in a real job. It is much easier and efficient.
    The point I'm trying to make is, we should start with fundatmantal programming skill and logic. Like 3V0 said, if any one find that programming is not for him, then better move to different direction before wasting more time.
    Learn asm then high level language. Because ultimately the students will have to find a job and high level language (C) is more important.
     
  16. kayjayuk

    kayjayuk New Member

    Joined:
    Mar 14, 2010
    Messages:
    7
    Likes:
    0
    Location:
    Stockport, Cheshire
    Hi guys

    I'm new on here, searching for pwm info and I got enthralled in the debate about high level languages so I thought I'd add my two penne'th .... I grew up with computers starting back in 1976 by building the first UK micro, the Nascom I and then the Nascom II. These were designed around (in my opinion) the worlds finest uProcessor, the Z80, As supplied the Nascom had no high level languages and it had no assembler either, the machine was coded by entering the hex values required directly into memory, ahhh happy days, VERY happy days. As the Nascom became more popular then software came onto the market for it, I was too green at programming then to be able to code myself an assembler so I bought one as soon as one became available. This turned the world of programming around for me, it was so much easier ! After a few weeks I had completely grasped the how to code in Z80 assembler and I next turned my attentions to the 6800 having bought another UK kit computer, the 77/68, I did the same with this comp as I did with the Nascom. I then turned to the BBC B which had come onto the market in the early 80's and I set about learning 6809. The BBC B computer had been specifically designed for use in schools to teach the kids how to use comps and how to program, it had one of the best operating systems I've ever seen, loads of easily accessible routines within it for your machine code programs to access, it also had a built in assembler !

    I write all this because we were meant to learn how to code in machine code, that's why the BBC B was built the way it was, for the schoolkids. I did learn BASIC at one point but the programs were so bloated and meant very little with respect to accessing the specially designed parts of the operating system and the hardware too. Another major point to consider, high level languages are simply programs not the code that drives the computer, that is machine code, you walk before you run, you write programs the way the processor was built to understand, in machine code, if you want to write bloated code then you learn that after you know how the code you are writing affects your hardware

    High level languages were designed for professional coders to complete programs quickly and in separate modules, allowing lots of programmers to write one program between them. High level languages mean nothing with regards to the true operation of the computer. I have never learnt C, I don't see the point, it's more like pseudo code, a mix between machine code and BASIC, in fact C is so close to machine code it's better to go the whole hog and write your program in machine code anyway, saves you having to learn another language. It is much harder to learn a high level language when you don't understand what it's doing.

    Just one more point, assembler isn't a language as some of the previous posts were suggesting, it's a method of programming, it's a program to convert nmemonics into machine code. What was actually meant would be PIC machine code (in that instance) although there are many types, in fact one for every different family of processors, you tend to find that the same code is used by manufacturers for the same family of processors, such as the Z8 family, right down to the Z80 which is downward compatible with the Z8 and like the 8080, the Z80 was designed to run 8080 code but has a lot more registers so it's downward compatible being able to run all 8080 but not the other way about because of all the extra registers.

    I hope that helps and perhaps puts a cap on which method of coding to learn first, Acorn got it right by making the school computer very, very machine code friendly, machine code first, absolutely essential then if you have the inclination turn to medium and high level languages.

    Keith <kayjayuk>
     
  17. techmanx

    techmanx New Member

    Joined:
    Mar 6, 2008
    Messages:
    29
    Likes:
    0
    Location:
    Germany
    Hi andy, you might find some help here electronics-home
    greetings
     
  18. harrier

    harrier New Member

    Joined:
    Feb 4, 2012
    Messages:
    1
    Likes:
    0
    techmanx

    What a great site for beginners, thanks
     
  19. techmanx

    techmanx New Member

    Joined:
    Mar 6, 2008
    Messages:
    29
    Likes:
    0
    Location:
    Germany
    HI, Perhaps you will find help here http://www.chiphil.com , this site is specially designed for beginners,several free circuit design downloads etc.
    hope it is helpful
    greetings
     
    Last edited: Feb 4, 2012
  20. techmanx

    techmanx New Member

    Joined:
    Mar 6, 2008
    Messages:
    29
    Likes:
    0
    Location:
    Germany
    Very pleased it was helpful

    Note:The site address has now changed to http://www.chiphil.com
     

Share This Page