Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on 3217 using PC0 .. PC4 #2

Open
shpi opened this issue Mar 21, 2024 · 13 comments
Open

on 3217 using PC0 .. PC4 #2

shpi opened this issue Mar 21, 2024 · 13 comments

Comments

@shpi
Copy link

shpi commented Mar 21, 2024

Tried the library on a 3217 and just get 0x00 reading (but no pointer issue) ?

@shpi
Copy link
Author

shpi commented Mar 21, 2024

Ok it works, but only with Arduino.h

@MX682X
Copy link
Owner

MX682X commented Mar 21, 2024

I was hoping to get it to work without the Arduino.h.
Can you post your code? And in which file was the Arduino.h missing?

@shpi
Copy link
Author

shpi commented Mar 21, 2024

I want to run your library complete without the Arduino crap, but it doesnt compile. Of course unmodified it works. But just with "#include <avr/interrupt.h>" it doesnt compile.

I have 4 nodes with one Y and tried to code a slider. But it seems the value, regardless it can securely detect a touch, jump around after touches and are not stabilized in 512 range?

@MX682X
Copy link
Owner

MX682X commented Mar 21, 2024

Can you copy the error message on a failed compilation? In order to make it work, I need to know what is throwing the errors.

I don't think I will be able to help with the sliders though, as I don't have a way to test it (no slider PCB).

I can tell you however, that using self-capacitance on a slider is a bad idea, there will be too much noise. An X Line is highly recommended (See Mutual Example). If you cannot spare another Pin, consider driving the other nodes as shields (see corresponding Example).

@shpi
Copy link
Author

shpi commented Mar 21, 2024

I use mutual capacitance :)

ptc_add_mutualcap_node(&nodes[0], PIN_TO_PTC(PIN_PC1), PIN_TO_PTC(PIN_PC0));
ptc_add_mutualcap_node(&nodes[1], PIN_TO_PTC(PIN_PC2), PIN_TO_PTC(PIN_PC0));
ptc_add_mutualcap_node(&nodes[2], PIN_TO_PTC(PIN_PC3), PIN_TO_PTC(PIN_PC0));
ptc_add_mutualcap_node(&nodes[3], PIN_TO_PTC(PIN_PC4), PIN_TO_PTC(PIN_PC0));

But the calibration varies between nodes? I cannot get one node to 512, it idles at 590. And if i touch them they change their value only +- 20 ?

@MX682X
Copy link
Owner

MX682X commented Mar 21, 2024

How do you read out the values of the nodes?
The variation of the calibration is absolutely normal. The calibration value is the reference capacitance(!) used internally for normal operation. as the pins are bonded differently (see picture as an example below) and the layout on the silicon is different too, so they will have different stray capacitances.

There are two calibration options by the way: 1 by capacitance. 2. by a reference. the function "ptc_get_node_delta(cap_sensor_t* node)" is the one you need to get the touch value minus reference.

image009-2648489759

@shpi
Copy link
Author

shpi commented Mar 21, 2024

Ok thanks, i just do this now in the TWI ISR:

switch (commandbyte) {

            case 0x00: TWI0.SDATA = buffer_address; break;
            case 0x01: TWI0.SDATA = sensorValue; break;
            case 0x02: TWI0.SDATA = lastButtonState;  break;
            case 0x03: TWI0.SDATA = buffer_address == 1 ? ((nodes[0].sensorData - nodes[0].reference) >> 8 ) & 0xFF : (nodes[0].sensorData - nodes[0].reference) & 0xFF; break;
            case 0x04: TWI0.SDATA = buffer_address == 1 ? ((nodes[1].sensorData - nodes[1].reference) >> 8 ) & 0xFF : (nodes[1].sensorData - nodes[1].reference) & 0xFF; break;
            case 0x05: TWI0.SDATA = buffer_address == 1 ? ((nodes[2].sensorData - nodes[2].reference) >> 8 ) & 0xFF : (nodes[2].sensorData - nodes[2].reference) & 0xFF; break;
            case 0x06: TWI0.SDATA = buffer_address == 1 ? ((nodes[3].sensorData - nodes[3].reference) >> 8 ) & 0xFF : (nodes[3].sensorData - nodes[3].reference) & 0xFF; break;
            case 0x07: TWI0.SDATA = error; break;
            default: TWI0.SDATA = 0xAA;  // Unknown command
        } 
        buffer_address++;

The result is like this:

outer:0 center:590 right:0 left:0

So it seems one has no reference?

@MX682X
Copy link
Owner

MX682X commented Mar 21, 2024

This looks like a calibration error.
You can check by looking at node[x].state.error . It is set true if calibration failed.
or node[x].hw_compCaps / ptc_get_node_cc_fempto(cap_sensor_t* node) (the value must not be too big)

or check for this event callbacks

ptc_event_callback(PTC_CB_EVENT_ERR_CALIB_LOW, node);
ptc_event_callback(PTC_CB_EVENT_ERR_CALIB_HIGH, node);
ptc_event_callback(PTC_CB_EVENT_ERR_CALIB_TO, node);

@shpi
Copy link
Author

shpi commented Mar 21, 2024

Ok it tells me "Calib error, Cc too low." :( The slider is indeed quiet small

@MX682X
Copy link
Owner

MX682X commented Mar 22, 2024

consider using the shield option

ptc_add_selfcap_node(&nodes[0], PIN_TO_PTC(PIN_PC1), 
    PIN_TO_PTC(PIN_PC0) | PIN_TO_PTC(PIN_PC2) | PIN_TO_PTC(PIN_PC3)  | PIN_TO_PTC(PIN_PC4) ); 
ptc_add_selfcap_node(&nodes[0], PIN_TO_PTC(PIN_PC2), 
    PIN_TO_PTC(PIN_PC0) | PIN_TO_PTC(PIN_PC1) | PIN_TO_PTC(PIN_PC3)  | PIN_TO_PTC(PIN_PC4) ); 

etc...

@shpi
Copy link
Author

shpi commented Mar 22, 2024

Well we need to use mutual cap. Btw we redesigned the slider and give it a next try. Ok, adjusted. Can u verify that your analog read of pins work while ptc is suspended? Made it work without Arduino.h, we just needed to make a dummy function for the arg function.

@MX682X
Copy link
Owner

MX682X commented Mar 25, 2024

Alright, I've pushed an update to make it compile in Microchip studio at least. The Dummy functions might require Link Time Optimizations enabled (-flto).
The PTC module does not do the conversion, the ADC does. Generally, I'd recommend to use the second ADC if possible. (The DA series has a second ADC by the way, but it is reserved for the PTC)
Anyway - upon suspending the library, the ADC will not be accessed by the library, so you are free to use it for yourself,
The PTC library will reconfigure the ADC for itself upon starting a conversion cycle (after resuming)
Be careful about the interrupts though, as the PTC library relies on the Window Compare and Result Ready interrupts. If you need those, you'll need to rewrite the ISRs aswell, which I don't recommend.
On a side Note: the ptc_init_ADC0() function initializes the ADC in the same way the megaTinyCore does. You might require a custom init.

@shpi
Copy link
Author

shpi commented Mar 25, 2024

Well couldnt get it to work with ADC0, using ADC1 now on 3217. That works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants