How to set HPWM to generate 38khz signal? (16F870)


Results 1 to 11 of 11

Threaded View

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


    Did you find this post helpful? Yes | No

    Default Re: How to set HPWM to generate 38khz signal? (16F870)

    Knocked this up when the remote for my aircon died , never really finished it . got a clone remote on ebay for $10 (delivered)
    why bother.

    this can work for any osc >= 8 MHz


    Code:
    '****************************************************************
    '*  Name    : ir38khz.BAS                                       *
    '*  Author  : RICHARD                                           *
    '*  Notice  :                                                   *
    '*          :                                                   *
    '*  Date    : 6/30/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : REPL BRA WITH GOTO  FOR NASTY OLD CHIPS           *
    '*          : OSC MUST BE AT LEAST 8 MHZ                        *
    '****************************************************************
     
    
     
     
     
    DEFINE OSC 16       ; MIN=8     TESTED  OK 8,16,32
    DEFINE IRPORT  LATC 
    DEFINE IRPIN  4 
    define IR_1   2000     ; 1 TIME IN uS   MAX 6500 ISH
    define IR_0   900      ; 0 TIME IN uS
     
    cycnt       var byte  bank0       ;set to numbr of 38k cycles req then call irout  RANGE 1-255
    dly         var byte  bank0      ;system
    
    goto overasm
     asm  
    _irout1                 ;entry point FOR 1 pulse   
            movlw   (IR_1/26)
            movwf   _cycnt
            BRA     _irout    ;GOTO 
    _irout0 movlw   (IR_0/26) ;entry point FOR 0 pulse   
            movwf   _cycnt       
            
    _irout                 ;entry point for cycnt cycles
    nxbt    CHK?RP IRPORT
            BSF IRPORT ,IRPIN
            CALL dly13
            CHK?RP IRPORT
            BCF  IRPORT ,IRPIN
            CALL dly13
            RST?RP
            DECFSZ _cycnt,F
            BRA nxbt             ;GOTO
            RETURN 
    dly13   movlw   (OSC-(16/OSC))
            RST?RP 
            movwf   _dly
    d13         
            DECFSZ _dly,F
            BRA d13           ;GOTO
            RETURN
     endasm        
       
    overasm:         
      
     
    
       OSCCON=$78
       ANSELA=0
       ANSELC=0
    
       TRISA = %111110
       TRISC = %11000011         ' set PORTC I/O
     
     
      
    main:
        cycnt = 100
        call irout
        pauseus 250
        call irout1
        pauseus 250
        call irout0
        pause 50
        
    goto main
    Last edited by richard; - 1st July 2016 at 03:35. Reason: comments
    Warning I'm not a teacher

Similar Threads

  1. How can I stop HPWM and then manually set the pin level?
    By gavinthacker in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2016, 16:55
  2. 6 HPWM signal generation with PIC18F4431
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th March 2013, 05:00
  3. 38Khz Modulator
    By Gord11 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th September 2011, 08:14
  4. HPWM signal transfered to an other pin!
    By lilimike in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd April 2010, 19:25
  5. Generate a 120Khz signal using the pic16F877a
    By texas5 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 11th September 2008, 21:59

Members who have read this thread : 1

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