Member | Action | Date |
---|---|---|
![]() |
Replied
to
Write an array of structures in flash
Im using external VREF. VREF = 2V. input to ADC is given directly by trimpot which vary from 0V to 2V. is there any problem in hardware or in initialization of ADC or any noise??? #include<c8051f410.h> #include "stdio.h" #include<math.h> #define SYSCLK 12250000 // //sfr16 TMR2RL = 0xCA; // Timer2 reload value //sfr16 TMR2 = 0xCC; // Timer2 counter sfr16 adc0 = 0xBD; void oscillator_init(void); void timer2_init(void); void delay(void); void lcmnd(unsigned int value); void ldata(unsigned int value); void lcd_init(void); void adc_init(void); sbit rs=P1^3; sbit en=P1^4; sbit rw=P1^5; unsigned int temp; int i; void delay() { unsigned int j; for(j=0;j<50000;j++); } void cmnd(unsigned int value) { P2=value; rs=0; rw=0; en=1; delay(); en=0; } void ldata(unsigned int value) { P2=value; rs=1; en=1; rw=0; en=1; delay(); en=0; } void lcd_init() { cmnd(0x38); cmnd(0x0C); cmnd(0x01); cmnd(0x80); } void oscillator_init() { OSCICN = 0x86; //sys clk divided by 2 CLKSEL = 0X00; XBR0 = 0x00; //Enable crossbar and weak pullups XBR1 = 0x40; PCA0MD &= ~0x40; P1MDIN &= 0x7F; //0111 1011 P1.7, P1.2 P1SKIP |= 0x80; //1000 0100 } void main(void) { oscillator_init(); lcd_init(); adc_init(); EA=1; timer2_init(); while(1) { cmnd(0x80); cmnd(0x0C); ldata((temp/1000)+48); // display the result on LCD ldata(((temp%1000)/100)+48); ldata(((temp%100)/10)+48); ldata(((temp%10))+48); } } void adc_read() interrupt 5 { TF2H = 0; //AD0BUSY=1; //start conv. // //while (AD0INT == 0); //conv. in progress if(AD0INT == 1) //conv finished { ADC0H &= 0x0F; temp = ADC0H; //adc high byte temp<<=8; temp|=ADC0L; AD0INT = 0; } } void timer2_init(void) { TMR2CN = 0x00; // Stop Timer2; Clear TF2; // use SYSCLK as timebase, 16-bit // auto-reload CKCON |= 0x10; // Select SYSCLK for timer 2 source TMR2RL = 65535 - (SYSCLK / 10000); // Init reload value for 10 us TMR2 = 0xffff; // Set to reload immediately ET2 = 1; // Enable Timer2 interrupts TR2 = 1; // Start Timer2 } /* void display() interrupt 10 { cmnd(0x80); cmnd(0x0C); ldata((temp/1000)+48); // display the result on LCD ldata(((temp%1000)/100)+48); ldata(((temp%100)/10)+48); ldata(((temp%10))+48); } */ void adc_init (void) { ADC0CN = 0x03; // ADC0 disabled, burst-mode disabled, // conversion triggered on TMR2 overflow ADC0TK = 0x08; // Pre-tracking mode enabled, keep // default timing settings REF0CN = 0x02; // external VREF on VREF pin, // Bias Generator enabled ADC0MX = 0x0f; // ADC0 positive input = P1.7 ADC0CF = 0x00; // Repeat count = 1 ADC0CF |= ((SYSCLK/3000000)-1)<<3; // Set SAR clock to 3MHz //EIE1 |= 0x08; // Enable ADC0 EOC interrupt AD0EN = 1; // Enable ADC0 }
|
Oct 28 2017, 12:53 PM |
![]() |
Replied
to
Write an array of structures in flash
my readings are when it have to be 0000, it is 0391 when it have to be 1269, it is 1824 when it have to be 1719, it is 2130 when it have to be 2600, it is 3232
and so on..
is there any problem in programming adc or is it because of noise.. ???
I checked 0v. it is OK..
|
Oct 28 2017, 12:53 PM |
![]() |
Replied
to
Write an array of structures in flash
Hello expertrs, im working on c8051f410. adc is working properly. It is showing count 0391 instead of 0000. I think there is issue of noise. can anyone tell how this noise can be removed. Is it removed by hardware or software.
i am using trimpot to vary the input volt to adc. many thanks. |
Oct 28 2017, 12:53 PM |
![]() |
Posted
Write an array of structures in flash on
Forum
Hello! Arose the need sometimes to read and write arrays of structures of the flash memory of the microcontroller. The dataset looks like this:
struct event { unsigned char state; unsigned char vector; unsigned char codename; unsigned char start_date_day; unsigned char start_date_month; unsigned char start_date_year; unsigned char start_weekday; unsigned char start_hour; unsigned char start_minute; unsigned char stop_hour; unsigned char stop_minute; double fade; double delay_multipiller; }; xdata struct event calendar[25]; Typically, the entire array is stored in RAM, and all internal communications are made only in RAM. However, when you add a new calendar event, I need to copy all added events in flash, in case of power failure the microcontroller when resuming restored the calendar back into RAM.
As far as I understand, my C8051F320 supports recording in flash with 512 byte sectors. My array just put in 1 this sector. On the website I found some libraries "AN201SW Writing to flash from firmware", but still do not quite understand how they work (there are examples write 1 byte, but how to write complex structure is not clear). In addition, I did not understand how to explain to the compiler (Simplicity studio) that a certain segment of the flash will not be able to write code is my main program will take almost 15 KB of memory available 16 .
Please, could you explain to me how to implement my task.
|
Oct 28 2017, 12:53 PM |
![]() |
Replied
to
c8051f410 adc is not working properly
yes i start every line of code with first coloumn. does it make any difference??? |
Oct 28 2017, 12:50 PM |
![]() |
Replied
to
c8051f410 adc is not working properly
im starting the programs with includes. but not mentioned it here. sysclk is 24.5 Mhz. Timer is for 10 us |
Oct 28 2017, 12:50 PM |
![]() |
Replied
to
c8051f410 adc is not working properly
when i use the following code i get 0000 at 0V but for 0.04V im getting 0003. but 0002 is not obtained. next im getting 0007, it is skipping the values in between. after 0007, it jumps to 0015, then 0031, then 0063, then 0127, then 0255, 0511,1023,2048. after 2048 it is continuously increasing... Vref=2v, i have changed sysclk and SARCLK.. what else modifications are required??? #define SYSCLK 24500000 void timer2_init(void) { TMR2CN = 0x00; // Stop Timer2; Clear TF2; // use SYSCLK as timebase, 16-bit // auto-reload CKCON |= 0x10; // Select SYSCLK for timer 2 source TMR2RL = - (SYSCLK); // Init reload value for 10 us //TMR2RL = 0xCA; TMR2 = 0xffff; // Set to reload immediately ET2 = 1; // Enable Timer2 interrupts // Start Timer2 } void oscillator_init() { OSCICN = 0x87; //sys clk divided by 1 } void adc_init (void) { ADC0CN = 0x03; // ADC0 disabled, burst-mode disabled, // conversion triggered on TMR2 overflow ADC0TK = 0x08; // Pre-tracking mode enabled, keep // default timing settings REF0CN = 0x02; // external VREF on VREF pin, // Bias Generator enabled ADC0MX = 0x0F; // ADC0 positive input = P1.7 ADC0CF = 0x00; // Repeat count = 1 ADC0CF |= ((SYSCLK/3000000)-1)<<3; // Set SAR clock to 3MHz //EIE1 |= 0x08; // Enable ADC0 EOC interrupt AD0EN = 1; // Enable ADC0 } void adc_read() interrupt 5 { TF2H=0; //while (AD0INT == 0); //conv. in progress if(AD0INT == 1) //conv finished { // AD0INT=0; // clear ADC conversion complete accumulator+=adc0; i++; if(i==16) { i=0; accumulator=accumulator/16; display(); accumulator=0; } } } void main(void) { oscillator_init(); lcd_init(); adc_init(); timer2_init(); EA=1; while(1) { TR2=1; } }
|
Oct 28 2017, 12:50 PM |
![]() |
Replied
to
c8051f410 adc is not working properly
sorry.. |
Oct 28 2017, 12:50 PM |
![]() |
Replied
to
c8051f410 adc is not working properly
#include<c8051f410.h> #include "stdio.h" #include<math.h> #define SYSCLK 12250000 // //sfr16 TMR2RL = 0xCA; // Timer2 reload value //sfr16 TMR2 = 0xCC; // Timer2 counter sfr16 adc0 = 0xBD; void oscillator_init(void); void timer2_init(void); void delay(void); void lcmnd(unsigned int value); void ldata(unsigned int value); void lcd_init(void); void adc_init(void); sbit rs=P1^3; sbit en=P1^4; sbit rw=P1^5; unsigned int temp; int i; void delay() { unsigned int j; for(j=0;j<50000;j++); } void cmnd(unsigned int value) { P2=value; rs=0; rw=0; en=1; delay(); en=0; } void ldata(unsigned int value) { P2=value; rs=1; en=1; rw=0; en=1; delay(); en=0; } void lcd_init() { cmnd(0x38); cmnd(0x0C); cmnd(0x01); cmnd(0x80); } void oscillator_init() { OSCICN = 0x86; //sys clk divided by 2 CLKSEL = 0X00; XBR0 = 0x00; //Enable crossbar and weak pullups XBR1 = 0x40; PCA0MD &= ~0x40; P1MDIN &= 0x7B; //0111 1011 P1.7, P1.2 P1SKIP |= 0x84; //1000 0100 } void main(void) { oscillator_init(); lcd_init(); adc_init(); EA=1; timer2_init(); while(1) { cmnd(0x80); cmnd(0x0C); ldata((temp/1000)+48); // display the result on LCD ldata(((temp%1000)/100)+48); ldata(((temp%100)/10)+48); ldata(((temp%10))+48); } } void adc_read() interrupt 5 { TF2H = 0; //AD0BUSY=1; //start conv. // //while (AD0INT == 0); //conv. in progress if(AD0INT == 1) //conv finished { ADC0H &= 0x0F; temp = ADC0H; //adc high byte temp<<=8; temp|=ADC0L; AD0INT = 0; } } void timer2_init(void) { TMR2CN = 0x00; // Stop Timer2; Clear TF2; // use SYSCLK as timebase, 16-bit // auto-reload CKCON |= 0x10; // Select SYSCLK for timer 2 source TMR2RL = 65535 - (SYSCLK / 10000); // Init reload value for 10 us TMR2 = 0xffff; // Set to reload immediately ET2 = 1; // Enable Timer2 interrupts TR2 = 1; // Start Timer2 } /* void display() interrupt 10 { cmnd(0x80); cmnd(0x0C); ldata((temp/1000)+48); // display the result on LCD ldata(((temp%1000)/100)+48); ldata(((temp%100)/10)+48); ldata(((temp%10))+48); } */ void adc_init (void) { ADC0CN = 0x03; // ADC0 disabled, burst-mode disabled, // conversion triggered on TMR2 overflow ADC0TK = 0x08; // Pre-tracking mode enabled, keep // default timing settings REF0CN = 0x02; // external VREF on VREF pin, // Bias Generator enabled ADC0MX = 0x0f; // ADC0 positive input = P1.7 ADC0CF = 0x00; // Repeat count = 1 ADC0CF |= ((SYSCLK/3000000)-1)<<3; // Set SAR clock to 3MHz //EIE1 |= 0x08; // Enable ADC0 EOC interrupt AD0EN = 1; // Enable ADC0 }
|
Oct 28 2017, 12:50 PM |
![]() |
Replied
to
c8051f410 adc is not working properly
#include<c8051f410.h> #include "stdio.h" #include<math.h> #define SYSCLK 12250000 // //sfr16 TMR2RL = 0xCA; // Timer2 reload value //sfr16 TMR2 = 0xCC; // Timer2 counter sfr16 adc0 = 0xBD; void oscillator_init(void); void timer2_init(void); void delay(void); void lcmnd(unsigned int value); void ldata(unsigned int value); void lcd_init(void); void adc_init(void); sbit rs=P1^3; sbit en=P1^4; sbit rw=P1^5; unsigned int temp; int i; void delay() { unsigned int j; for(j=0;j<50000;j++); } void cmnd(unsigned int value) { P2=value; rs=0; rw=0; en=1; delay(); en=0; } void ldata(unsigned int value) { P2=value; rs=1; en=1; rw=0; en=1; delay(); en=0; } void lcd_init() { cmnd(0x38); cmnd(0x0C); cmnd(0x01); cmnd(0x80); } void oscillator_init() { OSCICN = 0x86; //sys clk divided by 2 CLKSEL = 0X00; XBR0 = 0x00; //Enable crossbar and weak pullups XBR1 = 0x40; PCA0MD &= ~0x40; P1MDIN &= 0x7F; //0111 1011 P1.7, P1.2 P1SKIP |= 0x80; //1000 0100 } void main(void) { oscillator_init(); lcd_init(); adc_init(); EA=1; timer2_init(); while(1) { cmnd(0x80); cmnd(0x0C); ldata((temp/1000)+48); // display the result on LCD ldata(((temp%1000)/100)+48); ldata(((temp%100)/10)+48); ldata(((temp%10))+48); } } void adc_read() interrupt 5 { TF2H = 0; //AD0BUSY=1; //start conv. // //while (AD0INT == 0); //conv. in progress if(AD0INT == 1) //conv finished { ADC0H &= 0x0F; temp = ADC0H; //adc high byte temp<<=8; temp|=ADC0L; AD0INT = 0; } } void timer2_init(void) { TMR2CN = 0x00; // Stop Timer2; Clear TF2; // use SYSCLK as timebase, 16-bit // auto-reload CKCON |= 0x10; // Select SYSCLK for timer 2 source TMR2RL = 65535 - (SYSCLK / 10000); // Init reload value for 10 us TMR2 = 0xffff; // Set to reload immediately ET2 = 1; // Enable Timer2 interrupts TR2 = 1; // Start Timer2 } /* void display() interrupt 10 { cmnd(0x80); cmnd(0x0C); ldata((temp/1000)+48); // display the result on LCD ldata(((temp%1000)/100)+48); ldata(((temp%100)/10)+48); ldata(((temp%10))+48); } */ void adc_init (void) { ADC0CN = 0x03; // ADC0 disabled, burst-mode disabled, // conversion triggered on TMR2 overflow ADC0TK = 0x08; // Pre-tracking mode enabled, keep // default timing settings REF0CN = 0x02; // external VREF on VREF pin, // Bias Generator enabled ADC0MX = 0x0f; // ADC0 positive input = P1.7 ADC0CF = 0x00; // Repeat count = 1 ADC0CF |= ((SYSCLK/3000000)-1)<<3; // Set SAR clock to 3MHz //EIE1 |= 0x08; // Enable ADC0 EOC interrupt AD0EN = 1; // Enable ADC0 }
Hello experts,
i m working on C8051f410.. I am new on this device so facing some problems. I have to enabe internal ADC and display the result(count 0000-4095) on LCD.. I am configuring it in following way. but the counts are not continuous from 0000 to 4095(0000 - 0FFF). at 0V it is displaying 0063. at 0.57 it is 0127. But the counts between 0067 and 0127 are not displayed. similar situation is there for other values of voltage. input is given at P1.7. |
Oct 28 2017, 12:50 PM |