A week into really working with PicAxe - and pleasantly surprised. Not the sub microseconds results that I am accustomed to using ARM. But perfect for quite a few ideas that I want to pursue. I am tending to use Logicator to learn the structure and then copy/paste/edit into PICAXE.
I have a requirement to generate 20hz, 860hz, 3.12kh/z and 5kh/z. The PWM is perfect except for the 20hz. (I did find that I can get the 20hz frequency if I change the PIC clock to 1mh/z).
So the next thought, Ok on port C.0 use the standard PWM to output the higher frequencies, then use a second PWM, divide it and switch port C.0 into toggle mode when needed to get the 20hz. With this in mind I have linked Port pins C.1 to C.2 ( C.2 fixed output at 320hz, C.1 interrupt input)
So far, so good - it works well.
Next I activated the multitasker, I find that the pin B.2 outputs a perfect 500ms toggle only if I comment out the setint line at [NOTE1]. If I allow the interrupt the pin B.2 toggles at a jiggly 9 - 12 ms period. (I don't understand why).
I don't know if I have made a code error. I don't really understand where I have gone wrong. I thought multitasking might introduce some jitter. But no, the 20hz is perfect. However the little routine Spin: gets all out of wack. Below is the code as of now. I would appreciate any comments.
Note. I found that the Multitasking mode switches the PIC clock to 16mh/z, and that Setfreq is not allowed.
I have a requirement to generate 20hz, 860hz, 3.12kh/z and 5kh/z. The PWM is perfect except for the 20hz. (I did find that I can get the 20hz frequency if I change the PIC clock to 1mh/z).
So the next thought, Ok on port C.0 use the standard PWM to output the higher frequencies, then use a second PWM, divide it and switch port C.0 into toggle mode when needed to get the 20hz. With this in mind I have linked Port pins C.1 to C.2 ( C.2 fixed output at 320hz, C.1 interrupt input)
So far, so good - it works well.
Next I activated the multitasker, I find that the pin B.2 outputs a perfect 500ms toggle only if I comment out the setint line at [NOTE1]. If I allow the interrupt the pin B.2 toggles at a jiggly 9 - 12 ms period. (I don't understand why).
I don't know if I have made a code error. I don't really understand where I have gone wrong. I thought multitasking might introduce some jitter. But no, the 20hz is perfect. However the little routine Spin: gets all out of wack. Below is the code as of now. I would appreciate any comments.
Note. I found that the Multitasking mode switches the PIC clock to 16mh/z, and that Setfreq is not allowed.
Code:
symbol varA = b0
let dirsB = %11111111
main: CALIBFREQ -1
setint %00000000,%00000010 'enable int input c.1, low [NOTE1]
pwmout pwmdiv64, C.2, 194, 391 ' PWM 320hz output on C.2
spin: pause 1000
goto spin
interrupt: ; if pinC.1 = 0 then interrupt 'needed to debug using push switch
let varA = varA + 1
if varA = 16 then ResetCnt
ExitInt: ' debug
setint %00000000,%00000010
return 'Return
ResetCnt: let varA = 0
toggle C.0 ' 20hz output on B.1
goto ExitInt
start1:
Spin2: pause 500 ' 500 ms
toggle B.2 ' toggle speed measured @ 9-12ms!
goto Spin2
#no_data 'reduce download
Last edited: