Menu

HELP PIC16F1704 issues - resolved

Help
Gigi
2019-08-25
2019-08-26
  • Gigi

    Gigi - 2019-08-25

    I can't get this PIC to work for the first time.
    From my tests the problem is that the internal oscillator does not work, it seems dead, I have tried many FUSE configurations and OSCCON register, I did tests even without setting anything since the default GCB seems to put an internal 32Mhz oscillator but it doesn't work.
    I attach a test code just to see if I change the output PIN the rest of the code is all to fix, note that I have set the CLOCK fuse output to PIN to see if it works, 300-400Khz wave trains come out and nothing else .
    I hope someone can help me.

    '***************************************************************
    '*  Name    : PWM test                                        *
    '*          :                                *
    '*  Date    : 08/2019                                        *
    '****************************************************************
    ' -- OSC=8 + PLLx4 32Mhz -- 
    #chip 16F1704,32      'Velocità in Mhz oscillatore interno
    #config FOSC_INTOSC, PLLEN_OFF, WDTE_OFF, MCLR_ON, PWRTE_ON, BORV_HI, LVP_OFF, CLKOUTEN_ON
    
    #option explicit
    
    'On Interrupt Timer0Overflow call TM0_int
    'On Interrupt Comp1Change call CMP_int
    
    '===========================================================================
    '*****  SETTAGGIO PORTE
    #define a0      PORTA.0     '
    #define Cp1-     PORTA.1     ' input V_out TENSIONE (2.5Volt ref.)
    #define CLC1     PORTA.2     ' OUT CLC1
    #define A3      PORTA.3     ' (solo INP)
    #define A4      PORTA.4     ' OUT C1
    #define A5      PORTA.5     ' OUT C2
    '-------------------
    #define C0        PORTC.0    '
    #define CP2-      PORTC.1    ' Input corrente (DAC REF.+)
    #define pinX      LATC.2    '
    #define Pwm       PORTC.3    '
    #define En        PORTC.4    ' LCD data LCD seriale
    #define Rs        LATC.5    ' LCD clock
    
    '============ VARIABILI ===========================================
    #define Ric_T1     65405          '
    #define Ric_T0      150           ' Frequenza del PWM
    
    dim T0cal       as byte at 50
    dim Temp1       as byte
    dim Temp        as byte
    dim Temp2     as byte
    dim Wtemp     as word
    dim Stato       as byte        ' FLAG controllo errori ecc.
    
    '==== SETTAGGI DELLE PORTE DEL PIC I/O ======================
    reset:
    Rs= 1
    OSCCON= b'11110000'
    'OSCSTAT= solo READ         ; OSCILLATOR STATUS REGISTER
    'OSCTUNE=                  ; OSCILLATOR TUNING REGISTER
    
    ' --------  bit a bit controllo 0=output  1=input
    dir porta  b'00001011'    ' impostazioni INP/OUT
    dir portc  b'00000011'    ' delle porte  (1,2 occupati BUS)
    
    ' -- INIZIALIZZA
    'InitPPS
    'InitCLC
    
    ' -- TIMER0
    'psa =1 : t0cs = 0          ' attiva timer0 NO prescaler
    'OPTION_REG=b'11011010'    '   step 10uS circa
    
    ' -- TIMER1              ' Timer1 ON -- prescaler /8
    'TMR1GE = 1     ' attiva PIN T1Gate
    'InitTimer1 Osc, PS1_1    '   setta OSC & prescaler
    'StartTimer 1
    
    ' -- CMP1 & VREF
    CM1CON0= b'10000100'         ' CM1 tensione OUT
    CM1CON1= b'00110000'
    ' --  CMP2
    CM2CON0= b'10000100'         ' CM2 OVER corrente
    CM2CON1= b'00101001'
    
    FVRCON = b'10101000'         ' Volt ref. 3.1V
    ' -- DAC1
    DAC1CON0=  b'10001000'
    'DAC1CON1=  b'10101000'
    
    wait 100 ms                   ' RITARDO impulsi spuri
    
    'timer1= Ric_t1:tmr0= Ric_t0
    'IntOn
    
    do
    
    rs= ! rs
    
    loop
    
    Sub TM0_int    'RX-38400 -- TX-57600   RX BUS PICNET
    '  pinX=0
    '  tmr0= Ric_t0
      pinX= ! pinX
    
    End Sub
    
    sub CMP_int
       pinx= C2OUT   ' blocca PWM over_tensione
    '   if c1out=0 then pinX=0  ' blocca PWM over_current
    
      CMIE= 0
    end sub
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.5.26
        'PinManager data: v1.76
        'Generated for 16f1704
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16f1704
    
        Sub InitPPS
               'Module: CLC1
                RA2PPS = 0x0004    'LC1OUT > RA2
                'Module: CMP1
                RA4PPS = 0x0016    'C1OUT > RA4
                'Module: CMP2
                RA5PPS = 0x0017    'C2OUT > RA5
    
        End Sub
        'Template comment at the end of the config file
    sub InitCLC
      CLC1GLS0  = 0x02;
      CLC1GLS1  = 0x00;
      CLC1GLS2  = 0x00;
      CLC1GLS3  = 0x80;
      CLC1SEL0  = 0x04;
      CLC1SEL1  = 0x00;
      CLC1SEL2  = 0x00;
      CLC1SEL3  = 0x0A;
      CLC1POL   = 0x00;
      CLC1CON   = 0x83;
      CLCIN0PPS = 0x00;
      CLCIN1PPS = 0x00;
      CLCIN2PPS = 0x00;
      CLCIN3PPS = 0x00;
    end sub
    sub test
    
    end sub
    
     
  • Anobium

    Anobium - 2019-08-25

    Sorry what does not work?

    What happens with the chip statement and the flashing of an LED? My guess that works. Please try. So, remove all the additional code and just try something simple.

    I am sure this is OK for the osc setup with the latest build.

    Anobium.

     
  • Gigi

    Gigi - 2019-08-25

    I thank you for your prompt reply, you are great.

    This does not work
    rs= ! rs ;#define Rs LATC.5 ' LCD clock

    I removed everything that is not needed, I enclose the code, tried it doesn't work, the internal oscillator seems dead, all the pins look like INPUT
    Use the latest version of GCB.

    '***************************************************************
    '*  Name    : PWM test                                        *
    '*          :                                *
    '*  Date    : 08/2019                                        *
    '****************************************************************
    ' -- OSC=8 + PLLx4 32Mhz -- 
    #chip 16F1704,32      'Velocità in Mhz oscillatore interno
    #option explicit
    
    '===========================================================================
    '*****  SETTAGGIO PORTE
    #define a0      PORTA.0     '
    #define Cp1-     PORTA.1     ' input V_out TENSIONE (2.5Volt ref.)
    #define CLC1     PORTA.2     ' OUT CLC1
    #define A3      PORTA.3     ' (solo INP)
    #define A4      PORTA.4     ' OUT C1
    #define A5      PORTA.5     ' OUT C2
    '-------------------
    #define C0        PORTC.0    '
    #define CP2-      PORTC.1    ' Input corrente (DAC REF.+)
    #define pinX      LATC.2    '
    #define Pwm       PORTC.3    '
    #define En        PORTC.4    ' LCD data LCD seriale
    #define Rs        LATC.5    ' LCD clock
    
    '============ VARIABILI ===========================================
    #define Ric_T1     65405          '
    #define Ric_T0      150           ' Frequenza del PWM
    
    dim T0cal       as byte at 50
    dim Temp1       as byte
    dim Temp        as byte
    dim Temp2     as byte
    dim Wtemp     as word
    dim Stato       as byte        ' FLAG controllo errori ecc.
    
    '==== SETTAGGI DELLE PORTE DEL PIC I/O ======================
    reset:
    
    ' --------  bit a bit controllo 0=output  1=input
    dir porta  b'00001011'    ' impostazioni INP/OUT
    dir portc  b'00000011'    ' delle porte  (1,2 occupati BUS)
    
    wait 100 ms                   ' RITARDO impulsi spuri
    
    do
    
    rs= ! rs
    
    loop
    
     
  • Anobium

    Anobium - 2019-08-25

    Try this, Keep things very simple to find out if there is real issue.

    #chip 16F1704,32
    #option explicit
    
    #define Rs        LATC.5
    dir Rs out
    
    do
    
        Rs= ! Rs
        wait 100 ms
    
    loop
    

    Also, please confirm version of compiler. You will find this information at the first line of the ASM file.

    If this fails. I will try a 16F1704 on Monday.

     
  • Gigi

    Gigi - 2019-08-25

    I tried, IT WORKS !!!!
    Of course I'd like to understand why, do you have any ideas? very strange, I don't think there are many things out of place
    MANY THANKS

     
    • Anobium

      Anobium - 2019-08-25

      Sure. Rebuild your code. Add functionality and test with each new piece of functionality.

      Avoid using things like dir porta b'00001011' ' impostazioni INP/OUT this command will work but you only need one bit out to confuse things.

      So. slowly rebuild.

      :-)

       
  • Gigi

    Gigi - 2019-08-25

    Yes, tomorrow I try to slowly reconstruct the code.
    Thanks good evening

     
  • Gigi

    Gigi - 2019-08-26

    I found, the problem is the label reset:
    I used it many times and it never gave me any problems, now everything works even the 8Mhz external clock, I lost a couple of days for so little.
    Good day
    CIAO

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.