PWM on PIC16F88


Closed Thread
Results 1 to 37 of 37

Thread: PWM on PIC16F88

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    play with this one

    Code:
            ;       ---------------------------------------------------------------
            ;
            ;       Simple program which display ADC results of AN0
            ;       to 8 LED connected to PORTB<7:0>
            ;
            ;       Enjoy!
            ;       Steve AKA Mister_e
            ;
            ;       ---------------------------------------------------------------
            
            list p=16f88, W=-302
                            ; bank switching                   
                            
            INCLUDE "p16f88.inc"
    
            ;       Program Configuration Register 1
    CFG1 = _INTRC_IO & _MCLR_OFF & _BODEN_ON & _PWRTE_ON & _WDT_OFF & _LVP_OFF
    CFG2 = _DEBUG_OFF & _CP_OFF & _CCP1_RB0 & _WRT_PROTECT_OFF & _CPD_OFF
            __CONFIG    _CONFIG1,  CFG1 & CFG2
            
            ;       Program Configuration Register 2
            __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    
            ORG 0  
                  
            BANKSEL OSCCON
            MOVLW   B'01100000'
            MOVWF   OSCCON          ; 4 MHz INT CLOCK MODE
            BTFSS   OSCCON,IOFS     ; wait 'till int osc is stable 
            GOTO    $-1
            
            BANKSEL TRISA
            MOVLW   .1
            MOVWF   TRISA           ; porta.0 as input, other to output
            CLRF    TRISB           ; all pins set to output
    
            MOVLW   .7
            MOVWF   CMCON           ; disable analog comparator
            
                    ;
                    ;       ADC setup
                    ;       ---------
            BANKSEL ANSEL
            MOVLW   .1
            MOVWF   ANSEL           ; Disable all ADCs but AN0
    
            CLRF    ADCON1          ; Left justified results
                                    ; ADCS2 : disabled
                                    ; Vref : Vdd, Vss
    
            BANKSEL ADCON0
            MOVLW   B'01000001'     
            MOVWF   ADCON0          ; ADCS : Fosc/8
                                    ; select AN0
                                    ; ADON = 1
            
                    ;
                    ;       Hardware initialisation
                    ;       -----------------------
            CLRF    PORTB           ; Clear all 
            CLRF    PORTA           ; outputs
                                    
            ;
            ;       Program Start
            ;       -------------                                
    Start
                    ;
                    ;       ADC Conversion
                    ;       --------------
            MOVLW   .12             ; ~12 uSec acquisition loop
            DECFSZ  W,F             ;
            GOTO    $-1             ;
            
            BSF     ADCON0, GO_DONE ; Start conversion
            BTFSC   ADCON0, GO_DONE ; conversion finished?
            GOTO    $-1             ;   NO, wait again
            
                    ;
                    ;       Display result
                    ;       --------------
            MOVF    ADRESH,W        ; Move ADC result to Wreg
            MOVWF   PORTB           ; display it on PORTB
            GOTO    Start
            END
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Nov 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Talking thanks alot.

    hi ya am surely one lucky guy.i know i might me asking for alot but can u please send the schematic for the adc code. by the way am called gonza, am from uganda in eastafrica.its like am one of the very few people in my part of the world dealing with microcontrollers.its really cool stuff i must say...... thanks alot for the support i appreciate it.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    There's no real difficulties here, LED cathode goes to GND, anode goes to a resistor (200-300 ohm) lead, and the other resistor lead goes to the PIC PORTB pins. repeat it 8 times.

    pot ( <10K ) wiper goes to the AN0 pin (PORTA.0), one pot side on gnd, the other to Vdd.

    Not much!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Nov 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default thanks

    okay mate am going to try that.

  5. #5
    Join Date
    Nov 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Talking the adc code works

    hey the code works very well. thank you. pliease help me with sample code for reading and writing to the eeprom.plays with leds. thanks

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Don't push your luck too much you should have some code example in the datasheet?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    And when you find a spare moment;

    I need code in binary please & full schematics in Protel format please to measure the speed of sub-atomic dark matter particles in a vacume, as they pass through a 1/2 eaten snickers bar, at -900 degrees kelvin, on the dark side of the moon, 10+E1200 meters from the event horizon of a black hole, at full moon, in the 3rd cycle. Can you help?

    No hurry. I have 12 minutes before my ship departs....;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 23:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 07:03
  3. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 08:24
  4. Replies: 8
    Last Post: - 7th December 2006, 16:42
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 01:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts