• slider image 442
  • slider image 477
  • slider image 479
  • slider image 480
  • slider image 481
  • slider image 482
:::

論壇索引


Board index » All Posts (Redjackson)




Re: 執行過程中,程式會自動暫停
#1
新會員
新會員


謝謝S大跟版主的回覆。
因為我沒有看到程式有跳出錯誤訊息,所以後來我選擇將WDT關閉,就不會重啟了。

發表於: 2021/6/3 22:27
頂部


Re: 執行過程中,程式會自動暫停
#2
新會員
新會員


謝謝版主回覆
想請問我的程式中沒有使用中斷,也會發生NMI嗎?

發表於: 2021/6/2 20:07

Edited by Redjackson on 2021年06月02日 20:55:23
頂部


執行過程中,程式會自動暫停
#3
新會員
新會員


先進您好,我是使用Pic24fj128g106這顆晶片。

在執行Debug的途中,程式會自動暫停,我原本以為是因為Debug模式的緣故,但是我將程式載入至晶片時也會不斷暫停,即便之後會自動重啟,也對於我正在執行的計畫有很大的影響,想請問是有什麼設定會造成這樣的現象嗎?

由於程式較多,所以先不放上來。主要有使用到的是UART、OC1、Timer2、A/D 這些功能,程式內並無設定中斷,所以初步判斷不是中斷引起的暫停(也可能有地方沒檢查到),想請問如何解決這個問題?

謝謝

發表於: 2021/5/30 17:59
頂部


如何看到暫存器及時的數值?
#4
新會員
新會員


各位前輩好,我目前正在做A/D轉換來控制PWM。

目前使用MPLAB IDE X在Debug模式下開啟variables視窗去檢視暫存器的數值(A/D轉換後的值)

但是無法即時看到數值改變,必須要暫停Debug才可以看到數值改變,請問有辦法即時看到數值的變化嗎?

發表於: 2020/12/15 22:21
頂部


Re: PIC24FJ128GB106 PWM頻率問題
#5
新會員
新會員


非常感謝您的回覆
當初在看到教育光碟的時候想說dspic30不適用於我這顆pic24的晶片,所以沒有讀到這部分。
我目前是照著mcc設定為Edge-Aligned PWM mode設定如附圖

您提到的方式我會再研究的,謝謝。

Attach file:



jpg  oc1.jpg (71.42 KB)
78057_5fc47184ea3bb.jpg 582X737 px

發表於: 2020/11/30 12:14
頂部


Re: PIC24FJ128GB106 PWM頻率問題
#6
新會員
新會員


您好,感謝回覆
我使用的是mcc的程式生成,以下是相關code

oc1的設定。
參照:
#include "oc1.h"

/** OC Mode.
  @Summary
    Defines the OC Mode.
  @Description
    This data type defines the OC Mode of operation.
*/

static uint16_t         gOC1Mode;

/**
  Section: Driver Interface
*/


void OC1_Initialize (void)
{
    
// ENFLT0 disabled; OCSIDL disabled; OCM Edge-Aligned PWM mode; OCFLT0 disabled; OCTSEL TMR2; TRIGMODE Only Software; 
    
OC1CON1 0x06;
    
// SYNCSEL TMR2; TRIGSTAT disabled; OCINV disabled; OCTRIG Trigger; OC32 disabled; FLTOUT disabled; OCTRIS disabled; FLTMD Cycle; FLTTRIEN disabled; 
    
OC1CON2 0xCC;
    
// CMP2B 100; 
    
OC1RS 1000;
    
// CMP1B 30; 
    
OC1R 300;
    
// OC1TMR 0; 
    
OC1TMR 0x00;
    
gOC1Mode OC1CON1bits.OCM;
    
IFS0bits.OC1IF false;
    
IEC0bits.OC1IE true;
}

void __attribute__ ((weak)) OC1_CallBack(void)
{
    
// Add your custom callback code here
}

void __attribute__ ( ( interruptno_auto_psv ) ) _ISR _OC1Interruptvoid )
{    
    if(
IFS0bits.OC1IF)
    {
        
// OC1 callback function 
        
OC1_CallBack();
        
IFS0bits.OC1IF 0;
    }
}


void OC1_Startvoid )
{
    
OC1CON1bits.OCM gOC1Mode;
}


void OC1_Stopvoid )
{
    
OC1CON1bits.OCM 0;
}

void OC1_SecondaryValueSetuint16_t secVal )
{
   
    
OC1RS secVal;
}


void OC1_PrimaryValueSetuint16_t priVal )
{
   
    
OC1R priVal;
}

bool OC1_IsCompareCycleCompletevoid )
{
    return(
IFS0bits.OC1IF);
}


