StartTimer();
Loop forever
TimerValue = ReadTimer();
if TimerOverflowFlag = 1 then
LED1 = 0;
LED2 = 0;
LED3 = 0;
TimerOverflowFlag = 0;
end if;
if TimerValue > LED1TurnOnTime then
LED1 = 1;
end if;
if TimerValue > LED2TurnOnTime then
LED2 = 1;
end if;
if TimerValue > LED2TurnOnTime then
LED1 = 2;
end if;
end loop;
bmcculla said:You only need one timer.
pseudo code:
Code:StartTimer(); Loop forever TimerValue = ReadTimer(); if TimerOverflowFlag = 1 then LED1 = 0; LED2 = 0; LED3 = 0; TimerOverflowFlag = 0; end if; if TimerValue > LED1TurnOnTime then LED1 = 1; end if; if TimerValue > LED2TurnOnTime then LED2 = 1; end if; if TimerValue > LED2TurnOnTime then LED1 = 2; end if; end loop;
Forgive the weird mixed syntax I've got both C and VHDL on my brain right now. The timer should have a flag that gets set when the timer overflows (goes from 255 to 0) check the datasheet. You can use this flag to reset the pwm signal on all your LEDs. You then just keep looking at the timer and when it reaches the turn on time for each LED you turn on that LED. This should give you 256 levels more or less.
checkmate said:Why not just use 3 separate timers, each controlling the pwn of one LED? All three timers could easily be configured to run at different speeds, and changing bits only takes up a single clock cycle, so I'm pretty sure it'll be more than sufficient to handle all thre..
checkmate said:The Timer module not only counts. It can trigger interrupts after some condition is met. You can refer to the PIC mid-range manual on the section on timers. When this interrupt is triggered, you can add in code to do whatever processing you want, including setting I/O pins and checking states.
checkmate said:To set off three timers to run is the same as setting off one. Most PICs have at least 2-3 hardware timers for you to use that can be operated independently.
timothyjackson said:So, if a PIC has 3 hardware timers, this would limit the not of "different" fading rate LED's to three? If I wanted 5 different fading rate led's, I'd need 5 hardware timers?
How many instruction lines can I have when in the code(16f628)? a million????
Nigel Goodwin said:timothyjackson said:So, if a PIC has 3 hardware timers, this would limit the not of "different" fading rate LED's to three? If I wanted 5 different fading rate led's, I'd need 5 hardware timers?
No, you can do it all with interrupt code off a single timer, as 'bmcculla' previously mentioned.
There have been a couple of LED flasher/fader projects in EPE, you can download the software from their website.
How many instruction lines can I have when in the code(16f628)? a million????
The 628 has 2K of program memory, so basically 2048 instruction lines - this is a great deal of assembler!.
bmcculla said:You can manage each bit individualy using something called masking. Masking lets you change the state of only a few bits. I don't know PIC assembler so I'll just give you the basic idea. I'm only using 4 bits to keep the typing down, it'll be the same with 8 bits.
Say you have 0010 on a port and you want to change the first bit. You just use the OR operation: 0010 OR 1000 = 1010. Now if you want to change the first bit back to 0 you use the AND operation : 1010 AND 0111 = 0010. You still read and write the whole port at once but you change only the bits you want to before writing it back to the port.
timothyjackson said:Thanks Nigel. I've come across a bit of a problem.
I'm using (or will be) a programmer from Quasar electronics. Problem is, MPLAB doesnt work on the same PC that the programmer will be connected to (its running on win 95). So, is it ok to do my code writing/buidling simulating on one pc in MPLAB, and then, with a floppy disk, copy the .hex file to the other pc with the programmer???
Nigel Goodwin said:Yes, that's fine - it's no different to downloading a file off the net.
Nigel Goodwin said:Although I'm not sure why you can't get MPLAB to work on your other machine, as far as I know it should work on anything Win95 or later (but not on Win3.11 or earlier). The important part of MPLAB is the assembler, MPASM, you might try if that will work.
timothyjackson said:"MPLAB tools v7 requires Win 98 sE, Win mE, or NT, or 2000, or XP". So, I guess I'm stumped on that one. Unless, another version works with win 95, which can be downloaded elsewhere.
Nigel Goodwin said:I suspect those requirements are for USB support, earlier OS's didn't support USB (at least not enough to make it usable). It's only the recent versions of MPLAB which provide USB support, with the introduction of their own USB programmers - if you're not using a USB connection (and you're not using the programmer side of MPLAB at all), it may well install and work OK.
Nigel Goodwin said:Even if it won't run, if you can install it you should have the latest version of MPASM installed along with it - this is all you need to program PIC's. Personally I never use MPLAB, just the MPASM assembler.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?