Go Down

Topic: NilRTOS - A Fast Tiny Preemptive RTOS (Read 17 times) previous topic - next topic

pito

Another issue I've found - I have to use:
Code: [Select]
struct FifoItem_t {
  uint16_t usec;        // Low 16-bit of time in usec.
  uint16_t value;  // ADC value.
  uint8_t error;   // Overrun count since last point.
};

otherwise the adc value read is not correctly passed to p->value. It seems our compiler has got a problem with passing values to bitfields ..

fat16lib

#26
Jan 26, 2013, 03:56 am Last Edit: Jan 26, 2013, 04:55 am by fat16lib Reason: 1
I don't understand.  I store this counter in thread 1
Code: [Select]

 //  p->value = analogRead(0);
    p->value = nr;
    nr = nr < 1023 ? nr + 1: 0;

and the correct result is written to the SD.  The bit field works fine.  I ran it for many cycles of 0 - 1023.

Why can't I reproduce your results?

Edit: I now can show that only 8-bit of the ADC value get stored even though the counter works.

Edit: I got rid of the bit fields and now the ADC values in the file match a fixed voltage applied to pin A0.

pito

#27
Jan 26, 2013, 07:52 am Last Edit: Jan 26, 2013, 11:51 am by pito Reason: 1
.. you may see for example (when p->value is a bitfield):
Code: [Select]
p->value = 1023;      //this works
p->value = analogRead(0); //this does not work, only 8bits passed
p->value = temp;      //this does not work, only 8bits passed

PS: now it seems to me all above issues I saw here were caused by the bitfield issue..

fat16lib

pito,

Do you still need the call to analogReference() after changing FifoItem_t?

I really would like to get to the bottom of why you need the analogReference() call.  All it does is set the global analog_reference.  My experience has been that things like this are a symptom of a nasty bug.

Code: [Select]

uint8_t analog_reference = DEFAULT;

void analogReference(uint8_t mode)
{
// can't actually set the register here because the default setting
// will connect AVCC and the AREF pin, which would cause a short if
// there's something connected to AREF.
analog_reference = mode;
}



I have more cases where bit fields work and a lot where they don't.  Clearly they are to be avoided.

pito

I do not need analogreference when not using bitfields.

Go Up