Although not entirely clear what represents what on te scope it looks like I'd expect given the code ...
Code:
pulsin 1,1,b1
do
b1 =0
high 3
Pause 6
high 2
Pause 1
low 2
Loop
Firstly, you only synchronise once, before the Do-LOOP so after that it becomes a free-running pulse generator. You need to synchronise to the zero-crossover for every half phase of mains.
Try a much simpler program to start with ignoring actual control of the triac / light ...
Code:
Do
PulsIn 1, 1, b1
PulsOut 2, 10
Loop
You should see a pulse on Pin 2 whenever the zero-crossover happens. If not then you have a hardware problem which needs fixing ( or PULSIN is looking for the wrong level ).
Then you can look at delaying the pulse until after zero-crossover. Use a PULSOUT to an otherwise unused pin and adjust the length of that pulse from 0 to ~8mS ...
Code:
Do
PulsIn 1, 1, b1
[b]PulsOut [i]?[/i], [i]?[/i][/b]
PulsOut 2, 10
Loop
Choose a suitable PULSOUT time to put the triac firing pulse halfway through the phase, then alter the length of the time of the triac firing pulse to suit the triac, and with the light connected you should get 50% brightness.
Code:
Do
PulsIn 1, 1, b1
PulsOut [i]?[/i], [i]?[/i]
PulsOut 2, [b]?[/b]
Loop
Now you can move the pulse along the phase angle, and determine what the minimum and maximum values of the time delay pulse can be ( w1 ) ...
Code:
Do
[b]w1 = [i]?[/i][/b]
PulsIn 1, 1, b1
PulsOut [i]?[/i], [b]w1[/b]
PulsOut 2, [i]?[/i]
Loop
Then all you need to do is decide what 'w1' should be each time through the loop and you have your dimmer. Here's something which should give 0% to 100% dimming ...
Code:
Do
b1 = 50 ' 0 to 100 ( % brightness )
If b1 = 0 Then
Low 2
Else
If b1 >= 100 Then
High 2
Else
w1 = 100 - b1 * [i]?[/i] / [i]?[/i] + [i]?[/i]
PulsIn 1, 1, b1
PulsOut [i]?[/i], w1
PulsOut 2, [i]?[/i]
End If
End If
Loop