I am brand new to PIC coding and programming, so don't beat me up too bad. I have a background in electronics, but the assembly language is throwing me off a bit. I'm more of a see one, do one, teach one kind of guy, so I've been looking at other folks source codes to try to decipher and mimic what they are doing. My end goal is to make a model of a rotating sealed-beam light to put on a 10th scale RC truck. Most of the commercially available lights are for 1/14th scale and smaller, and the operation isn't quite what I'm after. I successfully made a discrete component mock-up on a breadboard and it worked okay, but I just could not get the timing slow enough while keeping the fade rate the way I wanted. The rotation effect was either too fast with good fade, or the speed was right and it was too dim.
Here is a short video of the original discrete component circuit using a 555 and a couple of 4017s. There are some components that aren't connected. I was testing different things and just left them on the board.
That's when I started looking at PICs for my solution. I am trying to learn about changing PWM code in assembly language. The code I'm currently using is from http://picprojects.org.uk/projects/433chaser/index.htm and I modified it to suit my needs, but it only has four PWM states, off, dim, bright and very bright. This works pretty good using 6 LEDs and only lighting one LED to have it rotate around. I tried to use 8 LEDs, arranged in a circle and I lit two LEDs at a time (opposite of each other) to mimic a sealed-beam rotating PAR36 light that I'm trying to emulate. I can time the PIC to flash the "rotator" at 90 flashes per minute, but due to the PWM only having four brightness's, it looks jittery. I asked the writer of the original code to point me in the right direction, so I could add a few more states, but he said that it would take too much to modify the code and that if he had to do that, he would start over and write a new program in C. That is way over my head. So, I ask the experts here, what do I need to do to add a few more PWM states to the source code in the above link?
Here is the area of the code that pertains to the PWM operation. The writer pointed me here, but I have absolutely no clue where to start. The area where I played around with is in the SeqData.inc file. That is where I changed which LED is lit, how bright and when, as well as the hold time between cycles. It works, it is just a little too jittery.
I read quite a bit on how the PIC gets its instructions and how the code works, but I'm just a simpleton, so any help is greatly appreciated.
Thank you in advance.
Here is a short video of the original discrete component circuit using a 555 and a couple of 4017s. There are some components that aren't connected. I was testing different things and just left them on the board.
That's when I started looking at PICs for my solution. I am trying to learn about changing PWM code in assembly language. The code I'm currently using is from http://picprojects.org.uk/projects/433chaser/index.htm and I modified it to suit my needs, but it only has four PWM states, off, dim, bright and very bright. This works pretty good using 6 LEDs and only lighting one LED to have it rotate around. I tried to use 8 LEDs, arranged in a circle and I lit two LEDs at a time (opposite of each other) to mimic a sealed-beam rotating PAR36 light that I'm trying to emulate. I can time the PIC to flash the "rotator" at 90 flashes per minute, but due to the PWM only having four brightness's, it looks jittery. I asked the writer of the original code to point me in the right direction, so I could add a few more states, but he said that it would take too much to modify the code and that if he had to do that, he would start over and write a new program in C. That is way over my head. So, I ask the experts here, what do I need to do to add a few more PWM states to the source code in the above link?
Here is the area of the code that pertains to the PWM operation. The writer pointed me here, but I have absolutely no clue where to start. The area where I played around with is in the SeqData.inc file. That is where I changed which LED is lit, how bright and when, as well as the hold time between cycles. It works, it is just a little too jittery.
Code:
; PWM Function
_pwm movfw vc0 ; AND all 5 bits of vertical counter
andwf vc1,W
andwf vc2,W
andwf vc3,W
andwf vc4,W
iorwf pwmOutput,F ; then OR bits with pwmOutput working variable
movfw pwmOutput ; load in W
; when 5 bits in vertical count reach 11111
; corresponding Port bit is turned on and then
; remains on until counter is reset
movwf PORTA ; write to PORTA
andlw 0xF0 ; force W to xxxx0000
iorwf copyPORTB,W ; copy the software oscillator output bit
movwf PORTB ; and write to physical PORTB
; ---------------------------------------
; 2^5 bit x 8 vertical counter
; generates the pwm for the 8 channel LED output
; http://everything2.com/e2node/vertical counter
_vc32 movf vc3,W
andwf vc2,W
andwf vc1,W
andwf vc0,W
xorwf vc4,F
movf vc2,W
andwf vc1,W
andwf vc0,W
xorwf vc3,F
movf vc1,W
andwf vc0,W
xorwf vc2,F
movf vc0,W
xorwf vc1,F
comf vc0,F
; ---------------------------------------
decfsz pwm,F ; decrement PWM counter
return ; return if count != 0
; reset and reload PWM output / counter
movlw .31 ; reload PWM counter
movwf pwm
clrf pwmOutput ; reset output port working variable
; vertical counter is 8 channels by 5 bits
; rvc1 rvc0 vc4-0 PWM ratio
; 0 0 00000 0/31 off
; 0 1 00001 1/31 dim
; 1 0 00100 8/31 bright
; 1 1 11111 31/31 very bright
;
movfw loReload ; reload the vertical counter
movwf vc0
movfw hiReload
movwf vc3
andwf loReload,W
movwf vc1
movwf vc2
movwf vc4
return
I read quite a bit on how the PIC gets its instructions and how the code works, but I'm just a simpleton, so any help is greatly appreciated.
Thank you in advance.