Using HPWM to blink an LED?


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    I'm a bit confused about using the timer1. I have read Darrel's posts on his timers and trying to follow the code myself is very confusing. Is there a step by step explanation on how to do it. I didn't see anything in the manual and if there was I didn't see it.

    Thanks,

    Chris

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Chris,

    You've read this post?
    http://www.picbasic.co.uk/forum/showthread.php?p=23259

    What part don't you understand?

    How the Timer works?
    How the Interrupts work?
    How the program works?
    <br>
    DT

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Yes, I have read that post. I changed the prescaler and it does work but it's not what I am looking for because it only made the LED blink faster, not slower. I guess I was trying to solve my problem more simply. When using the HPWM command, the code is one line and as you know looks like this:

    hpwm 1, 1000,1000

    but when using the hpwm command, the control of the LED is more of a dimming function because it's just too fast for the naked eye see.

    In my current program within the main loop, I am using a pause 1 command and counting to 1000 and then toggling the LED. I guess I was just hoping that there was a 1 line command when you can say "I want to blink the LED every 2 seconds" or something like that.

    Chris

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default How many ways can you blink an LED?

    Oh, I see. Sorry about that Chris, with the talk of HPWM and duty-cycle, I thought you were going for the Fader. It helps to know as many details as possible at the beginning.
    Quote Originally Posted by Christopher4187
    I was just hoping that there was a 1 line command when you can say "I want to blink the LED every 2 seconds" or something like that.
    How's this look?
    Code:
    <font color="#0000FF"><b><i>; Initialise your Hardware first
    
    </i></b></font><b>LED      </b><font color="#008000"><b>VAR  </b></font><b>PORTB</b>.<b>2             
    ONstate  </b><font color="#008000"><b>CON  </b></font><b>1                   </b><font color="#0000FF"><b><i>; 0=ON when LOW, 1=ON when HIGH(default)
    
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;SingleLEDblinker.bas&quot;
    
    </font><font color="#000080">@ Blink  10, 190                  </font><font color="#0000FF"><b><i>; Blink 1/10 sec every 2 seconds
    
    </i></b></font><b>Main</b>:
      <font color="#008000"><b>PAUSE </b></font><b>1000
    </b><font color="#008000"><b>GOTO </b></font><b>Main</b>
    It uses DT_INTS-18 to get interrupts from timer1 every 10 ms, or 100hz.
    But you can just change it to DT_INTS-14 if using a 16F.

    It simply turns the LED ON, OFF for a number of periods specified by the constants provided.

    @ Blink 10, 190

    Will turn the LED ON for 10/100th's sec (0.1 sec). and OFF for 190/100th's (1.9 sec). The total of the two, determines the length of time between pulses (2.0 sec) and must be under 65535, which is 655 seconds.

    Other included commands are ...

    @ NoBlink ONtime, OFFtime

    This is the same as Blink, except that it doesn't start Blinking. It simply defines the ON and OFF times in preperation for a ...

    @ BlinkON

    which can then be placed somewhere else in the program to actually Start the LED blinking.

    Of course you need the ...

    @ BlinkOFF

    To round things out. And now it allows you to make a more custom blinking sequence.

    For instance, this one will "FLASH" the LED every second, instead of just Blinking it. Giving more of an "ALERT!" type of indication.
    Code:
    <font color="#0000FF"><b><i>; Initialise your Hardware first
    
    </i></b></font><b>LED      </b><font color="#008000"><b>VAR  </b></font><b>PORTB</b>.<b>2             
    ONstate  </b><font color="#008000"><b>CON  </b></font><b>1                   </b><font color="#0000FF"><b><i>; 0=ON when LOW, 1=ON when HIGH(default)
    
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;SingleLEDblinker.bas&quot;
    
    </font><font color="#000080">@ NoBlink  3, 3                   </font><font color="#0000FF"><b><i>; set Blink to 3/100 ON, 3/100 OFF
    </i></b></font><font color="#008000"><b>PAUSE </b></font><b>2000                        </b><font color="#0000FF"><b><i>; just to verify it's not blinking
    
    </i></b></font><b>Main</b>:
    <font color="#000080">@ BlinkON                         </font><font color="#0000FF"><b><i>; Start Flashing LED
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>1000                      </b><font color="#0000FF"><b><i>;  continue for 1 second
    </i></b></font><font color="#000080">@ BlinkOFF                        </font><font color="#0000FF"><b><i>; Stop Flashing LED
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>1000                      </b><font color="#0000FF"><b><i>;  for another second
    </i></b></font><font color="#008000"><b>GOTO </b></font><b>Main
    </b>
    Or here's several different Blink sequences ...
    Code:
    <font color="#0000FF"><b><i>; Initialise your Hardware first
    
    </i></b></font><b>LED      </b><font color="#008000"><b>VAR  </b></font><b>PORTB</b>.<b>2             
    ONstate  </b><font color="#008000"><b>CON  </b></font><b>1                   </b><font color="#0000FF"><b><i>; 0=ON when LOW, 1=ON when HIGH
    
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;SingleLEDblinker.bas&quot;
    
    
    </font><b>Main</b>:
      @ <b>Blink  2</b>, <b>10                  </b><font color="#0000FF"><b><i>; .02 ON, .1 OFF
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>4000
      
      </b>@ <b>Blink  10</b>, <b>10                 </b><font color="#0000FF"><b><i>; .1 ON, .1 OFF
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>4000
      
      </b>@ <b>Blink  20</b>, <b>10                 </b><font color="#0000FF"><b><i>; .2 ON, .2 OFF
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>4000
      
      </b>@ <b>Blink  50</b>, <b>50                 </b><font color="#0000FF"><b><i>; .5 ON, .5 OFF
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>4000
    
      </b>@ <b>Blink  50</b>, <b>10                 </b><font color="#0000FF"><b><i>; .5 ON, .1 OFF
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>5000
      
      </b>@ <b>BlinkOFF                      </b><font color="#0000FF"><b><i>; stop blinking
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>3000
      
      </b>@ <b>BlinkON                       </b><font color="#0000FF"><b><i>; resume blinking at same rate
      </i></b></font><font color="#008000"><b>PAUSE </b></font><b>5000
    </b><font color="#008000"><b>GOTO </b></font><b>Main
    
    </b>
    Attached Files Attached Files
    DT

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Wow, that's great! I didn't expect you to write it for me but I'm certainly not complaining. I'm still trying to learn more about PBP and this will help me a lot.

    Thanks,

    Chris

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Novice 16F83A BLINK LED program help
    By owali in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 25th July 2007, 05:02
  3. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  4. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts