![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jay_chs
Joined: 05 Oct 2003 Posts: 2
|
newbie needs directions |
Posted: Mon Oct 13, 2003 8:42 am |
|
|
hi everyone, i'm currently writing a program which is supposed to monitor a dc voltage(2v to 3v) at the input.
the output will also be another dc voltage, which is +0.1v OR +0.2v of the original input voltage, depending on the pseudo random binary sequence which i had generated in another function (i.e if sequence is 001101... the input voltage is 2.5.... the output voltage will be 2.6v, 2.6v, 2.7v, 2.7v, 2.6v, 2.7v.... in sequence.
i have already written the gneration of the pseudo random sequence and now i need help to move on from there and here's a sample of the code that i've already done:
Code: | #include <16F876.h>
#include <pr_noise.c>
#use delay(clock=20000000)
#fuses HS,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
void main() {
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
while (TRUE)
{
if (PR_Noise()==1)
{
output_high(pin_b0);
delay_ms(200);
}
else
output_low(pin_b0);
delay_ms(200);
}
}
byte PR_Noise()
{
static int32 SR=0xAA55AA55; //or any other non-zero random value
bit xor_result;
xor_result=bit_test(SR,31) ^ bit_test(SR,22);
SR <<= 1;
if (xor_result)
bit_set(SR,0);
else
bit_clear(SR,0);
a = bit_test(SR,31);
return a;
} |
cheerio![/code][/list] |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Oct 13, 2003 6:22 pm |
|
|
First you have to decide how to generate the analog voltage. One soution is to use a D/A, but you have to make sure your D/A is accurate enough. One other way it to use the PWM module along with a low-pass filter to take an 'average' of the square wave. I've used this method before, you can create any voltage by changing the duty cycle of the wave. But again it may not be accurate enough for your application.
You can also create different analog voltages by smart setup and usage of PIC pins and resistor voltage dividers. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|