Hm, strange.
Shouldn't I get an error report if there is a loop error?
If I add an ELSE, I get a syntax error.
I have changed some and now it works, sort of.
Some pulses seem to be too long....
I think I will have to do some measurements to see what parameters I really want.
Here's the new program:
'Define ADCIN parameters
ANSEL = %00001101 'GP4 = AN3
CMCON0 = %00000111 'Deactivate the comparator
DEFINE ADC_BITS 8 'Set number of bits in result
DEFINE ADC_CLOCK 5 'Set clock source
DEFINE ADC_SAMPLEUS 50 'Set sampling time in us
OSCCON = %01110101 'Sets internal osc to 8 Mhz and stable
DEFINE OSC 8 'Clock = 8 MHz
TRISIO = %11111111 'Defining PORT (all inputs)
orange var byte 'Value for base colour
colour var byte 'Value for colour
space var byte 'Value for time between pulses
spacet var byte 'Counter for space time
spacet1 var word 'Value for random space time
pulse var byte 'Value for pulse time
pulset var byte 'Counter for pulse time
pulset1 var word 'Value for random pulse time
orange = 45
space = 100
pulse = 16
colour = orange
spacet = space
pulset = pulse
loop1: Pause 10 'Wait 10 ms
colour = colour + 1 'Increase colour by 1
pulset = pulset - 1 'Decrease pulse time by 1
hpwm 1, colour, 22000 'channel 1, duty cycle, freq
if pulset > 0 then goto loop1 'Go to loop1
loop2: Pause 10 'Wait 10 ms
colour = colour - 1 'Decrease colour by 1
hpwm 1, colour, 22000 'channel 1, duty cycle, freq
if colour > orange then goto loop2
random spacet1'Randomize value in spacet1
spacet = spacet1 / 655
spacet = spacet + 10
random pulset1'Randomize value in pulset1
pulset = pulset1 / 4096
loop3: Pause 10 'Wait 10 ms
colour = orange
spacet = spacet - 1 'Decrease space time by 1
hpwm 1, colour, 22000 'channel 1, duty cycle, freq
if spacet = 0 then: goto loop1 'Go to loop1
goto loop3
end
'Define ADCIN parameters
ANSEL = %00001101 'GP4 = AN3
CMCON0 = %00000111 'Deactivate the comparator
DEFINE ADC_BITS 8 'Set number of bits in result
DEFINE ADC_CLOCK 5 'Set clock source
DEFINE ADC_SAMPLEUS 50 'Set sampling time in us
OSCCON = %01110101 'Sets internal osc to 8 Mhz and stable
DEFINE OSC 8 'Clock = 8 MHz
TRISIO = %11111111 'Defining PORT (all inputs)
orange var byte 'Value for base colour
colour var byte 'Value for colour
space var byte 'Value for time between pulses
spacet var byte 'Counter for space time
spacet1 var word 'Value for random space time
pulse var byte 'Value for pulse time
pulset var byte 'Counter for pulse time
pulset1 var word 'Value for random pulse time
orange = 45
space = 100
pulse = 16
colour = orange
spacet = space
pulset = pulse
loop1: Pause 10 'Wait 10 ms
colour = colour + 1 'Increase colour by 1
pulset = pulset - 1 'Decrease pulse time by 1
hpwm 1, colour, 22000 'channel 1, duty cycle, freq
if pulset > 0 then goto loop1 'Go to loop1
loop2: Pause 10 'Wait 10 ms
colour = colour - 1 'Decrease colour by 1
hpwm 1, colour, 22000 'channel 1, duty cycle, freq
if colour > orange then goto loop2
random spacet1'Randomize value in spacet1
spacet = spacet1 / 655
spacet = spacet + 10
random pulset1'Randomize value in pulset1
pulset = pulset1 / 4096
loop3: Pause 10 'Wait 10 ms
colour = orange
spacet = spacet - 1 'Decrease space time by 1
hpwm 1, colour, 22000 'channel 1, duty cycle, freq
if spacet = 0 then: goto loop1 'Go to loop1
goto loop3
end
Bookmarks