Jump to content

!Qwert

Members
  • Content Count

    10
  • Joined

  • Last visited


Reputation Activity

  1. Like
    !Qwert got a reaction from OzGrant in msp430 peripherals to tm4C123G peripherials   
    Okay, I found out that using pinMode, digitalWrite and digitalRead works and I can understand how my capacitive sensor is implemented. I got my sensor to get the number of cycles I am expecting since it is allowing the sensor to be discharged and charged at a rate where I can get better readings.
    Since the board is running at 80MHz, one cycle is 0.0125us so if I am not touching the pin, the value will be around 40 cycles with 4M ohm pulling it high. Then if I touch the sensor, the number jumps to ~200.
     
    I am still figuring out why the port manipulation does not work but the pinMode, digitalWrite and digitalRead works.
     
    Here is how I defined my readCapacitancePin() without port manipulation:
    uint32_t readCapacitivePin(int pinMeasure){ //First Discharge the pin before starting pinMode(pinMeasure,OUTPUT); digitalWrite(pinMeasure,LOW); delay(1); //Charging the pin to HIGH without internal pull up //have an external resistor to pull up the pin to +5V pinMode(pinMeasure,INPUT); int cycles = 2000; //The tiva board clk is at 80MHz, tested which large value would be enough for the pin to charge and discharge the sensor //External pull-up is around 4M Ohm to +5V for(int i = 0; i < cycles; i++){ if(digitalRead(pinMeasure) == HIGH){ cycles = i; break; } } //Discharge the pin for more readings in the future pinMode(pinMeasure,OUTPUT); digitalWrite(pinMeasure,LOW); pinMode(pinMeasure,INPUT); return cycles; } Is it when pin is defined to portDATARegister(digitalPinToPort(pinToMeasure)) that it cannot tell if this is referring as an input or output so that is why every time I touch the sensor the number of cycles always the fixed value I put in readCapacitancePin()?
×
×
  • Create New...