PWM A and B

Discussion to talk about software related topics only.
Post Reply
chourizo
Posts: 16
Joined: Tue Apr 07, 2015 8:00 pm

PWM A and B

Post by chourizo »

I am trying to use B3 and A1 PWM outputs in a Nano. I have A1 working properly, but I am having problems getting B3 to work. So far I can only use it in complementary mode (cr2 = 0x0000), but not independently.

I really just want to have A1 and B3 identical.

Can somebody point me to some example or documentation?

My code is below, there are probably some unnecessary things because I've been testing all kind of things (for example cr2 as 0x2001 is only a test).

Code: Select all

     Pins[16].function(PIN_16_PWM_B3);
     Pins[15].function(PIN_15_PWM_A1);

	sim1.mcpwm.sm[1].cr1 = 0x0404;
	sim1.mcpwm.sm[1].cr2 = 0x2000;
	sim1.mcpwm.sm[1].init = 0;         	
	sim1.mcpwm.sm[1].val[0] = 2500;
	sim1.mcpwm.sm[1].val[1] = 5000;     
	sim1.mcpwm.sm[1].val[2] = 0;      	// PWM A ON counter value
	sim1.mcpwm.sm[1].val[3] = 8;      	// PWM A OFF counter value
	sim1.mcpwm.sm[1].val[4] = 8;      	// PWM B ON counter value
	sim1.mcpwm.sm[1].val[5] = 0;      	// PWM B OFF counter value
	sim1.mcpwm.sm[1].ocr = 0;
	sim1.mcpwm.sm[1].dismap=0xFF00;

	sim1.mcpwm.sm[3].cr1 = 0x0444;
	sim1.mcpwm.sm[3].cr2 = 0x2001;//0x2001;// &= 0x2000;
	sim1.mcpwm.sm[3].init = 0;
	sim1.mcpwm.sm[3].val[0] = 2500;
	sim1.mcpwm.sm[3].val[1] = 5000;
	sim1.mcpwm.sm[3].val[2] = 0;
	sim1.mcpwm.sm[3].val[3] = 8;
	sim1.mcpwm.sm[3].val[4] = 8;
	sim1.mcpwm.sm[3].val[5] = 0;
	sim1.mcpwm.sm[3].ocr = 0;
	sim1.mcpwm.sm[3].dismap=0xFF00;

	//Set output mask to 0
	sim1.mcpwm.mask = 0;
	sim1.mcpwm.outen |= 0x0080;// Enable PWM B3
	sim1.mcpwm.outen |= 0x0200;	// Enable PWM A1

    if(sim1.mcpwm.mcr & 0x000F == 0x000F){
    	sim1.mcpwm.mcr |= 0x00F0;
    }

    //Once cleared, clear the reset bit to enable LDOK to run later.
    sim1.mcpwm.mcr &= 0xFF0F;
mbrown
Posts: 61
Joined: Tue Jan 29, 2013 7:12 pm

Re: PWM A and B

Post by mbrown »

There is a PWM example for the NANO and the MOD5441x in the nburn/examples/NANO54415 and nburn/examples/MOD5441x folders. The comments say that cr2 value set the PWMs to be "dependent" but looking at the cr2 register, the options are independent and complementary mode. I believe these run in independent mode given both their current settings and what I remember when I was testing the example. That is, when you enable one signal, it does not automatically enable the other signal to work.

The function definitions given in the example may not work for your specific application, but this should be a pretty quick way to get an example running and outlines all the settings that were used to initialize the modules.
Post Reply