Multi-Button CSM with Pic16LF722A


Closed Thread
Results 1 to 32 of 32

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,686


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    in this example I use indirect addressing to retrieve the data ,but due to the 12f1822 architecture only the low 8 bits are retrievable .wastes a bit of space but its heaps quicker

    Code:
    '****************************************************************
    '*  Name    : ws2812.BAS                                                                              *
    '*  Author  : richard                                                                                       *
    '*  Notice  :                                                                                                   *
    '*          :                                                                                                     *
    '*  Date    : 1/11/2016                                                                                  *
    '*  Version : 1.0                                                                                            *
    '*  Notes   : pic12f1822  @32 mhz 3v3                                                           *
    '*          : porta.5 >>>> ws2821 Din                                                             *
    '****************************************************************
     #CONFIG
    cfg1 = _FOSC_INTOSC
    cfg1&= _WDTE_ON
    cfg1&= _PWRTE_OFF
    cfg1&= _MCLRE_ON
    cfg1&= _CP_OFF
    cfg1&= _CPD_OFF
    cfg1&= _BOREN_ON
    cfg1&= _CLKOUTEN_OFF
    cfg1&= _IESO_ON
    cfg1&= _FCMEN_ON
      __CONFIG _CONFIG1, cfg1
    
    cfg2 = _WRT_OFF
    cfg2&= _PLLEN_ON
    cfg2&= _STVREN_ON
    cfg2&= _BORV_19
    cfg2&= _LVP_OFF
      __CONFIG _CONFIG2, cfg2
    
    #ENDCONFIG
    
     bt VAR byte  bank0
     px VAR byte  bank0
     pc var byte bank0   ; number of rgb led to write x3
    
     pixels  var byte[3]    ;  rgb led  x3
     DURATION  var byte
     
     palette var word    ;address of pallet
     TEMP VAR WORD
     OFFSET VAR WORD     ;pallet index
    
    
     
     
       
     goto overpalette   ; green,red,blue data   
     my_palette:     ;  note !!!  inde read can only access the low byte of each  stored  word
     @ dw 100,120,0  ;
     @ dW 0,100,0  ; RED
     @ dW 0,80,0  ;
     @ dW 0,60,0  ;
     @ dW 0,20,0  ;
     @ dW 200,200,0  ;OR
     @ dW 160,160,0  ;
     @ dW 100,100,0  ;
     @ dW 80,80,0  ;
     @ dW 2,5,0  ; 
     @ dW 200,150,0  ;YEL
     @ dW 160,120,0  ;
     @ dW 100,75,0  ;
     @ dW 80,60,0  ;
     @ dW 40,30,0  ; 
     @ dW 150,200,0  ; ?
     @ dW 120,160,0  ;
     @ dW 75,100,0  ;
     @ dW 60,80,0  ;
     @ dW 30,40,0  ; 
     @ dW 120,100,0  ;
     @ dW 160,160,160  ; WH
     @ dW 100,100,100  ;
     @ dW 80,80,80  ;
     @ dW 30,30,30  ;
    ASM  
     
    
    ;---[Returns the Address of a Label as a Word]------------------------------
    GetAddress macro Label, Wout
        CHK?RP Wout
        movlw low Label          ; get low byte
        movwf Wout
        movlw Label >> 8         ; get high byte
        movwf Wout + 1
      endm     
    endasm
    overpalette :  
     
     goto overasm
       asm
    _pram                     ;entry point to read from sram
            movlw   low _pixels
            movwf   FSR0L
            movlw   high _pixels
            movwf   FSR0H 
            goto _nxby
    _prom                     ;entry point to read from flash 
            CHK?RP _OFFSET
            MOVE?WW   _OFFSET , FSR0
            BSF FSR0H ,7
    _nxby   MOVIW  FSR0 ++
            movwf _px
            MOVLW 8
            movwf _bt
            RLF _px,F
    _nxbt   BSF LATA ,5
            BTFSS STATUS,C
            GOTO XX
            NOP
            NOP
            NOP
    XX      BCF  LATA ,5
            NOP
            RLF _px,F
            DECFSZ _bt,F
            GOTO _nxbt 
            DECFSZ _pc,F
            GOTO _nxby
            RETURN 
       
    endasm
    
    overasm:
    
    
    
     CLEAR
     define OSC 32
     osccon=$f0
     trisa=%011110
     @ GetAddress _my_palette,_palette  ;set pallet address
     
     
    loopy: 
     GOSUB FLICKER
     PC=3    ; value is  number of rgb leds X 3 
     call prom
     pause DURATION
     goto loopy
     
     
     
     
    FLICKER:
     RANDOM TEMP
     DURATION=TEMP&$7F
     RANDOM TEMP
    ' temp=0
     OFFSET =(TEMP //25)*3 + palette
    RETURN
    Warning I'm not a teacher

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,686


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    you can toggle on/off like this

    IF KP = 0 THEN '1/0 BUTTON PRESSED
    ;use p_level to see what state machine is in 0=off ,non zero = on
    if p_level then
    ccp1con=0 ;must be on kill it
    led=0
    p_level= 0
    else ;must be off power to max
    p_level= 5
    endif

    stoping it repeating too quickly is a bit trickier
    a pause that's long enough to allow reaction time would do , its a bit klunky.
    the best way is to wait for the key to be released before acting (or repeating the action)
    maybe counting three passes through main loop with flg=0 after an I/O key press would indicate key is released
    and its safe to re-enable the key
    Warning I'm not a teacher

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,686


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    since the isr TB1 is an accurate timebase you can
    make a new var
    Code:
     kio_inhibit var byte
    modify the I/o key routine
    Code:
    IF KP = 0 THEN '1/0 BUTTON PRESSED
            ;use  p_level to see what state machine is in  0=off ,non zero = on
            if kio_inhibit==0 then
               kio_inhibit=152    ;152*32mS = about 5 seconds
            if  p_level then     
                ccp1con=0 ;must be on kill it
                led=0
                p_level= 0
            else         ;must be off  power to max
                p_level= 5
            endif
           endif
    and add this to the isr

    Code:
    if kio_inhibit then
        kio_inhibit =  kio_inhibit -1
        endif
    now the I/O key is inhibited for 5 sec after being acted on

    I like ART's quote and its so true
    PBP is very well documented, however you’ll notice all examples of command use are also examples of exactly how not to write a cyclic program.
    you need to adjust your way of thinking to loops , states and flags . it opens up a whole new vista
    Last edited by richard; - 25th May 2016 at 09:26.
    Warning I'm not a teacher

  4. #4
    Join Date
    Apr 2016
    Location
    Mi, USA
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Wow, you are awesome. I'll have to try it out to see what it does. Thanks!

  5. #5
    Join Date
    Apr 2016
    Location
    Mi, USA
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Hello again,

    Was that timestamp of 3:12 as in 3:12AM?! I did the modification as above. It works like you explained. It doesn't cycle now, but the 5-second delay is way too long to be able to
    power it up again. If I change the kio_inhibit value to a shorter value, will it just end up cycling again? Is there a means that if the 1/0 button is released it resets the counter to zero so that the button can be used immediately again? The long delay is fine for when the button is being held for an extended period of time. Thanks!

  6. #6
    Join Date
    Apr 2016
    Location
    Mi, USA
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Hello again!

    Just curious as to why there isn't any reference to the PR2 register in the program, for setting up the PWM? If I wanted to increase the pwm frequency to 25Khz, I take it I would have to go to a higher oscillator frequency and use different prescaler values?! Thanks.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,686


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Just curious as to why there isn't any reference to the PR2 register in the program, for setting up the PWM?
    flicker is virtually invisible to the human eye for switching frequencies above 50 Hz, switching losses increase with frequency , other than that the frequency is irrelevant .
    fine control of the pwm frequency is possible using pr2 at the expense of resolution . since the frequency is largely irrelevant why not have maximum resolution


    If I wanted to increase the pwm frequency to 25Khz, I take it I would have to go to a higher oscillator frequency and use different prescaler values?
    depends on required resolution, @4mHz 25kHz is possible with 1:1 prescale and pr2=39 , however maximum duty occurs @ pwm_duty_reg = 160 , ie pw range is 0 to 160 (instead of 0 to 1023 steps as before)
    Warning I'm not a teacher

  8. #8
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Hi All,

    Has anyone had any experience with a 2 channel CSM slide switch?
    I would like to implement a slide switch rather than an up / down button arrangement to select the PWM output for a LED string.
    In my case, the granularity is quite coarse - only eight steps of PWM selection.

    Any input would be greatly appreciated.

    Cheers
    Barry

  9. #9
    Join Date
    Apr 2016
    Location
    Mi, USA
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Hello,

    Regarding the flicker, you know this and I know this, however, we are trying to match an existing product that is set at 25khz. It appears at lower frequencies
    it is causing their power supply to make audible noise at the PWM frequency. And sure enough, at 1khz, at certain pwm levels, we can hear it in the power supply. I don't have to keep the oscillator at 4khz, but I assume making any changes to the main Oscillator will also affect the touch circuit, as well. I did see in the pwm section of the datasheet that the resolution drops depending on the oscillator frequency after I posted this. Thanks again!

  10. #10
    Join Date
    Apr 2016
    Location
    Mi, USA
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: Multi-Button CSM with Pic16LF722A

    Sorry for the repeated post.
    Last edited by RWright; - 4th June 2016 at 05:11. Reason: Duplicate post

Similar Threads

  1. Replies: 5
    Last Post: - 18th March 2012, 22:40
  2. multi functions button press
    By malwww in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th May 2009, 01:12
  3. Multi-Threading
    By Ted's in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 2nd September 2008, 06:55
  4. Multi-tasking
    By malc-c in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 13th July 2006, 19:50
  5. Multi Interrupt How To ?
    By capitano in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd February 2005, 15:48

Members who have read this thread : 4

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