Author Topic: Trying to duplicate/understand this switch circuit(SOLVED)  (Read 16682 times)

0 Members and 1 Guest are viewing this topic.

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Trying to duplicate/understand this switch circuit(SOLVED)
« on: January 09, 2024, 09:22:16 pm »
I have a two identical BMS boards that have an override switch circuit per schematic in the first attachment.  The only difference is the microcontroller on the functioning BMS is factory programmed and the other board has a new microcontroller that I'm trying to program to duplicate the factory original. I do not understand how the outputs on both PB1 and PC5 are configured from the factory nor to I get the why part of using the two signals together to create the combined stepped PWM? output in the second attachment.  I removed R97 and scoped the output of PB1 and PB5 (third and fourth attachments respectively) I could only get the output of PB1 to stabilize with AC coupling.  PC5 however would not stabilize under any setting I could think but at least the image capture shows the it's form.

On the BMS board with the new microcontroller the I have set both pins to output high which is how I think they should be configured.

Any direction in furthering my understanding of the techniques used in this switch circuit would be appreciated.


Jerry
« Last Edit: January 12, 2024, 06:18:48 pm by jerryk »
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 3199
  • Country: ca
Re: Trying to duplicate/understand this switch circuit
« Reply #1 on: January 09, 2024, 10:47:38 pm »
What is Vcc?
Bill
----
 

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Re: Trying to duplicate/understand this switch circuit
« Reply #2 on: January 09, 2024, 10:48:15 pm »
vcc = 3.3V
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 3199
  • Country: ca
Re: Trying to duplicate/understand this switch circuit
« Reply #3 on: January 09, 2024, 10:57:25 pm »
Then part of what you are seeing in that bottom trace is that LED acting like a capacitor.  It'd be great if could arrange the 2 bottom traces together at the same time with the resistor in on 2 different channels so we could see the timing of when each pin changes state, and I would probe at the pins.

This is the working unit, right?
« Last Edit: January 09, 2024, 11:00:09 pm by BillyO »
Bill
----
 

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Re: Trying to duplicate/understand this switch circuit
« Reply #4 on: January 09, 2024, 11:03:55 pm »
I can try the second two together but not all three since I would need to reinstall R97 which results in the first scope capture in my original post.  I was curious if it's possible that they are toggling the data direction register between input and output?

Jerry
 

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Re: Trying to duplicate/understand this switch circuit
« Reply #5 on: January 09, 2024, 11:05:32 pm »
Correct.  These are from the working unit. 

Jerry
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 3199
  • Country: ca
Re: Trying to duplicate/understand this switch circuit
« Reply #6 on: January 09, 2024, 11:07:44 pm »
I can try the second two together but not all three since I would need to reinstall R97 which results in the first scope capture in my original post.  I was curious if it's possible that they are toggling the data direction register between input and output?

Jerry

It might be, but we'd need to see those two traces with the resistor in.
Bill
----
 
The following users thanked this post: jerryk

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Re: Trying to duplicate/understand this switch circuit
« Reply #7 on: January 09, 2024, 11:30:54 pm »
Thanks.  It will be a moment, possibly tomorrow morning as I have to step away from the office.

Jerry
 

Online WattsThat

  • Frequent Contributor
  • **
  • Posts: 916
  • Country: us
Re: Trying to duplicate/understand this switch circuit
« Reply #8 on: January 10, 2024, 03:03:26 am »
The only way the mirco can tell the bypass switch is closed is to have PC5 become an input. That’s what exactly is shown in the fourth trace, that pulse with the rc decay is the pin changing from a high output to an input with its pull up enabled. The first trace shows the same thing and the differences in amplitude is change in PC5 from output to input.

If you use two channels and observe both port pins at the same time, it will make sense, you cannot see them independently with just one input channel used.
 
The following users thanked this post: jerryk

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Re: Trying to duplicate/understand this switch circuit
« Reply #9 on: January 10, 2024, 05:08:07 pm »
First attachment is the circuit with trace locations and I have left R97 in so I can activate the switch. Next are two three channel views.   The first view depicts switch S3 open and the second view S3 is closed.

I'm getting a better understanding of this but still can't see how I can detect the switch state of S3. 

Edit - Now I think I see that I have to read the trace at PC5 1ms after the output is changed to input??

Jerry
« Last Edit: January 10, 2024, 05:27:16 pm by jerryk »
 

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Re: Trying to duplicate/understand this switch circuit
« Reply #10 on: January 11, 2024, 07:26:54 pm »
Thanks to the help provided I have been able to duplicate the logic to at least impersonate the factory board output with the switch open.  When I close the switch there is some variation in the from the factory output.  Traces from my coding of the test board are below.
 
