Problem with simulating arduino in proteus8

on my way for making this project I am trying to simulate and test my code (the part on hardware) in proteu8 professional.

in the the last post I was told that using Serial.write() in the ISR part would be a good idea but I didn't know what should I put inside the Serial.write() command. it came to my mind that I can put ADCH there but I kept getting garbage value in the visual terminal in that case so I put the code this way:

void setup()
{
   Serial.begin(115200);
   ADCSRA = 0;             // clear ADCSRA register
   ADCSRB = 0;             // clear ADCSRB register
   ADMUX |= (0 & 0x07);    // set A0 analog input pin
   ADMUX |= (1 << REFS0) | (1 << REFS1);  // set reference voltage
   ADMUX |= (1 << ADLAR);  // left align ADC value to 8 bits from ADCH register
   // sampling rate is [ADC clock] / [prescaler] / [conversion clock cycles]
  // for Arduino Uno ADC clock is 16 MHz and a conversion takes 13 clock cycles
  //ADCSRA |= (1 << ADPS2) | (1 << ADPS0);    // 32 prescaler for 38.5 KHz
  ADCSRA |= (1 << ADPS2);                     // 16 prescaler for 76.9 KHz
  //ADCSRA |= (1 << ADPS1) | (1 << ADPS0);    // 8 prescaler for 153.8 KHz

  ADCSRA |= (1 << ADATE); // enable auto trigger
  ADCSRA |= (1 << ADIE);  // enable interrupts when measurement complete
  ADCSRA |= (1 << ADEN);  // enable ADC
  ADCSRA |= (1 << ADSC);  // start ADC measurements
}

ISR(ADC_vect)
{
  byte x = ADCH;  // read 8 bit value from ADC
}
  
void loop()
{
  Serial.println(ADCH);
}

and in the proteus8 I got all zeros in serial monitor.

however in 1Mb/s baud I got some strange values but they were nonsense too I guess.

so my questions are:
1-how can I use Serial.write() in the ISR?

2-how should I change both my code or my simulation to get sure that at least I'm okay on the hardware part?

P.S: I have just done a hardware test. with my arduino, a 5v adapter and a voltage divider (divide by two). and here are my results so far:


Have I written the factor right? (a=5/255) or should it be (5/1023)?
and does anyone have any idea why the voltage I'm getting is a bit low?

Serial.write(ADCH); ? But zero will more that likely not show in the Serial Monitor (or whatever it is in Proteus). You're better of trying to use Serial.print(ADCH); as you did in loop.

Just use analogRead() to test the hardware instead of register manipulation.

Note:
Not many of us use Proteus; most prefer to work on the real hardware.

Honestly I find proteus 8 bad. The software seems buggy. Hangs quite often. I think proteus 7 is better.

So I guess its better I test it on the hardware too.

the reason I used register manipulation was that for my purpose analogRead() is a little slow and using this method I'll probably get better results.

Really? :astonished:

yup! you can find complete description in link bellow.

I just did the actual hardware test. would be happy to know your opinion now.

Do not edit posts after you got replies. You should have added it as a new reply.

Which board?
Have you tested with GND, 5V (if your board is a 5V board) and 3.3V that are provided by the board and without voltage divider.

Next add the voltage divider and test again with boards voltages. I don't know which voltage divider you used so cannot say if your result are OK or not.

First display the readings not voltages.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.