Slow down PWM on 28X1?

womai

Senior Member
Still working on my low-cost scope, currently battling some issues with unstable trigger positions (the scope very obviously waits for a trigger, but then seems to have variable delay), but other than that - if I use single-shot acquisition - my breadboarded version produces crisp, clean, virtually noise-free signal traces up close to its theoretical limit (recognizable sine waves up to about 150 kHz without interpolation, and if you only need approximate frequency information I got usable results up to around 300 kHz). Even without any optimizations (like hwserial instead of sertxd) I get 1.5 screen refreshs per second.

But now to my question:

Since I'd like to be able to go to low samples rates as well, does anybody know how to slow down PWM on an 28X1? In particular on the "classic" PWM pin 1, because I'd like to reserve the 4 hardware PWM pins for other purposes (to run at a slower period, used for analog control of trigger threshold and the like). I'm running the 28X1 at 16MHz clock (to maximize the acquisition and transfer speed), so the slowest PWM is 16 kHz - which means I can't even look at a full 50 Hz (20ms) period because the 256 sample record spans only 16ms. One option would be of course to slow down the clock frequency (internal oscillator instead of external resonator), but that would affect the ability to receive full-speed RS-232 commands from the PC unless I keep changing the baud rate on the fly (I don't want the scope to be "deaf" while it waits for the trigger, because the trigger may never come).

I know there are some POKE's for the 18X, so does anybody know an equivalent approach for the 28X1?

Thanks,

Wolfgang
 

womai

Senior Member
Some digging in the 16F886 data sheet seems to indicate the 28X1 also has such a prescaler (part of the timer2 register T2CON, address 0x12):

16F886 data sheet, p. 25

register T2CON (address 0x12), bits <1:0> (T2CKPS)

Untested code (have to wait until I get back into the lab):

Code:
peek 0x12, b0 ' read current timer2 setup
bit0 = b ' modify the two LSBs (i.e. the prescaler)
bit1 = a
poke 0x12, b0 ' write back the modified setup byte
Prescaler <ab> = 00 --> 1, 01 --> 4, 1x --> 16


Has anybody tried this before? Success?
 

Dippy

Moderator
Haven't tried it but a quick go on the calc shows that even with pre-scaler at 1:16 you'll struggle much below 1kHz @ 16MHz xtl.
 

womai

Senior Member
That's right, it will only go down to 1 kHz. But with 250 data points in a record that means 0.25sec for an acquisition, plus transfer time, so it already starts to limit the screen refresh rate. For anything slower (500 Hz and below) I can probably just switch into a different mode where I use the timer to toggle the clock pin in regular intervals (see my code from a few months ago), and also go into a "roll mode" for display.

Wolfgang
 
Top