The code I came up to accomplish this:
Code: [Select]
void init_timer0()
{
    _mf0e = 0x01; // enable Multi-function 0 interrupt
    _stm0ae = 0x01; // enable STM0A interrupt
    _stm0c0 = 0x30; // set clk = f(sys)/64
    _stm0c1 = 0xc1; // set TIMER MODE AND CLEAR COUNT
    _stm0af = 0x00; // clear STM0A interrupt flag
    _mf0f = 0x00; // clear Multi-function 0 flag
    _stm0al = 0x7d; // Matching value
    _stm0ah = 0x00;
    _st0on = 1; // start counting
}



void __attribute((interrupt(0x14))) ISR_TMR0 (void)
{
    //1ms pulse
    count ++;
    subcount++;
   
    _stm0af = 0x00; // clear T2A interrupt flag
    _stm0al = 0x7d; // Matching value = 125 (8MHz/64/1000)
    _stm0ah = 0x00;


    // Logic for override switch detect

    if(subcount == 1)
    {
        _pb1 = 1;  // Pin PB1
        _pcc5 = 0; // sets _pc5 to output
        _pc5 = 0; // Pin PC5
        _pcpu5 = 0; // disable pullup on pin _pc5
    }


    if(subcount == 4)
    {
        _pc5 = 1;
        _pcc5 = 1;                 
    }

    if(subcount == 5)
    {
        _pb1 =0;
        _pc5 = 0;   
       
    }

    if(subcount == 6)
    {
    _pcpu5 = 1;
    _pc5 = 1;     
    }

    if(subcount >= 6)
    {   
        subcount = 0;
    }
   
    if(count >= 63536)
    {   
        count = 0;
    }
}

So it seems like the goal of duplicating at least part of the logic to create the original signals has happened but I still don't understand how to code the detection logic required for a switch press detection.  I'm not so much asking for the coding part but just need some direction on what part of the traces show a low signal after the switch press?

Also, if I'm I should have posted this in the microcontroller forum let me know. 

Jerry
 

Offline jerrykTopic starter

  • Frequent Contributor
  • **
  • Posts: 254
  • Country: us
Re: Trying to duplicate/understand this switch circuit (SOLVED)
« Reply #11 on: January 12, 2024, 06:16:26 pm »
The only way the mirco can tell the bypass switch is closed is to have PC5 become an input. That’s what exactly is shown in the fourth trace, that pulse with the rc decay is the pin changing from a high output to an input with its pull up enabled. The first trace shows the same thing and the differences in amplitude is change in PC5 from output to input.

If you use two channels and observe both port pins at the same time, it will make sense, you cannot see them independently with just one input channel used.

I did finally manage to emulate the factory original circuit exactly.  I also had also set _pb1 to input with pull up enabled at what would be the 4th ms place (upper step of _pb1 trace) if you look at the whole period as 6ms.  Right or wrong it works and all I have to is poll pin _pb1 for a low condition.

FWIW here is the change in the interrupt that made it work:
Code: [Select]
void __attribute((interrupt(0x14))) ISR_TMR0 (void)
{
    //1ms pulse
    count ++;
    subcount++;
   
    _stm0af = 0x00; // clear T2A interrupt flag
    _stm0al = 0x7d; // Matching value = 125 (8MHz/64/1000)
    _stm0ah = 0x00;


    // Logic for override switch detect

    if(subcount == 1)
    {
        _pb1 = 1;  // Pin PB1
        _pcc5 = 0; // sets _pc5 to output
        _pc5 = 0; // Pin PC5
        _pcpu5 = 0; // disable pullup on pin _pc5
    }

    if(subcount == 4)
    {
        _pbc1 = 1;
        _pc5 = 1;
        _pcc5 = 1;                     
    }

    if(subcount == 5) // subcount 5 is the 4th ms in the 6ms period
    {
        _pbc1 = 0; // THE FIX - changed PB1 to input
        _pbpu1 = 1;// THE FIX - enabled PB1 pullup
        _pb1 =0;
        _pc5 = 0;
    }

    if(subcount == 6)
    {
    _pcpu5 = 1;   
    }

    if(subcount >= 6)
    {   
        subcount = 0;
    }

Your post helped get me over the hump and now my override switch works.

Jerry
« Last Edit: January 12, 2024, 06:28:41 pm by jerryk »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->