Quantcast
Channel: Question and Answer » pwm
Viewing all articles
Browse latest Browse all 108

Using PSMC instead of CCP

$
0
0

Hi I am building a motor controller and I decided to use PSMC instead of CCP to create my PWM, my decision was based on the fact that I dont have enough CCP ports on my pic 16f1788 for the project. I am using the PSMCdesigner module provided by Microchip. I went through it and generated my code but unfortunately the code doesn’t work. I know how to program CCP but never worked with PSMC before I would like to get some help here is the code I generated through the program.

#include <xc.h>
// Config word

// CONFIG1
#pragma config FOSC = INTOSC    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = ON        // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON       // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

// CONFIG2
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config VCAPEN = OFF     // Voltage Regulator Capacitor Enable bit (Vcap functionality is disabled on RA6.)
 #pragma config PLLEN = ON       // PLL Enable (4x PLL enabled)
 #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
 #pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
 #pragma config LPBOR = OFF      // Low Power Brown-Out Reset Enable Bit (Low power brown-out is disabled)
 #pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)





  void main(void)

{


PSMC1CON  = 0x00;
PSMC1MDL  = 0x00;
PSMC1SYNC = 0x00;
PSMC1CLK  = 0x30;
PSMC1POL  = 0x00;
PSMC1BLNK = 0x00;
PSMC1REBS = 0x00;
PSMC1FEBS = 0x00;
PSMC1PHS  = 0x00;
PSMC1DCS  = 0x00;
PSMC1PRS  = 0x00;
PSMC1ASDC = 0x00;
PSMC1ASDL = 0x00;
PSMC1ASDS = 0x00;
PSMC1PHH  = 0x00;
PSMC1PHL  = 0x14;
PSMC1DCH  = 0x00;
PSMC1DCL  = 0x00;
PSMC1PRH  = 0x00;
PSMC1PRL  = 0xC7;
PSMC1DBR  = 0x00;
PSMC1DBF  = 0x00;
PSMC1FFA  = 0x00;
PSMC1BLKR = 0x04;
PSMC1BLKF = 0x02;
PSMC1STR0 = 0x3F;
PSMC1STR1 = 0x80;
PSMC1INT  = 0x00;
PSMC1OEN  = 0x05;
PSMC1CON  = 0x80;
PIE4     &= 0xEE;
PIE4     |= 0x00;



   }

Viewing all articles
Browse latest Browse all 108

Trending Articles