Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

code error

Status
Not open for further replies.

Adam2014

Member
hi
i upload a frequency meter code & schematic
but there is an error in measurement ...
for example if i apply an square wave with 5000Hz ,,, LCD display it about 40khz !!!
what is the error ?
 

Attachments

  • fff.txt
    2.8 KB · Views: 459
  • fff.PNG
    fff.PNG
    47.8 KB · Views: 470
when i rebuild the the code and restart compile
i see this message "Linker error: the program has no 'main' function"
and proteus can't work with new edit !!!
 
Hi
thanks Ian Rogers
i solve the problem :)
i have a questions !
Q1) i need to build a bottom to make a force calibration when i press it .
how i can do it in my code ?
the main idea i want to do is "re execute the calibration subroutine" when there is an interrupt from calibration bottom


Q2) how i can monitor the pin state depending on the external switch state ..
i mean how i can know the pin is High/Low using atmega16 & c code
 
Last edited:
I normally use a button to give a low to the micro pin ( pulled up internally ) then poll the pin for changes..
If you write a small function that can be called from your super loop, that will analyze a range of pins to report a button press. Then you can act on this report...

ie something like this...
C:
int keyhit()
   {
   if(!PIN1) return 1;
   if(!PIN2) return 2;
   return 0;
   }
You will need a debounce.... I use a 200mS delay to debounce..
C:
int keyhit()
   {
   int key=0;
   if(!PIN1) key += 1;
   if(!PIN2) key += 2;
   if(key) delayMs(200);
   return key
   }
 
thanks :)
i define a bottom ca=PORTD.0; // do a forced calibration
how i can make a forced calibration at any time if (ca=High) ,,, even if the Micro controller do another task
 
When you say "bottom" I was assuming "Button"

If you poll a button each cycle of a super loop its usually fast enough not to miss a press.. However... If you need to you can implement an interrupt to take care of the button press..... If you have capture compare CCP module.. you can detect a single button press and have automatic noise rejection as you can program the module to ensure the key is pressed for a minimum time before registering it..
 
Hi
I use code vision avr to program my micro controller atmega16a
when i run the program it still work with the internal oscillation 1MHZ even if i set timer with external clock 16Mhz
" AVR Core Clock frequency: 16.000000 MHz "
so that the value showed is multiple by 16
what the solution to have the real value ?
i try CKSEL=0xf; but with that instruction there is a syntax error
 
If I remeber correctly the clock settings for the ATmega series are done in fuses, not in code. You need to set this in your programming tool.
 
HI
what the problems with my code to display capacitor value ?
because it display the value on all 16 digits LCD Screen ???

//-----------disply Capacitor function --------------------//
float dis_capacitor(unsigned long int c)

{

float cf;
lcd_clear();
lcd_putsf("Capacitor=");
lcd_gotoxy(0,1);
if(c>=0.000001)
{
cf=(float)c*1000000;
ftoa(cf,3, buffer);
lcd_puts(buffer);
lcd_putsf("uF");
}
else if (c>=0.000000001)
{
cxxf=(float)c*1000000000;
ftoa(cf,3, buffer);
lcd_puts(buffer);
lcd_putsf("nF");
}
else
{
ltoa(cf, buffer);
lcd_puts(buffer);
lcd_putsf("pF");
}
delay_ms(3000);
return 0;
lcd_clear();
lcd_gotoxy(0,0);
}
 
If c is an int, then it will be allways true, unless c is zero. Not sure about the rest.
 
HI
when i run the program it take long time to execute
the attached image show the MCU set ,,, what is the problem?
 

Attachments

  • crys.PNG
    crys.PNG
    45.3 KB · Views: 401
When you "run" your simulation... go into debug mode and see what's causing the slow down....

Have you managed a clean compile??? Otherwise the hex file is never updated...

Step through the program and keep an eye on the "warnings" in the status bar...
 
Hi
when i run LC meter the LCD display an initial value with out any DUT (device under test)
How i can edit my code to subtract it from the reading thus LCD display an initial value 0.000 ?
 
You need to "Map" your input to your LCD output.... If you google you will find examples of mapping.

Mapping...
Display_Value = (((Read_Value - Read_Value_zero_figure) * Displayed_Value_span_figure ) / Read_Value_Span_figure) - Display_Value_Zero_figure....
 
thanks Ian Rogers
I'm working now with ADC ...
i want to convert voltage from analog signal to digital and then store it in parameter Vo
where the MCU store its digital value that equal Vo
 
WHY ARE YOU SHOUTING!!!

I'm not sure what you mean... If you create a variable to hold the result... You need to fetch the value stored in the result register... I can't remember it's name on the AVR chips... The "Map" function should resemble my example above..
 
SHOUTING !!!
in my circuit design x=f(V0) ,,, so i want to measure voltage using ADC and then calculate x
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top