We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am require to calculate the distance of the object that the range finder detects. The microcontroller I am using is C167CR-LM. I am using T1 to detect the time lag between transmitting and receive of the pulse. When the the content of the timer is latch into the CC1 register, what is saved inside there? The timer's location? In what format(decimal, hexadecimal)? Without knowing, I couldn't continue my program. Awaiting ur reply, Frank
The C167 manual says: In response to an external event the content of the associated timer (T0/T1 or T7/T8, ...) is latched into the respective capture register CCx. So the content of register T1 (the timer's current value) is copied to register CC1. The format / layout is like the layout of any other storage word on C167. Thomas
U mean that if the timer is counting upwards or downwards and when there is an external signal, the content of the timer's register will be copied to the CC1. If at that moment, the timer's value is at 0x5555, then can I assumed that when I type the command printf("%g/n",CC1); I will get the message 0x5555? Apparantly when I test my code, what i get is 0/ when timer 1 value = 0x2A3F Any possible explanation?
%g is a floating point conversion specifier.
...when there is an external signal, the content of the timer's register will be copied to the CC1. This is exactly the purpose of the capture / compare unit when configured in capture mode. In opposite to the general purpose timer units GPT1 and GPT2, T1 (which is part of the capture / compare unit) is always incremented (i.e. never runs downwards). printf("%g/n",CC1); In addition to Dan's remark on %g: /n is not newline, but \n is. Thomas
Thanks for pointing out the mistake. But anything wrong with using %g as the floating point specifier? It won't affect the result right? If I can't, what should i use?
But anything wrong with using %g as the floating point specifier? If the number you're printing is a floating point one, no. It won't affect the result right? Wrong. If it didn't affect the result, why would it exist as a separate option? If I can't, what should i use? A C textbook. Seriously, you need to brush up your C knowledge before you go on foraging into the specifics of embedded programming in C.
If you want to use %g, you must cast the value:
printf("%g\n", (float) CC1);
printf("%#0x\n", CC1);
printf("%u\n", CC1);
Erm, looks like I really need to brush up my c again.:P..Thanks Hans And thank you Thomas for pointing me the way...nvr knew there is a C166 compiler user guide....stupid of me
I want to program the C167 to implement an ultrasonic range finder device, could someone please help me with how to start/do this as I'm not entirely too sure how to acheive this. Thanks :)