I haven't done the code for these yet, so can't really show them. It's a task I need to prove that I can do, but i'm not sure and understand how to do it.That doesn't answer my question.
Where is the DAC?
Where is the switch?
I haven't done the code for these yet, so can't really show them. It's a task I need to prove that I can do, but i'm not sure and understand how to do it.That doesn't answer my question.
Where is the DAC?
Where is the switch?
I am not asking you to show code. What I am asking for is the big picture.I haven't done the code for these yet, so can't really show them. It's a task I need to prove that I can do, but i'm not sure and understand how to do it.
I see, sorry. My bad. Does this help? https://imgur.com/gallery/hbMcLgYI am not asking you to show code. What I am asking for is the big picture.
Draw a picture of what is connected to what, physically.
Without seeing the big picture we are going to be playing the game of 101 Q & A.
char number[7];
void realVoltage_usart ()
{
number[0] = '0';
number[1] = '.';
number[2] = '0';
number[3] = '0';
number[4] = '0';
number[5] = 'v';
number[6] = ' ';
unsigned int ActVolt;
ActVolt = ADC_convert()*1000;
while (ActVolt > 1000)
{
ActVolt -= 1000;
number[0]++;
}
send_usart(number[0]);
send_usart(number[1]);
while (ActVolt > 100)
{
ActVolt -= 100;
number[2]++;
}
send_usart(number[2]);
while (ActVolt > 10)
{
ActVolt -= 10;
number[3]++;
}
send_usart(number[3]);
while (ActVolt > 1)
{
ActVolt -= 1;
number[4]++;
}
send_usart(number[4]);
send_usart(number[5]);
send_usart(number[6]);
}
float ADC_convert(void)
{
unsigned short ADC_DATA;
float Voltage;
ADC_DATA=read_adc();
Voltage= (ADC_DATA*(3.3/4096));
return Voltage;
}
char mystr[128] = { 0 };
float myfloat = 123.456;
sprintf(mystr, "%f", myfloat);
printf("Number: %s\n", mystr); // send to uart instead of printf here
I'll give it a go. Thank you! Mind explaining what line 2 of the code means?Use something like sprintf() to convert your float to a string, then send the string to the uart. For example:
sprintf(mystr, "%f", myfloat);Code:char mystr[128] = { 0 }; [code]float myfloat = 123.456;
printf("Number: %s\n", mystr); // send to uart instead of printf here
[/code]
If your ADC values are jumping all over, put a scope on your power leads and check if it's clean. If there is ripple or noise on your power, that can affect the ADC readings. Additionally you can take multiple samples. Just put a little loop to read your ADC a few times with a pause in-between, add them up and divide by the number of readings. That will give you an average. Play with the number of readings and delay it to suit your needs. Also check the spec for your ADC, some are configurable to oversample automatically if you enable the option.
To get it to type overitself on the same line, you're going to have to use a combination of things. Your terminal will have to be set to NOT automatically line-feed, then send the \r character to rewind the carriage to the start of the line (terminology from the old typewriter days). Sending \n will give you a new line.
float myfloat = 123.456;
void send_usart(unsigned char d)
{
while(!(USART_MODULE->SR&USART_SR_TC)); //wait for transmission complete
USART_MODULE->DR=d; //write byte to usart data register
}
int iNumReadings = 5;
int iDelayBetweenReadingsMicroSec = 10;
float avgReading = 0.0;
for(int i = iNumReadings; i > 0; i--)
{
avgReading += ADC_convert();
delayMicroseconds(iDelayBetweenReadingsMicroSec );
}
avgReading /= iNumReadings;
void CustomChar (float q) //analogue signal. (q is adcvalue)
{
float divider = 255; //3.3V represented by 16 character spaces (4096/16) (12bits)
int sum = q/divider;
cmdLCD(LCD_LINE2); //setting cursor location
for(int i = 0; i< 16 ; i++) //to get complete progress bar, have to account for all 16 memory locations, for= loops again.
if(i<=sum)
{
putLCD(0xFF); //transfer character code to memory and increments the cursor by 1
}
else putLCD(' '); //otherwise, put space.
}
void realVoltage_usart()
{
char mystr[128] = { 0 };
float Voltage = 123.456;
sprintf(mystr, "Volts=%.3f\n", Voltage);
send_usart((unsigned char) mystr); // send to uart instead of printf here}
}
Yes, as using my old code works :Did you initialize the USART correctly?
char number[7];
void realVoltage_usart ()
{
number[0] = '0';
number[1] = '.';
number[2] = '0';
number[3] = '0';
number[4] = '0';
number[5] = 'v';
number[6] = ' ';
unsigned int ActVolt;
ActVolt = ADC_convert()*1000;
while (ActVolt > 1000)
{
ActVolt -= 1000;
number[0]++;
}
send_usart(number[0]);
send_usart(number[1]);
while (ActVolt > 100)
{
ActVolt -= 100;
number[2]++;
}
send_usart(number[2]);
while (ActVolt > 10)
{
ActVolt -= 10;
number[3]++;
}
send_usart(number[3]);
while (ActVolt > 1)
{
ActVolt -= 1;
number[4]++;
}
send_usart(number[4]);
send_usart(number[5]);
send_usart(number[6]);
}
void myfunc(float voltage)
{
static bool init = false;
static float useval = 0.0;
const float gain = 0.5; // adjust this as necessary
if (!init) {
init = true;
useval = voltage;
} else {
useval = useval*gain + voltage*(1-gain);
}
// print useval as desired
}
by Aaron Carman
by Jeff Child
by Jake Hertz