i'm writing a code for control three leds from serial port. so i started with only one led at first.
here is the codes :
@ DEVICE PIC16F628A
@ DEVICE PIC16F628A, WDT_OFF
@ DEVICE pic16F628A, PWRT_ON
@ DEVICE PIC16F628A, PROTECT_OFF
@ DEVICE PIC16F628A, MCLR_OFF
@ DEVICE PIC16F628A, BOD_OFF
@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT
OPTION_REG = %10000000
INTCON = %11000000
PIE1 = %00100000
TRISA=%00000000
ON INTERRUPT GoTO kestirici
CMCON=7
define HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
define HSER_BAUD 4800
led var byte[3]
par var byte[3]
par[0] = 128
basla
for led[0] = 0 to 255
if led[0] < par[0] then
high porta.0
else
low porta.0
endif
next
goto basla
disable
kestirici:
HSERIN [wait("t"),dec2 par[0]]
Resume
enable
When i started this project.I was using pauesus to create duty cycles.But that was making a phase difference problem.So i searched,searched... for another methods to drive leds. Then i found timer interrupt.That was using timer for delays so there wasnt any phase difference problem. So i decided to use timer interrupt.
But there was a problem againWhen i was trying to pwm one led with timer interrupt, that was fine. i got about 2000hertz. But if i try to pwm three leds. The frequency falls down about 60 hertz. (and i'm not even using hserin for all this codes yet).
Whatever. 60 Hertz is not bad. But how was i'm going to use hserin with that codes? i tried to insert the hserin command to main loop. Didn't worked.Frequency falls down.Tried with timeout 1ms and 0ms. Frequency falls down again.
After that, i decided to write timer interrupt codes to main loop and change the timer interrupt with serial interrupt.
So here is my codes i get about 100hertz right now with one led. WHY? That should be about 2000 hertz like in the timer interrupt. Is that about if-statements? if i use less if statement, frequency increases.
It is just one led. When i make it three. Frequency is about 30hz. That sucks.
If you have another idea for control three leds(brightness) from serial port with about 100hz. I'm ready for do it. I'm tired. Trying to do this thing for 2 weeks.
Bookmarks