Home/Support/Support Forum/How to "activate" the isr for PWMs?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

How to "activate" the isr for PWMs?

0 votes
The isr still doesn't trigger on the PWM cycle. I guess I need to set bits 1 and 2 of register PWL0R to some non-zero value to give the isr a priority (if those bits are 0 the isr is disabled). What is the best way to do that. It seems that the WrPortI(PWL0R, NULL, 0x02) command should work, but I can't read back that register and when I use the WrPortI function to write the value the debug connection will drop out.
asked Mar 18 in Rabbit Software by raleighs New to the Community (2 points)

Please log in or register to answer this question.

1 Answer

0 votes
You might want to look at code in Lib/Rabbit4000/Peripherals/PWM.LIB. In particular, pwm_set() looks like it will configure PWL0R with an interrupt priority.

Since you can't read back the PWL0R register, you'd use the address its "shadow" register (&PWL0RShadow) as the second parameter to WrPortI(). So something like:

// set ISR priority
WrPortI(PWL0R, &PWL0RShadow, PWL0RShadow | 0x02);

You could also use BitWrPortI() to change a single bit.

Edit: That answer covers Dynamic C 10 and the Rabbit 4000 or later. The pwm_set() function in Dynamic C 9 doesn't allow setting an interrupt level because the original Rabbit 3000 didn't have that feature. You may be able to copy some of the pwm_set() code from Dynamic C 10 for use within Dynamic C 9.

https://github.com/digidotcom/DCRabbit_10/blob/master/Lib/Rabbit4000/Peripherals/PWM.LIB

Make sure your board has a Rabbit 3000A processor (UL2T or UZ2T marking instead of IL1T/IZ1T). I'd think that anything sold in the last 15 years would have the old revision 0 version of the 3000 chip.
answered Mar 18 by TomCollins Veteran of the Digi Community (2,185 points)
edited Mar 18 by TomCollins
Note that I've added additional information in the response to your support case.
I did dig down into the R3000.lib and found that the pwm_set() command will write over the entire PWL0R with only one possible option on bit 0 for "spreading".  This effectively disables the ISR priorities every time it is used.
I copied that and added an |= 0x02 to the byte being written to PWL0R.  That works, but now when that is executed the code will stop working.  Even if I don't set the vector.
Could it be that the priority should be 2 or 3 instead of 1?
...