PIC18F1320 HPWM on 2 pins


Closed Thread
Results 1 to 22 of 22
  1. #1
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116

    Talking PIC18F1320 HPWM on 2 pins

    Hello Folks,

    iīm trying to get my favorite PIC18F1320 to give out two different HPWM duty cycles with the same frequencies . The Duty cyles differ wildly and are not correspondent. I read the data sheet and couldnīt figure out which pin relates to which HPWM Channel. I searched through the forum
    and was more confused than before.

    I ran one single HPWM channel successful on a PIC16F88 but two on a PIC18F1320 seem way more complicated.

    DEFINE CCP2_REG PORTB
    DEFINE CCP2_BIT 3

    that should be PortB.3

    Is there a CCP1_REG PORTB ?

    I Know with 40 MHz minimum frequency is 2442 Hz and
    CCP1CON=1

    Thats the end of my knowledge about HPWM configs.

    Iīm dreaming of:

    HPWM 1,duty1,2442
    HPWM 2,duty2,2442

    regards
    Mugelpower

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    The PIC18F1320 only has one CCP Module, CCP1. Whereas the Data Sheet claims 1, 2, or 4 outputs, they are all Half- Full-Bridge complimentary outputs of the CCP1 Frequency & Duty Cycle. To achieve your goals, you need a processor with at least 2 CCP Functions. I'm not sure if your project requires an 18F part, but there are several 16F parts with 14/20 pins that incorporate 2+ CCP Modules. Here are some:

    PIC16F1507_8_9 (have 4 CCP Modules)
    PIC16F1615_9 (have 2)
    PIC16F1704_5_8_9 (2)
    PIC16F1713_6-9 (2)

    The list goes on and on. Sometimes you just have to move into the newer processors to achieve your goals.

  3. #3
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Mpgmike,

    you are right. I did a HPWM single channel with a 16F88 and it worked great. So I guess its waaaay easier to use two
    PICs than to scramble everything in just one.
    In my experience the use of multiple IF...THEN slows my 40 MHz PIC down to pure uselessness...
    I got the 18F1320 to measure speed and calculate fuel pump speed so I will go for a second PIC to measure temperature and control water pump speed. And show that on an LCD of course. Iīll have to get into hserout , baud rate and such strange things.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    In my experience the use of multiple IF...THEN slows my 40 MHz PIC down to pure uselessness...
    you can't be doing it the right way

  5. #5
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Guys,
    need alittlehelp because iīm totally stuck.
    Trying to send one byte from a PIC16F876A to a PIC16F88 and display it.
    Tried Debug,Serin and donīt get it working.
    Everything works in the proram exept the serout - serin communication.Tried with pullup resistor, baud rates from 1200 to 9600, negative and true.....tried to get samples from this forum, tried samples out of several PIC programming books, I donīt get it.
    Hello World2serin.txtADCINBargraphserout.txtHello World2serin.txt

  6. #6
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello folks,
    please help because Iīm totally stuck.
    Try to send one byte from a 16F88 to a 16F876A and display it on LCD using DEBUG.
    16F88 measures voltage on one pin and send the variable adval to 16F876A.
    Problem is: the LCD at the 16F876A shows only 4 different charcters: 48 up to 51 or if I change from DEC3 to DEC1 0 to 3.
    Should be 0 to 255 . The Voltage at the analog Input goes the full way from 0V to 4.8V but the LCD shows only 4 different characters which change at about 1/4 of the voltage change, so its proportional to the voltage change .
    I get the message "some configuration words are not in hex" from my PICKIT2 but only when programming the 16F88.

    Transmitter:

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 01.03.2012 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    '************************************************* ***************
    '* Name : AnalogDEBUG *
    '* Author : [Davidpower] *
    '* [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 05.12.2017 *
    '* Version : 1.0 *
    '* Notes : 16F88 no LCD *
    '* : Portb.7 analog IN 0-5V *
    '************************************************* ***************


    Include "modedefs.bas"

    Define OSC 4
    Define ADC_BITS 4 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_Mode 0
    DEFINE DEBUG_PACING 1000



    CMCON = 7 ' Disable analog comparator
    ANSEL = %01000000 ' set AN6 (RB7) as analog, others to digital
    ADCON1.7 = 1 ' Right justified results... duh... really needed in 8 bits???

    adval VAR WORD


    PAUSE 1000 ' lcd settle time
    DEBUG 10,13

    loop:
    ADCIN 6,adval ' Read channel 6 (RB7)



    DEBUG #adval

    Pause 100



    Goto loop

    End

    Receiver:
    '************************************************* ****************************
    '* MICROCODE STUDIO TIPS *
    '* *
    '* (1) : To get context sensitive help, move your cursor to a PICBasic *
    '* : command and then press F1. *
    '* (2) : Program assumes the PIC is running at 4MHz. To change the default *
    '* : setting (for example, to 20MHz) simply add DEFINE OSC 20 at the *
    '* : top of your program. *
    '* 16F876A 4zeiliges Display, 4 analoge eingänge *
    '* DEBUG PORTB.0
    'This sample program is supplied courtesy of microEngineering Labs Inc *
    '************************************************* ****************************

    ' PicBasic Pro program to display result of
    ' 8-bit A/D conversion on LCD
    ' Connect analog input to channel-0 (RA0)


    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 3
    DEFINE LCD_LINES 4
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50



    DEFINE DEBUGIN_REG PORTC
    DEFINE DEBUGIN_BIT 7
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUGIN_Mode 1


    DEFINE osc 4

    Include "modedefs.bas"

    CMCON = 7
    CVRCON = 0
    adval VAR WORD






    TRISC = %10000000

    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %00000000 ' Set PORTB to all output
    ADCON1 = %00000010 ' Set PORTA analog



    Pause 1000 ' Wait .5 second
    LCDOUT $FE, 2
    loop:

    DEBUGIN 1000,timeout,[adval]
    pause 50
    timeout

    LCDOUT $FE, 2

    Lcdout $fe,$C0 ' Move cursor to beginning of second line
    Lcdout "Ext ", DEC3 adval ' Display the decimal value



    Pause 100 ' Wait .1 second

    Goto loop ' Do it forever



    End

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


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Code:
    Define ADC_BITS 4 ' Set number of bits in result
    from manual
    You may set ADC_BITS to values 8-16, but in reality the result will either be 8-bits or the maximum precision available (10-bits, in most cases).
    Code:
    DEBUG #adval
    could send 1 to 5 ascii chrs for a word value {adc value 1 to 4 chrs }

    Code:
    DEBUGIN 1000,timeout,[adval]
    how is that meant to work ? you will also discover debug sends/receives bytes not words

    DEBUGIN 1000,timeout,[dec adval]
    might have a chance.

    simplistic async coms like this is seldom reliable, especially if the receiver has other tasks to perform other
    than sitting there waiting for a transmission.

    packetizing data in stx/etx codes and preferably with crc too is a better choice
    Warning I'm not a teacher

  8. #8
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Richard,
    o that... Itried for hours, read many threads here in the forum, tried "dec,dec2,dec3 , hex, bin,#" and without, ADC 8 bits, ADC 4 bits. It makes simply hardly a difference. Possible outcomes are:
    0 to 3
    000 to 003
    48 to 51

    or nothing.

    when I change

    DEBUG adval

    into

    DEBUG adval,10,13

    I will receive a 3 digit fast running number, impossible to read and no correspondece to the position of the poti for the analog Input.




    I got the input in the 16F876A from 0 to 3
    which is in the direction i need but way too coarse, then changed DEBUGIN_MODE 0 to 1 at the receiver still having DEBUG_MODE 1 at the transmitter and what: made no difference receiveived 0 to 3.
    That was the point when I realized that Iīm stuck.

    Of course tried serin, serin2,hserin. Nothing worked.
    Debug/Debugin shows at least anything at the receiver end.

    maybe my include file for the 16F88 is corrupt because I changed something 10 years ago. I will control that.

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    DEFINE DEBUG_Mode 0

    IS INCORRECT and simply won't do anything

    pbp defines must be uppercase


    try it this way tx:-

    DEFINE DEBUG_MODE 0
    DEFINE DEBUG_BAUD 9600



    DEBUG "*.*",DEC5 GLCDBM ,13,10




    rx


    SERIN2 PORTC.7,84,[ WAIT("*.*") , DEC RX] ;





    if this is still your goal
    So I guess its waaaay easier to use two
    PICs than to scramble everything in just one
    then you are sadly misguided , its never easier . get a better chip that's way easier
    if your goal is different why not start a more relevant thread

    either way post your latest code
    Warning I'm not a teacher

  10. #10
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Richard,

    thank you for your fast answer.

    I Know about the upper case sensitivity of Defines but it was obviously too late yesterday.

    Didnīt know DEBUG and SERIN2 can be mixed.

    I always thought how would one PIC know when to receive without handshake. Tried HSERIN for that with the RX and TX lines.

    Didnīt work of course althoug both PICs have a USART.

    Will try that at home this evening because its about noon by now and Iīm at work. Nothing with PICs, just metal and engines.

    regards

    Mugel

  11. #11
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Lightbulb Re: PIC18F1320 HPWM on 2 pins

    Hello Richard,

    by using the right PIC you may think of something like this:

    http://www.microchip.com/wwwproducts/en/PIC16F15323

    I donīt believe PBP supports that one or similar new ones.

    Iīm shure with 10 (or 30) more IQ points I could program an older one thats supported by PBP

    but Iīm stuck to my own miserable brain.


    regards
    Mugel

  12. #12
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Actually Mugel, PBP3.1 does support the PIC16F15323. At the cost of a few extra pins might I suggest something like the PIC18F26K22. It has 2 USART ports and can run @64Hhz.
    Dave Purola,
    N8NTA
    EN82fn

  13. #13
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    ahhh,

    you are trying to talk me weak for buying PBP3?

    may work......

  14. #14
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Richard,

    i tried your example and i get compilation error "DEBUG " bad expression or "SERIN2 bad expression"

    I even used a PBP example that was delivered with my software and I get the same "HSERIN bad expression" compilation error.
    So I have a software problem but I donīt know where to search.

  15. #15
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    i tried your example and i get compilation error "DEBUG " bad expression or "SERIN2 bad expression"

    a totally meaningless statement


    you need to post the complete code you are trying , also state the version of pbp you are using
    Warning I'm not a teacher

  16. #16
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Richard,

    Iīm using an old PC that runs XP Professional.
    MPLAB IDE v 7.61
    Microcode Studio 3.0.0.5
    Compiler Picbasic Pro 2.50C
    Programmer PICKIT2 and 3


    Complete Code:


    '************************************************* ***************
    '* Name : AnalogDEBUG *
    '* Author : [Davidpower] *
    '* [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 05.12.2017 *
    '* Version : 1.0 *
    '* Notes : 16F88 no LCD *
    '* : Portb.7 analog IN 0-5V *
    '************************************************* ***************


    Include "modedefs.bas"

    Define OSC 4
    Define ADC_BITS 4 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_Mode 0
    DEFINE DEBUG_PACING 1000



    CMCON = 7 ' Disable analog comparator
    ANSEL = %01000000 ' set AN6 (RB7) as analog, others to digital
    ADCON1.7 = 1 '

    GLCDBM VAR WORD


    PAUSE 1000 ' lcd settle time
    DEBUG 10,13

    loop:
    ADCIN 6,GLCDBM ' Read channel 6 (RB7)

    DEBUG "*.*",DEC5 GLCDBM,13,10


    Goto loop

    End


    The DEBUG line gives the compiling error "bad expression"

    If I use for example :

    DEBUG GLCDBM

    then no compiling error shows up. Doesnīt mean that it works.

  17. #17
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Richard,

    to be shure I ordered PBP3 Gold and Microcode studio 5.0 today. Will see if that helps. One question: What Computer do I need for that software?

    Regards

    Mugel

  18. #18
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hi,

    I copied the code in post #16 into microcode studio version 4.0.0.0, selecting 16F88 in the drop down menu and clicked on compile and it compiled using PBP 2.60c with MPSAM 5.06 with no errors

    The only change I had to make was change LOOP to MAIN for the main program loop

    Code:
    '************************************************* ***************
    '* Name : AnalogDEBUG *
    '* Author : [Davidpower] *
    '* [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 05.12.2017 *
    '* Version : 1.0 *
    '* Notes : 16F88 no LCD *
    '* : Portb.7 analog IN 0-5V *
    '************************************************* ***************
    
    
    Include "modedefs.bas"
    
    Define OSC 4
    Define ADC_BITS 4 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_Mode 0
    DEFINE DEBUG_PACING 1000
    
    
    
    CMCON = 7 ' Disable analog comparator
    ANSEL = %01000000 ' set AN6 (RB7) as analog, others to digital
    ADCON1.7 = 1 '
    
    GLCDBM VAR WORD
    
    
    PAUSE 1000 ' lcd settle time
    DEBUG 10,13
    
    main:
    ADCIN 6,GLCDBM ' Read channel 6 (RB7)
    
    DEBUG "*.*",DEC5 GLCDBM,13,10
    
    
    Goto main
    Mugel if you could use the code tags to insert code it makes the post easier to read ( use [ code ] insert your code here [ / code ] - remove the spaces between square brackets and code)

    Not sure if the code works as it should, but thought I would see if it compiled on an version 2.60 with an old copy of MPSAM...

  19. #19
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    MPLAB IDE v 7.61


    try to install MPLAB 8.92 ( XP compatible ) before going any further ... here : https://www.microchip.com/developmen...nloads-archive

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  20. #20
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Acetronics2,

    i installed PBP3 and everything on my Laptop which runs Wndows8. But still get this "Not all words are hex" warning while programming. Will hardware test it at the weekend.

    thanks for your input.

  21. #21
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: PIC18F1320 HPWM on 2 pins

    Hello Folks,

    so at least I got it working. No loud laughs please, I'm too old to stand it.
    Code is like this:
    TX
    '************************************************* ***************
    '* Name : 16F88debug1 *
    '* Author : MUGELPOWER/2 *
    '* Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 08.12.2017 *
    '* Version : 1.0 *
    '* Notes : WORKS! *
    '* : *
    '************************************************* ***************


    Define OSC 4
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 0
    DEFINE DEBUG_PACING 1000

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00000010 ' Set PORTA analog

    CMCON = 7 ' Disable analog comparator
    ANSEL = %01000000 ' set AN6 (RB7) as analog, others to digital

    RX VAR WORD


    PAUSE 1000 ' lcd settle time
    DEBUG 10,13

    Main:
    ADCIN 6,RX ' Read channel 6 (RB7)


    DEBUG "*.*",DEC3 RX ,13,10 ' dec3 is important

    Goto Main


    End

    RX:

    '************************************************* ***************
    '* Name : 16F876ADEBUGINa *
    '* Author : MUGELPOWER/2 *
    '* Notice : Copyright (c) 2017 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 08.12.2017 *
    '* Version : 1.0 *
    '* Notes : WORKS! *
    '* : *
    '************************************************* ***************


    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 3
    DEFINE LCD_LINES 4
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50


    ' Set Debugin pin port
    DEFINE DEBUGIN_REG PORTC
    ' Set Debugin pin bit
    DEFINE DEBUGIN_BIT 7
    ' Set Debugin baud rate (same as Debug baud)
    DEFINE DEBUG_BAUD 2400
    ' Set Debugin mode: 0 = true, 1 = inverted
    DEFINE DEBUGIN_MODE 0
    DEFINE osc 4


    CMCON = 7
    CVRCON = 0
    adval VAR WORD
    RX VAR word





    TRISC = %10000000

    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %00000000 ' Set PORTB to all output
    ADCON1 = %00000010 ' Set PORTA analog



    Pause 1000 ' Wait 1 second
    LCDOUT $FE, 2
    LCDOUT $FE,$C0,"HELLO"
    PAUSE 2000

    Main:


    DEBUGIN [WAIT("*.*"),DEC RX] 'dec is important


    LCDOUT $FE, 2
    pause 100

    Lcdout $fe,$C0 ' Move cursor to beginning of second line
    Lcdout "Ext=", DEC3 RX ' Display the decimal value


    Goto main ' Do it forever



    End

    Two main problems before:

    1. yes Scampy youre right: Main not Loop
    2. ADCON1.7 = 1 had to be erased, after that the reciever shows 0 to 255 and not 0 to 3.

    Thanks for your help.
    Thanks Crownhill for the fast delivery of PBP3

  22. #22
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Wink Re: PIC18F1320 HPWM on 2 pins

    Hello Acetronics2,
    now I guess I know how to post pictures.

    Name:  20171208_211220.jpg
Views: 677
Size:  560.5 KB

Similar Threads

  1. PIC18F1320 Config Help
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th June 2013, 07:31
  2. Timer 3 config for HPWM using remappable pins
    By jimbostlawrence in forum General
    Replies: 1
    Last Post: - 5th December 2012, 15:26
  3. PIC - 8 Pins - 6 Output Pins ?
    By DanPBP in forum Off Topic
    Replies: 0
    Last Post: - 22nd October 2007, 01:23
  4. Setting up 5 HPWM pins on 18F4680
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd August 2006, 06:54
  5. Compiling error with PIC18F1320
    By mazlan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 26th November 2004, 02:01

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