BS2 PWM PIC implemenation
manitou
Posts: 29
Just curioius: what are the PIC instructions used on the BS2 for implementing the PWM instruction? I've read that for the 20MHz BS2, PWM at 50% duty cycle has a pulse width of 4.5us. It would seem that a tight PIC loop could toggle a pin at 1.6us ...
inquring minds
inquring minds
Comments
-Phil
Always hopeful, I realize this would require an engineer with access to firmware code and willing to provide the code snippet or cycle count, and presuming not a gross violation of proprietary information.
tick tock tick tock
PWM myPin, 128, 255
the output frequency is close to 111 kHz. It is a symmetric square wave.
With a 20MHz xtal, and a 5 MHz instruction rate, that comes out to 45 instructions. (5 MHz / 45 = 111.111_ kHz) In my online article about stamp PWM, I came up empirically with 111.3kHz, but the difference from 111.111 was probably due to individual Stamp variation plus measurement error.
That does seem like more instructions than would be necessary. It shouldn't have to read the EEPROM for the interpreter during execution. All that is required is repeated addition and transfer of the carry to an output pin. It also has to keep track of the cycle count. I don't have the code used, but possibly they slowed it down a bit on purpose.
So that loop is 8 cycles, or 1.6us at 5 million ops per second. Too fast for an 8-bit counter to achieve a 1 ms duration. add NOPs
For what it's worth, I used logic analyzer @50Mhz to capture PWM 0,128,4 on BS2. I got pulse width of 4.4us, period of 8.8 us and frequency of 111.636 KHz. I couldn't see any change in the pulse train at the "cycle boundary" (1ms). The 4 cycle PWM pulse train lasted 4.505ms. The last pulse of the train was 16us high?