Code from PIC18F8722 to PIC18F4550


Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Feb 2005
    Posts
    130

    Default Code from PIC18F8722 to PIC18F4550

    Hi,

    Important Im using 4550 because is what I have at hand, but any pic with 3 simultaneous PWM work for me

    I'm experimenting with RGB leds and to test my program I used a 18f8722 VSM because I dont have the model for the 18f4550

    I have the code working, mostly by following advice from Bruce (rentron) in different posts across this forum.

    I dont know how to translate the 3rd PWM port I use in the 18f8722, here is my code:

    Code:
    DEFINE OSC 4
    ' Word vars for 10-bit value of each PWM duty cycle
    Duty1 VAR WORD ' Channel #1
    Duty2 VAR WORD ' #2
    Duty3 VAR WORD ' #3
    Rval	var	word	
    Gval	var	word	
    Bval	var	word
    
    ' Set CCPx pins to outputs
    TRISC.2=0 ' CCP1 output
    TRISC.1=0 ' CCP2 output (could also be assigned to RB3)
    TRISG=0 ' CCP3 output
    trisa=%00000111
    
    ' Set CCP modules to PWM mode
    CCP1CON = %00001100 ' Mode select = PWM
    CCP2CON = %00001100 ' Mode select = PWM
    CCP3CON = %00001100 ' Mode select = PWM
    
    ' Set period up for 1.22kHz PWM freq
    PR2 = $7F
    
    ' Set TMR2 up for 1:16 prescale & turn it on
    T2CON = %00000110 ' TMR2 ON 1:16 prescale
    
    mainloop:
    
    
    Adcin 0, Bval 
    serout  porta.3,2,[#Bval,"."]
    Adcin 1, Rval   
    serout  porta.3,2,[#Rval,"."]
    Adcin 2, Gval     
    serout  porta.3,2,[#Gval,"."]
    
    
    serout  porta.3,2,[10,13]
    
    Duty1 = Bval *2
    CCP1CON.4 = Duty1.0 ' Setup 10-bit duty cycle as
    CCP1CON.5 = Duty1.1 ' a 10-bit word
    CCPR1L = Duty1 >> 2
    
    Duty2 = Rval   *2
    CCP2CON.4 = Duty2.0 
    CCP2CON.5 = Duty2.1 
    CCPR2L = Duty2 >> 2
    
    Duty3 = Gval     *2
    CCP3CON.4 = Duty3.0 
    CCP3CON.5 = Duty3.1 
    CCPR3L = Duty3 >> 2
    
    Goto    mainloop    
    End
    I dont know how to translate CCP3CON.

    Help needed & appreciated.

    Thanks


    Pablo
    Last edited by peu; - 16th January 2006 at 22:39.

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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