0
\$\begingroup\$

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;



   }
\$\endgroup\$
1
  • \$\begingroup\$ My first thought when seeing this: OMG WHY DIDN'T I KNOW ABOUT #pragma config BEFORE! Sorry, I know this is not helpful to you, but I now hate my life for not knowing about that in college. \$\endgroup\$
    – iAdjunct
    Commented Mar 16, 2015 at 4:55

1 Answer 1

4
\$\begingroup\$

You have a fatal problem with your code that has nothing to do with the PSMC module. Microcontrollers are single-purpose hardware, so there's no such thing as "exiting" the code. You MUST have an infinite loop of some kind.

If your main() function simple ends, as yours does, the chip will have undefined behavior. In the case of PICs, it will reset the chip and start over again. Over and over again, for as long as it has power. You will probably never see any output on any pin.

The easiest way to fix this just to test the PSMC module is to put "while(1);" as the last line of code in main().

\$\endgroup\$
1
  • \$\begingroup\$ Thank you for your input. I gave up on using psmc I went back with using CCP much easier for now. \$\endgroup\$ Commented Mar 17, 2015 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.