bool OC1_FaultStatusGetOC1_FAULTS faultNum )
{
    
bool status;
    
/* Return the status of the fault condition */
   
    
switch(faultNum)
    { 
        case 
OC1_FAULT0:
            
status OC1CON1bits.OCFLT0;
            break;
        default :
            break;

    }
    return(
status);
}


void OC1_FaultStatusClearOC1_FAULTS faultNum )
{
    
    switch(
faultNum)
    { 
        case 
OC1_FAULT0:
            
OC1CON1bits.OCFLT0 0;
                break;
        default :
                break;
    }    
}


void OC1_ManualTriggerSetvoid )
{
    
OC1CON2bits.TRIGSTATtrue
}

bool OC1_TriggerStatusGetvoid )
{
    return( 
OC1CON2bits.TRIGSTAT );
}


void OC1_TriggerStatusClearvoid )
{
    
/* Clears the trigger status */
    
OC1CON2bits.TRIGSTAT 0;
}

/**
 End of File
*/


timer2的設定。

參照:
#include <stdio.h>
#include "tmr2.h"

/**
 Section: File specific functions
*/

/**
  Section: Data Type Definitions
*/

/** TMR Driver Hardware Instance Object

  @Summary
    Defines the object required for the maintenance of the hardware instance.

  @Description
    This defines the object required for the maintenance of the hardware
    instance. This object exists once per hardware instance of the peripheral.

  Remarks:
    None.
*/

typedef struct _TMR_OBJ_STRUCT
{
    
/* Timer Elapsed */
    
volatile bool           timerElapsed;
    
/*Software Counter value*/
    
volatile uint8_t        count;

TMR_OBJ;

static 
TMR_OBJ tmr2_obj;

/**
  Section: Driver Interface
*/

void TMR2_Initialize (void)
{
    
//TMR2 0; 
    
TMR2 0x00;
    
//Period = 0.01 s; Frequency = 8000000 Hz; PR2 9999; 
    
PR2 0x270F;
    
//TCKPS 1:8; T32 16 Bit; TON enabled; TSIDL disabled; TCS FOSC/2; TGATE disabled; 
    
T2CON 0x8010;

    
    
tmr2_obj.timerElapsed false;

}


void TMR2_Tasks_16BitOperationvoid )
{
    
/* Check if the Timer Interrupt/Status is set */
    
if(IFS0bits.T2IF)
    {
        
tmr2_obj.count++;
        
tmr2_obj.timerElapsed true;
        
IFS0bits.T2IF false;
    }
}

void TMR2_Period16BitSetuint16_t value )
{
    
/* Update the counter values */
    
PR2 value;
    
/* Reset the status information */
    
tmr2_obj.timerElapsed false;
}

uint16_t TMR2_Period16BitGetvoid )
{
    return( 
PR2 );
}

void TMR2_Counter16BitSet uint16_t value )
{
    
/* Update the counter values */
    
TMR2 value;
    
/* Reset the status information */
    
tmr2_obj.timerElapsed false;
}

uint16_t TMR2_Counter16BitGetvoid )
{
    return( 
TMR2 );
}




void TMR2_Startvoid )
{
    
/* Reset the status information */
    
tmr2_obj.timerElapsed false;


    
/* Start the Timer */
    
T2CONbits.TON 1;
}

void TMR2_Stopvoid )
{
    
/* Stop the Timer */
    
T2CONbits.TON false;

}

bool TMR2_GetElapsedThenClear(void)
{
    
bool status;
    
    
status tmr2_obj.timerElapsed;

    if(
status == true)
    {
        
tmr2_obj.timerElapsed false;
    }
    return 
status;
}

int TMR2_SoftwareCounterGet(void)
{
    return 
tmr2_obj.count;
}

void TMR2_SoftwareCounterClear(void)
{
    
tmr2_obj.count 0
}

/**
 End of File
*/


原本想放上截圖但圖片無法插入,以上是mcc生成的code

謝謝。

發表於: 2020/11/30 11:07
頂部


PIC24FJ128GB106 PWM頻率問題
#7
新會員
新會員


各位前輩好,小弟目前剛碰PIC24的晶片,以前也沒有過相關經驗,還請各位前輩多多賜教

我目前正在製作PWM,用的是PIC24FJ128GB106這塊晶片,使用MPLAB X IDE內的MCC撰寫程式

我上網查資料以及看了datasheet後有些地方一直不了解。

根據datasheet中pwm的頻率公式是:PWM Period = [(PRy) + 1] • TCY • (Timer Prescale Value)
裡面說明與PRy有關係。
但是測試後發現幾個問題:
1、我在調整PWM的DUTY時更動OCxRS OCxR 這兩個暫存器時竟然會連帶影響到PWM的頻率
2、根據原理,我調整PR2(我使用TIMER2)時並不會改變PWM的頻率
3、根據理論,當我的PR2+1我想請問要如何才能正確的調整PWM的頻率?
感謝

發表於: 2020/11/29 20:56
頂部






:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------