16F1827 setup


Closed Thread
Results 1 to 26 of 26

Thread: 16F1827 setup

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Joe

    I do think this file means ...

    '************************************************* ***************
    '* 16F1827.BAS *
    '* *
    '* By : Leonard Zerman, Jeff Schmoyer *
    '* Notice : Copyright (c) 2009 microEngineering Labs, Inc. *
    '* All Rights Reserved *
    '* Date : 06/23/09 *
    '* Version : 2.60 *
    '* Notes : *
    '************************************************* ***************
    Somebody already did the job ...

    I want to use the ADC, HWPWM1 and 2, and some digital only I/O's
    and the dedicated library is here ...

    Alain
    Last edited by Acetronics2; - 5th February 2010 at 21:05.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Most peripherals on the 16F1827 are the same as previous parts, but you will need to
    spend some time going through the 1827 data sheet to find out which ones are the same,
    and which ones have changed.

    Definitely have a look at the APFCON0 & APFCON1 registers.

    Also, check your PI14EEXT.BAS to make sure it has APFCON0 VAR BYTE EXT and not
    APFCON VAR BYTE EXT.

    There should also be these definitions in the PI14EEXT.BAS file;
    Code:
    MDCON  VAR BYTE EXT
    MDSRC  VAR BYTE EXT
    MDCARH VAR BYTE EXT
    MDCARL VAR BYTE EXT
    If these aren't in there, just add them.

    Then you can do cool stuff like this with the new Data Signal Modulator....
    Code:
    '****************************************************************
    '*  Name    : DSM.BAS                                           *
    '*  Author  : B. Reynolds                                       *
    '*  Notice  : Copyright (c) 2010 http://www.Rentron.com         *
    '*          : All Rights Reserved                               *
    '*  Date    : 2/5/2010                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : Using the 16F1827 Data Signal Modulator for IR    *
    '*          : serial communications with onboard USART.         *
    '****************************************************************
    
    ' MODOUT, RB3, outputs whatever you send with HSEROUT as a 40kHz
    ' modulated data stream. 
    
    ASM
      __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
      __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _VCAPEN_OFF & _LVP_OFF & _STVREN_OFF
    ENDASM
    
    DEFINE OSC 8
    DEFINE HSER_BAUD 2400  
    Duty VAR WORD
    TRISB = 0
    
    Init:
      PR2 = 49             ' Set PWM for ~40kHz
      CCP1CON = %00001100  ' Mode select = PWM
      T2CON = %00000100    ' %00000100 = TMR2 ON 1:1 prescale
    
      Duty = 100           ' Roughly 50% duty cycle
      CCP1CON.4 = duty.0   ' Setup 10-bit duty cycle as
      CCP1CON.5 = duty.1   ' a 10-bit word
      CCPR1L = DUTY >> 2
      APFCON0 = 1          ' CCP1 PWM output on RB0
      OSCCON = %01110000   ' 8MHz internal
      ANSELA = 0           ' all digital. A/D disabled
      ANSELB = 0
      MDCON = %11100000    ' modulator, MODOUT pin, slew rate limiting enabled
      ' Note: set MDSRC.7 to eliminate the TX signal output on RB2/TX
      MDSRC = %00001010    ' USART TX is modulation source, TX output still active
      MDCARH = %00000000   ' carrier OFF during idle periods
      MDCARL = %00000100   ' carrier ON only when sending data
    
    Main:
      HSEROUT [$55]        ' sends USART data out modulated at 40kHz
      PAUSE 50
      GOTO Main
      END
    The output of your 40kHz IR module spits out serial data you send with HSEROUT.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3


    Did you find this post helpful? Yes | No

    Question

    Hello Bruce,

    I am not all that familiar with this chip yet. How is it different than the 16F877A using PWM1 at 38.8Khz and sending serial data out on say RB4 data out? The IR LED would then be placed between PWM1 out and RB4 to modulate the data stream.

    Just wondering if the 1827 has a nifty way of doing it... Do you have a schematic of how the IR led connects to the I/O, using the code you attached?

    Best Regards,
    Nick

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I am not all that familiar with this chip yet.
    Neither am I. That's the 1st bit of code I've compiled or tested on this one.
    How is it different than the 16F877A using PWM1 at 38.8Khz and sending serial data out on say RB4 data out?
    Quite a lot. With the 16F1827 you only need a single pin. Here's a schematic;
    RB3 ----/\/\/\-----|>|---GND.

    Or you could use an NPN transistor if you need more range. Look at the logic picture below.

    The top signal is the modulated data output from RB3 MODOUT. The lower signal is
    the USART TX output.

    Here's a copy of the previous code with better explanations, and both the USART TX out,
    and PWM output pins disabled.
    Code:
    ' MODOUT, RB3, outputs whatever you send with HSEROUT as a 40kHz
    ' modulated data stream. 
    
    ASM
      __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
      __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _VCAPEN_OFF & _LVP_OFF & _STVREN_OFF
    ENDASM
    
    DEFINE OSC 8
    DEFINE HSER_BAUD 2400  
    Duty VAR WORD
    TRISB = 0
    
    Init:
      CCPTMRS = %00000000  ' CCP1 is based off Timer 2 in PWM Mode
      PR2 = 49             ' Set PWM for ~40kHz
      CCP1CON = %00001100  ' Mode select = PWM
      T2CON = %00000100    ' %00000100 = TMR2 ON 1:1 prescale
    
      Duty = 100           ' Roughly 50% duty cycle
      CCP1CON.4 = duty.0   ' Setup 10-bit duty cycle as
      CCP1CON.5 = duty.1   ' a 10-bit word
      CCPR1L = DUTY >> 2
      APFCON0 = 1          ' Assigns CCP1 PWM output to RB0 (RB3 is used for MODOUT)
      OSCCON = %01110000   ' 8MHz internal
      ANSELA = 0           ' all digital. A/D disabled
      ANSELB = 0
    
      ' Data Signal Modulator setup
      ' Notes: 
      ' MDSRC.7 = 1, which eliminates the USART TX signal output on RB2/TX.
      ' The PWM output signal, on CCP1 pin, which is set to RB0 with APFCON0=1
      ' has been disabled by setting MDCARL.7
      ' So even with the hardware USART outputting data, and PWM on, thier output pins
      ' are disabled. PWM and the serial data output from the USART are "mixed" internally
      ' by the Data Signal Modulator.
    
      MDCON = %11100000    ' modulator, MODOUT pin, slew rate limiting enabled
      MDSRC = %10001010    ' USART TX is modulation source, TX output "pin" disabled
      MDCARH = %00000000   ' carrier OFF during idle periods
      MDCARL = %10000100   ' carrier ON only when sending data, CCP1 PWM "pin" output disabled
    
    Main:
      HSEROUT [$55]        ' sends USART data out modulated at 40kHz
      PAUSE 500
      GOTO Main
      END
    Even with PWM on, and the USART sending data, there is no PWM output on the CCP1 pin
    or data output on the USART TX pin. Both signals are mixed internally by the DSM,
    and output only on RB3 or MODOUT.

    I only had the USART TX pin output enabled to capture the logic analyzer traces below to
    show the MODOUT signal compared to the USART TX output signal.
    Attached Images Attached Images  
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5


    Did you find this post helpful? Yes | No

    Question

    Hello Bruce,

    I tried to compile your code, it had many errors. I have PBP 2.60, using PB assembler (not MASM). I went through the PI14EEXT.BAS and made the changes you advised. I have 1 error left "CCPTMRS". This does not exist in the PI14EEXT.BAS, only CCPTMRS0 and CCPTMRS1.

    Which of these did you intend?

    thanks!
    Nick

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Nick,

    Add CCPTMRS to your PI14EEXT.BAS file. There were several register definitions missing.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7


    Did you find this post helpful? Yes | No

    Question

    Hello Bruce,

    I made the changes, still nothing. I am getting a bunch of errors saying that the 16F1827.inc could not be found. It is giving me a BUNCH of errors. Errors for symbol not previously defined portA, PortB, portC...etc.

    I found the 16F1827.inc within the PBP directory, opened it up and it says not to use PB assembler, but rather MPASM. So I selected MPASM as my assembler, still I am getting a ton of errors using MPASM. I have never seen this many errors ever...wow.

    Nick

Similar Threads

  1. 16F913 setup
    By Andre_Pretorius in forum General
    Replies: 31
    Last Post: - 18th April 2010, 00:45
  2. TMR1 external LP xtal setup check
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th October 2009, 19:11
  3. ADCIN setup for PIC16F688
    By PixController in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th February 2008, 19:38
  4. ADCIN setup help need
    By dangill in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th February 2008, 16:22
  5. Use Button For setup
    By tump in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 21st November 2007, 20:43

Members who have read this thread : 3

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