10-Bit PWM using PIC16F1509


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,681


    Did you find this post helpful? Yes | No

    Default Re: 10-Bit PWM using PIC16F1509

    its fairly easy to get 3 different pwm streams from one ccpm module , you just to need to
    1. set pulse width for channel
    2. set pin steering to channel pin
    in a sequentially multiplexed routine
    eg
    Code:
    /**
      Generated Main Source File
    
    
            Device            :  PIC16F1825
            Driver Version    :  2.00
     */
    
    
    int pwmv[3];
    char cnt = 0;
    void ticker(void);
    
    
    
    
    #include "mcc_generated_files/mcc.h"
    
    
    /*
                             Main application
     */
    void main(void) {
        // initialize the device
        SYSTEM_Initialize();
        TMR1_SetInterruptHandler(ticker);
        // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
        // Use the following macros to:
        PSTR1CON = 0x10;
        // Enable the Global Interrupts
        INTERRUPT_GlobalInterruptEnable();
    
    
        // Enable the Peripheral Interrupts
        INTERRUPT_PeripheralInterruptEnable();
    
    
        // Disable the Global Interrupts
        //INTERRUPT_GlobalInterruptDisable();
    
    
        // Disable the Peripheral Interrupts
        //INTERRUPT_PeripheralInterruptDisable();
    
    
        while (1) {
            pwmv[cnt] = ADC_GetConversion(cnt);
            __delay_ms(300);
            cnt++;
            cnt &= 3;
            // Add your application code
        }
    }
    
    
    void ticker(void) {
        static char inx = 0;
        CCPR1L = pwmv[inx] >>8;
        CCP1CON = ((pwmv[inx]&0xc0)>>2) | 0xC;
        PSTR1CON = 0x10 | (2 << inx);
        inx++;
        inx &= 3;
    }
    this sort of led modulation is exactly how those p10 led modules work
    Attached Images Attached Images  
    Last edited by richard; - 22nd January 2020 at 02:04.
    Warning I'm not a teacher

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: 10-Bit PWM using PIC16F1509

    Hi Richard. Thanks for posting this. I was not aware this was possible.

    But, doesn't this have glitches in the signal when steering is changing channel?

    Have to try this in real hardware.

    Ioannis

Similar Threads

  1. DMX512 Reception + 3 * 8-Bit PWM Outputs
    By JEC in forum Code Examples
    Replies: 5
    Last Post: - 16th February 2015, 16:21
  2. 16 bit PWM using CCP1
    By Normnet in forum mel PIC BASIC Pro
    Replies: 60
    Last Post: - 27th August 2014, 09:13
  3. Replies: 17
    Last Post: - 22nd May 2014, 20:58
  4. Replies: 1
    Last Post: - 13th March 2012, 00:34
  5. 10 bit pwm as dac
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th June 2004, 16:12

Members who have read this thread : 1

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