I am experiencing a very strange problem, and I wonder if anyone has a similar experience.
In a application I am using ADC input and port pin outputs on the same port (Port C on a MEGA328).
I have a boolean function, let us call it test, and a pin defined thus
Now if I set
the processor misbehaves, consistent with it resetting (I do not have watchdog or brownout detect) but I cannot say for sure that that is what is happening.
However, if I put
if Test then
MyOut := FALSE;
else
MyOut := TRUE;
endif;
everything behaves as it should.
Looking at the assembler, after optimisation timings should be about the same. The difference between these two pieces of code is that the one that does not work uses read-modify-write of the C port (IN and OUT), whereas the one that does work uses direct port pin manipulation (CBI and SBI). But I honestly don't see why that would make a difference unless ADC detection gets upset, and I don't see why it should.
There is nothing logically wrong with the code generated as far as I can see.
Has anyone experienced anything similar?
In a application I am using ADC input and port pin outputs on the same port (Port C on a MEGA328).
I have a boolean function, let us call it test, and a pin defined thus
Code
MyOut [@PortC, 1] : bit;
Now if I set
Code
MyOut := not Test;
the processor misbehaves, consistent with it resetting (I do not have watchdog or brownout detect) but I cannot say for sure that that is what is happening.
However, if I put
Code
if Test then
MyOut := FALSE;
else
MyOut := TRUE;
endif;
everything behaves as it should.
Looking at the assembler, after optimisation timings should be about the same. The difference between these two pieces of code is that the one that does not work uses read-modify-write of the C port (IN and OUT), whereas the one that does work uses direct port pin manipulation (CBI and SBI). But I honestly don't see why that would make a difference unless ADC detection gets upset, and I don't see why it should.
There is nothing logically wrong with the code generated as far as I can see.
Has anyone experienced anything similar?