機器のテスト用として、MOS-FETリレーを使って、一瞬の断線を再現する回路を作ってみた。
ボリュームで0~100.0ms、0.1msec単位の瞬断時間の調整が可能。
RSWを押すと1秒後に瞬時断線が1回だけ発生する。
MOS-FETリレーの仕様に合わせて、SW1でa接とb接の切り替えが出来るようにした。
使う際にはMOS-FETリレーの出力部分で電圧モニタして時間を調整する作業が必要だが、安定して断線の模擬信号が発生できるようになった。
IMG_5031


WS020016


CP1-2での電圧モニタ。
SW1-offでの動作。10msに調整してみた。
NewData2

SW1-onでの動作。同じく10ms。
NewData1


いつものバックグラウンドで割り込みタイマを走らせる手法だと、制御周期が1ms以下に出来なかったのでとりあえずベタで書いてみた。
実用上は問題なさそうではあるが、面白みの無い回路になってしまったので、後でタイマモジュール使ったプログラムに差し替えよう。
BreakingOfWireSimulater.c
/*
 * File:   BreakingOfWireSimulater.c
 * Author: http://kazuikazui.dreamlog.jp/
 * Device: PIC12F683
 * Compiler: XC8 Ver2.32
 * Created on 2021/07/12, 21:09
 */


// PIC12F683 Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON       // Brown Out Detect (BOR enabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

//****************** Global Variables *******************
#define _XTAL_FREQ 20000000      //20MHz External OSC

__bit M0;               //内部補助リレー
int Duty,Period;        //タイミングのパラメータ

/*** 関数プロトタイピング ***/
int ADConv10(unsigned char Ch); //10bitA/D変換(0?1023)

void main(void) {
    //OPTION REGISTER 設定、PIC12F683 Data Sheet による
    //OSCCON = 0b1110000;           // Internal Fosc=8MHz=125nsec
    ANSEL  = 0b0100001;             // アナログ入力 Fosc/32=1.6usec@20MHz,AN0使用
    CMCON0 = 0b00000111;            // コンパレータ無効化
    TRISIO = 0b001011 ;             // GP0,1,(3)入力、GP2出力,GP4,5 Clock
    WPU    = 0b001010;              // WakePullUpBIT GP1,(3) ON
    nGPPU  = 0b000000;              // GPIOプルアップ有効化

    /* Global Variables initialize */
    GPIO = 0b000000;            // GP2 default LOW
   
    while(1) {
        /* SW1=GP1,RSW=GP3,RL=GP2,VR1=AN0 */
        Period = ADConv10(0);
        //Period = 1;
        
        if (GP1==1){                //modeSW = off
            GP2 = 1;
        }
        else {
            GP2 = 0;
        }
        
        if (GP3 == 0){
            M0 = 1;
            Duty =0;
            __delay_ms(1000);
        }

        while (M0 == 1){
            if (Duty < Period){
                if (GP1==1){        //modeSW = off
                    GP2 = 0;
                }
                else {
                    GP2 = 1;
                }
                __delay_us(100);               
            }
            else {
                if (GP1==1){        //modeSW = off
                    GP2 = 1;
                }
                else {
                    GP2 = 0;
                }
                M0 = 0;
            }         
            Duty++;
        }

    }
}

/**************************************
*  AD入力サブ関数
*  ADConv10(unsigned char Ch) 10bit
* ADConv8(unsigned char Ch) 8bit
***************************************/

int ADConv10(unsigned char Ch){
    ADCON0 = 0b10000001 + (Ch << 2);  //右詰め,ref:Vdd,CH選択,ADON
    __delay_us(12);             //12μsecコンデンサチャージ待ち
    GO = 1;                     //AD変換開始
    while(GO);                  //変換終了待ち
    return(ADRESH * 256 + ADRESL);  //値を10bitで返す
    }