I am running this code on 28x2, the timer count comes out at either 230 or 232.
the pwm and the pulsout and b.7 run into a nand, the output of that runs into another nand set as an inverter. when c.1 goes high (PTM connected here, pin tied low) b.7 goes high meaning that the signal will run through to the inverting part of the circuit.
The pulsout should give 0.005 seconds (5us * 1000). the PWM is set to 10khz, so each clock cycle should give 0.0001 seconds. Unless I have something wrong (which is highly possible) I would have expected 50 in the timer variable with the preset on timer of 65535.
I have noticed that going over 65531 does seem to make things go a little strange, in some cases possibly due to rounding or alike, 65532 produces 13 - 0.005/0.0004 = 12.5. however 65533 produces 19 with a calculated 16.66.... 65532 produced 22, expected 25 and 65535 produced 230.
I will check the numbers in a more rigorous manor in the next couple of days, but this does seem like an odd quirk that other may need to know about.
Its not something that cant be designed around, and for most applications that level of resolution most likely wont be needed.
Code:
[color=Navy]#terminal 9600[/color]
[color=Blue]setfreq m8
pause [/color][color=Navy]1000[/color]
[color=Blue]let [/color][color=Purple]dirsb [/color][color=DarkCyan]= [/color][color=Navy]%11111111[/color]
[color=Blue]let [/color][color=Purple]pinsb [/color][color=DarkCyan]= [/color][color=Navy]%00000000[/color]
[color=Black]init:
[/color][color=Blue]pwmout B.0[/color][color=Black], [/color][color=Navy]199[/color][color=Black], [/color][color=Navy]399 [/color][color=Green]; 10000Hz at 50% @ 8MHz
[/color][color=Blue]settimer count [/color][color=Navy]65535[/color]
[color=Black]main:
[/color][color=Blue]if [/color][color=Purple]pinc.1 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then [/color][color=Green];check for user input
[/color][color=Blue]pulsout b.7[/color][color=Black], [/color][color=Navy]1000 [/color][color=Green];hold and gate input high for 0.005 second
[/color][color=Blue]pause [/color][color=Navy]1000
[/color][color=Blue]let [/color][color=Purple]w0 [/color][color=DarkCyan]= [/color][color=Purple]timer [/color][color=Green];put timer value in w0
[/color][color=Blue]bintoascii [/color][color=Purple]w0[/color][color=Black], [/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6 [/color][color=Green];convert to ascii
[/color][color=Blue]sertxd ([/color][color=Black]#[/color][color=Purple]w0[/color][color=Black], [/color][color=Navy]13[/color][color=Black], [/color][color=Navy]10[/color][color=Blue]) [/color][color=Green];send timer value as seen by picaxe
[/color][color=Blue]sertxd ([/color][color=Purple]b2[/color][color=Black],[/color][color=Purple]b3[/color][color=Black],[/color][color=Purple]b4[/color][color=Black],[/color][color=Purple]b5[/color][color=Black],[/color][color=Purple]b6[/color][color=Black],[/color][color=Navy]13[/color][color=Black],[/color][color=Navy]10[/color][color=Blue]) [/color][color=Green];send timer value as ascii
[/color][color=Blue]let [/color][color=Purple]timer [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Green];reset timer
[/color][color=Blue]pause [/color][color=Navy]500 [/color][color=Green];large debouce
[/color][color=Blue]end if
goto [/color][color=Black]main[/color]
The pulsout should give 0.005 seconds (5us * 1000). the PWM is set to 10khz, so each clock cycle should give 0.0001 seconds. Unless I have something wrong (which is highly possible) I would have expected 50 in the timer variable with the preset on timer of 65535.
I have noticed that going over 65531 does seem to make things go a little strange, in some cases possibly due to rounding or alike, 65532 produces 13 - 0.005/0.0004 = 12.5. however 65533 produces 19 with a calculated 16.66.... 65532 produced 22, expected 25 and 65535 produced 230.
I will check the numbers in a more rigorous manor in the next couple of days, but this does seem like an odd quirk that other may need to know about.
Its not something that cant be designed around, and for most applications that level of resolution most likely wont be needed.